Class: Coalla::Cms::Lookups::InstallGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/coalla/cms/lookups/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_sectionObject



45
46
47
# File 'lib/generators/coalla/cms/lookups/install_generator.rb', line 45

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

#copy_filesObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/coalla/cms/lookups/install_generator.rb', line 12

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

#setup_routesObject



36
37
38
39
40
41
42
43
# File 'lib/generators/coalla/cms/lookups/install_generator.rb', line 36

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