Sha256: d789ca7bb96ced080c0a097b647ab746663c910372c886809e3088762c05762c

Contents?: true

Size: 993 Bytes

Versions: 3

Compression:

Stored size: 993 Bytes

Contents

require "rails/generators/base"
require "administrate/generator_helpers"
require "administrate/namespace"

module Administrate
  class ViewGenerator < Rails::Generators::Base
    include Administrate::GeneratorHelpers
    class_option(
      :namespace,
      type: :string,
      desc: "Namespace where the admin dashboards live",
      default: "admin"
    )

    def self.template_source_path
      File.expand_path(
        "../../../app/views/administrate/application",
        __FILE__
      )
    end

    private

    def namespace
      options[:namespace]
    end

    def copy_resource_template(template_name)
      template_file = "#{template_name}.html.erb"

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

    def resource_path
      args.first.try(:underscore).try(:pluralize) || BaseResourcePath.new
    end

    class BaseResourcePath
      def to_s
        "application"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
administrate-1.0.0.beta3 lib/administrate/view_generator.rb
administrate-1.0.0.beta2 lib/administrate/view_generator.rb
administrate-1.0.0.beta1 lib/administrate/view_generator.rb