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
47
48
49
50
|
# File 'lib/generators/rails_view_component/rails_view_component_generator.rb', line 10
def create_rails_view_component_file
puts @dir = "app/rails_view_components/#{file_path}"
puts @haxe_dir = "#{@dir}/haxe"
puts @haxe_class_name = "#{@file_name.camelize}ViewComponent"
puts @haxe_file_name = "#{@haxe_dir}/#{@haxe_class_name}.hx"
puts @haxe_js_name = "#{@file_path.gsub("/",".")}_view_component.js"
@file_path
@file_name = file_name
@class_name = "#{class_name}::#{class_name.split('::').last}"
@args = args
copy_and_compile = ->(from, to){
root = File.expand_path("../", __FILE__)
erb = ERB.new(open("#{root}/erb/#{from}").read)
create_file to, erb.result(binding)
}
copy_and_compile.call("controller.rb.erb", "#{@dir}/#{@file_name}_controller.rb")
copy_and_compile.call("model.rb.erb", "#{@dir}/#{@file_name}_model.rb")
copy_and_compile.call("routes.rb.erb", "#{@dir}/#{@file_name}_routes.rb")
copy_and_compile.call("views/rails_view_component.html.erb.erb",
"#{@dir}/views/#{@file_name}_view_component.html.erb")
copy_and_compile.call("haxe/RailsViewComponent.hx.erb", @haxe_file_name)
inject_into_file "haxe_compile.hxml",
after: "## RailsViewComponent JavaScripts\n" do
<<RUBY
--next
# #{@haxe_dir}/#{@haxe_class_name}
-lib JQueryExtern
-cp lib/rails_view_component/haxe
-cp #{@haxe_dir}
-main #{@haxe_class_name}
-js public/javascripts/#{@haxe_js_name}
RUBY
end
route "#{@class_name}Routes.routings"
end
|