Class: Golden::Menu::InstallGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/golden/menu/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



10
11
12
13
# File 'lib/generators/golden/menu/install_generator.rb', line 10

def self.next_migration_number dirname
  next_migration_number = current_migration_number(dirname) + 1
  ActiveRecord::Migration.next_migration_number(next_migration_number)
end

Instance Method Details

#add_locales_pathObject



31
32
33
34
35
36
37
# File 'lib/generators/golden/menu/install_generator.rb', line 31

def add_locales_path
  file = 'config/application.rb'
  sentinel = "# config.i18n.default_locale = :de\n"
  insert_into_file file, after: sentinel do
    "    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]\n"
  end
end

#generate_helperObject



59
60
61
62
63
# File 'lib/generators/golden/menu/install_generator.rb', line 59

def generate_helper
  file = 'menu_resources_helper.rb'
  log :helper, file
  template file, File.join('app/helpers/golden/menu', class_path, file), verbose: false
end

#generate_initializerObject



25
26
27
28
29
# File 'lib/generators/golden/menu/install_generator.rb', line 25

def generate_initializer
  file = 'golden_menu.rb'
  log :initializer, file
  template file, File.join('config/initializers', class_path, file), verbose: false
end

#generate_localesObject



39
40
41
42
43
44
45
# File 'lib/generators/golden/menu/install_generator.rb', line 39

def generate_locales
  files = %w{menus.en.yml menus.zh-TW.yml}
  files.each do |file|
    log :locales, "golden/#{file}"
    template file, File.join('config/locales/golden', class_path, file), verbose: false
  end
end

#generate_migrationObject



15
16
17
18
19
20
21
22
# File 'lib/generators/golden/menu/install_generator.rb', line 15

def generate_migration
  %W(
    create_golden_menus.rb
    create_golden_menu_resources.rb
  ).each do |file|
    migration_template file, File.join('db/migrate', class_path, file)
  end
end

#inject_controllerObject



51
52
53
54
55
56
57
# File 'lib/generators/golden/menu/install_generator.rb', line 51

def inject_controller
  file = 'app/controllers/application_controller.rb'
  sentinel = "protect_from_forgery with: :exception\n"
  insert_into_file file, after: sentinel do
    "  helper Golden::Menu::HierarchicalMenusHelper\n"
  end
end

#inject_routesObject



47
48
49
# File 'lib/generators/golden/menu/install_generator.rb', line 47

def inject_routes
  route "mount Golden::Menu::Engine, at: '/'\n"
end