Sha256: 38ffcb51cfaabceaa6d0b3a3f653892f79b2f7f1501bf6486169fb4bfbaa1bde

Contents?: true

Size: 1.25 KB

Versions: 16

Compression:

Stored size: 1.25 KB

Contents

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

module Administrate
  module Generators
    class InstallGenerator < Rails::Generators::Base
      include Administrate::GeneratorHelpers
      source_root File.expand_path("../templates", __FILE__)

      class_option :namespace, type: :string, default: "admin"

      def run_routes_generator
        if dashboard_resources.none?
          call_generator("administrate:routes", "--namespace", namespace)
          load Rails.root.join("config/routes.rb")
        end
      end

      def create_dashboard_controller
        template(
          "application_controller.rb.erb",
          "app/controllers/#{namespace}/application_controller.rb",
        )
      end

      def run_dashboard_generators
        singular_dashboard_resources.each do |resource|
          call_generator "administrate:dashboard", resource,
            "--namespace", namespace
        end
      end

      private

      def namespace
        options[:namespace]
      end

      def singular_dashboard_resources
        dashboard_resources.map(&:to_s).map(&:singularize)
      end

      def dashboard_resources
        Administrate::Namespace.new(namespace).resources
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
administrate-0.14.0 lib/generators/administrate/install/install_generator.rb
viniBaxterDesk-22.0.0 lib/generators/administrate/install/install_generator.rb
viniBaxterDesk-0.21.0 lib/generators/administrate/install/install_generator.rb
viniBaxterDesk-0.20.0 lib/generators/administrate/install/install_generator.rb
viniBaxterDesk-0.14.0 lib/generators/administrate/install/install_generator.rb
viniBaxterDesk-0.13.2 lib/generators/administrate/install/install_generator.rb
viniBaxterDesk-0.13.1 lib/generators/administrate/install/install_generator.rb
administrate-0.13.0 lib/generators/administrate/install/install_generator.rb
administrate-0.12.0 lib/generators/administrate/install/install_generator.rb
administrate-0.11.0 lib/generators/administrate/install/install_generator.rb
semantic-administrate-0.10.1 lib/generators/administrate/install/install_generator.rb
semantic-administrate-0.10.0 lib/generators/administrate/install/install_generator.rb
administrate-0.10.0 lib/generators/administrate/install/install_generator.rb
semantic-administrate-0.1.1 lib/generators/administrate/install/install_generator.rb
administrate-0.9.0 lib/generators/administrate/install/install_generator.rb
semantic-administrate-0.1.0 lib/generators/administrate/install/install_generator.rb