Sha256: 64f4c93d02a1157100eb9158b92ba6ce364e29f6c731f8e316b3a7c32147b652

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require 'rubygems/specification'
require 'rails/generators/named_base'
require 'rails/generators/resource_helpers'

module Admin
  module Generators
    class ScaffoldControllerGenerator < Rails::Generators::NamedBase
      include Rails::Generators::ResourceHelpers

      source_root File.expand_path('templates', __dir__)

      class_option :prefix_name, banner: "admin", type: :string, default: "admin",
        desc: "Define the prefix of controller"

      class_option :parent_controller, banner: "admin", type: :string, default: "application",
        desc: "Define the parent controller"

      def create_controller_files
        # I think there should be a better way to detect if jbuilder is in use
        # If you know it, please let me know
        template "controllers/controller.rb.erb", File.join('app/controllers', prefix, class_path, "#{controller_file_name}_controller.rb")
        # create_file "app/controllers/a.rb", "# Add initialization content here"
      end

      def prefix
        options[:prefix_name]
      end

      def prefixed_class_name
        "#{prefix.capitalize}::#{class_name}"
      end

      def prefixed_controller_class_name
        "#{prefix.capitalize}::#{controller_class_name}"
      end

      def parent_controller_class_name
        options[:parent_controller].capitalize
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
admin_help-0.1.2 lib/generators/admin/scaffold_controller/scaffold_controller_generator.rb