Class: I18nLazyLookup::Generators::GenerateGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/i18n_lazy_lookup/generate/generate_generator.rb

Instance Method Summary collapse

Instance Method Details

#manifestObject



10
11
12
13
14
15
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
42
43
44
45
46
# File 'lib/generators/i18n_lazy_lookup/generate/generate_generator.rb', line 10

def manifest
  empty_directory File.join(view_path)

  controller_action_map = {}
  Find.find(File.join('app/views')) do |path|
    if path =~ /app\/views\/(.*)\/(.*)\.html\.[erb|haml]/
      controller, action = $1, $2 # controller include namaspace as well
      next if action     =~ /^_/
      next if controller =~ /#{options[:exclude_patterns]}/
      if controller_action_map.key?(controller)
        controller_action_map[controller] << action
      else
        controller_action_map[controller] = [action]
      end
    end
  end

  controller_action_map.each do |controller, actions|
    if controller =~ /\//
      namespace, controller = controller.split('/')
      empty_directory File.join(view_path, namespace, controller)
    else
      empty_directory File.join(view_path, controller)
    end
    options[:locales].each do |locale|
      @locale     = locale
      @controller = controller
      @actions    = actions
      if namespace.nil?
        template 'locale.erb', File.join(view_path, controller, "#{locale}.yml")
      else
        @namespace = namespace
        template 'namespace_locale.erb', File.join(view_path, namespace, controller, "#{locale}.yml")
      end
    end
  end
end

#view_pathObject



48
49
50
# File 'lib/generators/i18n_lazy_lookup/generate/generate_generator.rb', line 48

def view_path
  'config/locales/views'
end