Sha256: 51daccf2c1730f11734dc19dcfe92c220355aac6956cf7825f5421414890510d

Contents?: true

Size: 1.18 KB

Versions: 16

Compression:

Stored size: 1.18 KB

Contents

module Adminsite
  module Generators
    class AddResourceGenerator < Rails::Generators::NamedBase
      source_root File.expand_path("../templates", __FILE__)

      def table_name
        class_name_underscore.pluralize
      end

      #def file_name
      #  super.underscore.gsub('/','_')
      #end

      def class_name_underscore
        class_name.underscore.gsub('/','_')
      end

      def run_generation
        puts "Setting up resource #{class_name.camelize} for Adminsite"
        @resource_class = class_name.camelize

        #puts "file_name: #{file_name}"
        puts "table_name: #{table_name}"

        # Controllers
        template  "controllers/admin_resource_controller.rb", "app/controllers/adminsite/admin/#{table_name}_controller.rb"

        # Models
        template  "admin_configs/resource_admin_config.rb", "app/admin_configs/adminsite/#{class_name_underscore}_admin_config.rb"

        # Content-Menu
        inject_into_file "app/views/adminsite/admin/shared/_admin_menu.html.haml", :after => /\= yield :admin_menu\n/ do\
          "\n    = menu_item '#{class_name.camelize}Mngt', admin_#{table_name}_path, ['#{table_name}']\n"
        end

      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
adminsite-3.2.4 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-3.2.3 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-3.2.2 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-3.2.1 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-3.2.0 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-3.1.2 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-3.1.1 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-3.1.0 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-3.0.0 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-2.1.2 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-2.1.1 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-2.1.0 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-2.0.3 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-2.0.2 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-2.0.1 lib/generators/adminsite/add_resource/add_resource_generator.rb
adminsite-2.0.0 lib/generators/adminsite/add_resource/add_resource_generator.rb