Class: Loco::ViewGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/loco/view/view_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_namespaces_inside_intializerObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generators/loco/view/view_generator.rb', line 12

def create_namespaces_inside_intializer
  file_path = File.join Rails.root, 'app', 'assets', 'javascripts', 'initializers', 'loco.coffee'
  class_path.each.with_index do |name, index|
    prev_namespace_def = if index == 0
      nil
    else
      current_name = class_path[0, index].map(&:camelcase).join('.')
      "App.Views.#{current_name} = {}\n"
    end
    current_name = class_path[0, index + 1].map(&:camelcase).join('.')
    namespace_def = "App.Views.#{current_name} = {}\n"
    if prev_namespace_def.nil?
      prepend_file file_path, namespace_def
    else
      inject_into_file file_path, namespace_def, after: prev_namespace_def
    end
  end
end

#create_viewObject



4
5
6
7
8
9
10
# File 'lib/generators/loco/view/view_generator.rb', line 4

def create_view
  class_name = (class_path + [file_name]).map(&:camelcase).join('.')
  data = File.read find_in_source_paths('view.coffee')
  data.sub! '#{name}', class_name
  data.sub! '#{methods_def}', methods_def.join('')
  create_file file_path, data
end