Sha256: c38913c2451415c2258ae9e65527713659bab051d48328f7d852cd271abe33c7

Contents?: true

Size: 1.71 KB

Versions: 30

Compression:

Stored size: 1.71 KB

Contents

module Dradis
  module Plugins
    module Templates
      extend ActiveSupport::Concern

      included do
        # Keep track of any templates the plugin defines
        paths['dradis/templates'] = 'templates'
      end

      module ClassMethods
        def copy_templates(args={})
          destination = args.fetch(:to)

          destination_dir = File.join(destination, plugin_name.to_s)
          FileUtils.mkdir_p(destination_dir) if plugin_templates.any?

          plugin_templates.each do |template|
            destination_file = File.join(destination_dir, File.basename(template))

            next if skip?(destination_file)

            Rails.logger.info do
              "Updating templates for #{plugin_name} plugin. "\
              "Destination: #{destination}"
            end
            FileUtils.cp(template, destination_file)
          end
        end

        def plugin_templates(args={})
          @templates ||= begin
            if paths['dradis/templates'].existent.any?
              Dir["#{paths['dradis/templates'].existent.first}/*"]
            else
              []
            end
          end
        end

        private

        # Normally we want to copy all templates so that the user always has
        # the latest version.
        #
        # However, if it's a '.template' file, the user might have edited their
        # local copy, and we don't want to override their changes.  So only
        # copy .template files over if the user has no copy at all (i.e. if
        # this is the first time they've started Dradis since this template was
        # added.)
        def skip?(file_path)
          File.exist?(file_path) && File.extname(file_path) == ".template"
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
dradis-plugins-4.11.0 lib/dradis/plugins/templates.rb
dradis-plugins-4.10.0 lib/dradis/plugins/templates.rb
dradis-plugins-4.9.0 lib/dradis/plugins/templates.rb
dradis-plugins-4.8.0 lib/dradis/plugins/templates.rb
dradis-plugins-4.7.0 lib/dradis/plugins/templates.rb
dradis-plugins-4.6.1 lib/dradis/plugins/templates.rb
dradis-plugins-4.5.0 lib/dradis/plugins/templates.rb
dradis-plugins-4.4.0 lib/dradis/plugins/templates.rb
dradis-plugins-4.3.0 lib/dradis/plugins/templates.rb
dradis-plugins-4.2.0 lib/dradis/plugins/templates.rb
dradis-plugins-4.1.0 lib/dradis/plugins/templates.rb
dradis-plugins-4.0.0 lib/dradis/plugins/templates.rb
dradis-plugins-3.22.0 lib/dradis/plugins/templates.rb
dradis-plugins-3.21.0 lib/dradis/plugins/templates.rb
dradis-plugins-3.20.0 lib/dradis/plugins/templates.rb
dradis-plugins-3.19.0 lib/dradis/plugins/templates.rb
dradis-plugins-3.18.0 lib/dradis/plugins/templates.rb
dradis-plugins-3.17.0 lib/dradis/plugins/templates.rb
dradis-plugins-3.16.0 lib/dradis/plugins/templates.rb
dradis-plugins-3.15.0 lib/dradis/plugins/templates.rb