Sha256: 88a0b8f1c2a662107bf5ecac195f64349290ead9a677f47e9a6c76422bbbabb7

Contents?: true

Size: 1.87 KB

Versions: 3

Compression:

Stored size: 1.87 KB

Contents

require 'rails'
require 'rails/generators/active_record'

module Coalla
  module Cms
    module Lookups
      class InstallGenerator < ActiveRecord::Generators::Base
        argument :name, type: :string, default: ''
        source_root File.expand_path('../../../../../../', __FILE__)
        class_option :copy, type: :boolean, default: false, description: 'Copy all files to project'

        def copy_files
          migration_template 'lib/generators/coalla/cms/lookups/templates/migration.rb', 'db/migrate/create_lookups.rb'

          if options.copy?
            [ 'app/views/admin/lookups/types/boolean',
              'app/views/admin/lookups/types/enum',
              'app/views/admin/lookups/types/float',
              'app/views/admin/lookups/types/integer',
              'app/views/admin/lookups/types/memo',
              'app/views/admin/lookups/types/string',
              'app/views/admin/lookups/types/wysiwyg',
              'app/views/admin/lookups/_form.html.haml',
              'app/views/admin/lookups/edit.html.haml',
              'app/views/admin/lookups/index.html.haml',
              'app/views/admin/lookups/show.html.haml',
              'app/controllers/admin/lookups_controller.rb',
              'app/models/lookup.rb',
              'app/helpers/lookup_helper.rb'
            ].each do |path|
              copy_file path, path
            end
          end
        end

        def setup_routes
          sentinel = /namespace :admin do\s*$/

          routing_code = "  get 'lookups/(:category)' => 'lookups#index', as: :lookups_index\n  resources :lookups, except: [:show]"
          in_root do
            inject_into_file 'config/routes.rb', "\n  #{routing_code}", { :after => sentinel, :verbose => false }
          end
        end

        def add_section
          append_to_file 'config/structure.rb', "\nlookup_section"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coalla-cms-0.7.0.0 lib/generators/coalla/cms/lookups/install_generator.rb
coalla-cms-0.6.1.1 lib/generators/coalla/cms/lookups/install_generator.rb
coalla-cms-0.6.0.9 lib/generators/coalla/cms/lookups/install_generator.rb