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
|