Class: Metaslug::Generators::LocaleGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/rails/generators/metaslug/locale/locale_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



8
9
10
11
12
13
14
# File 'lib/rails/generators/metaslug/locale/locale_generator.rb', line 8

def self.banner
  <<-BANNER.chomp
rails generate metaslug:locale

Try to generate the metas file of the given locale, based on the current routes.
BANNER
end

Instance Method Details

#generate_locale_fileObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rails/generators/metaslug/locale/locale_generator.rb', line 16

def generate_locale_file
  routes = get_paths_from_routes

  locales = options.locale? ?
    [options.locale] :
    I18n.available_locales

  metas = options.metas? ?
    options.metas.split(',') :
    ["description", "title"]

  locales.each do |locale|
    buffer = "#{locale}:\n"
    add_metas_to_buffer(buffer, 'default', { quote_section: false }, *metas)

    routes.each do |route|
      add_metas_to_buffer(buffer, route, { quote_section: true }, *metas)
    end

    if options.output?
      $stdout.puts buffer
    else
      create_file "config/metaslug/#{locale}.yml", buffer
    end
  end
end