Sha256: 89cf95a065df8746df9c65108c644d9c016ed804670891a165cc55afa870aecc

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

module RailsViewComponent
  module Generators
    class RailsViewComponentGenerator < Rails::Generators::NamedBase
  
      source_root File.expand_path('../templates', __FILE__)

      desc "This generator creates RailsViewComponent files."
  
      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    
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_view_component-1.0.1 lib/generators/rails_view_component/rails_view_component_generator.rb
rails_view_component-1.0.0 lib/generators/rails_view_component/rails_view_component_generator.rb