Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
annotator-administrate / lib / generators / administrate / views / field_generator.rb
Size: Mime:
require "administrate/view_generator"

module Administrate
  module Generators
    module Views
      class FieldGenerator < Administrate::ViewGenerator
        def self.template_source_path
          File.expand_path(
            "../../../../../app/views/fields/",
            __FILE__,
          )
        end

        source_root template_source_path

        def copy_partials
          resource_path = args.first.try(:underscore)

          if resource_path == "all"
            entries = Dir.entries(self.class.template_source_path)
            field_types = entries.reject { |name| name[0] == "." }

            field_types.each do |field_type|
              copy_field_partials(field_type)
            end
          else
            copy_field_partials(resource_path)
          end
        end

        private

        def copy_field_partials(resource_path)
          copy_field_partial(resource_path, :index)
          copy_field_partial(resource_path, :show)
          copy_field_partial(resource_path, :form)
        end

        def copy_field_partial(resource_path, partial_name)
          template_file = "#{resource_path}/_#{partial_name}.html.erb"

          copy_file(
            template_file,
            "app/views/fields/#{template_file}",
          )
        end
      end
    end
  end
end