Class: React::Generators::UjsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/react/ujs_generator.rb

Constant Summary collapse

EVENT_SUPPORT_OPTIONS =
[
  :turbolinks,
  :turbolinks_classic,
  :turbolinks_classic_deprecated,
  :pjax,
  :native,
]

Instance Method Summary collapse

Instance Method Details

#create_ujs_fileObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/react/ujs_generator.rb', line 22

def create_ujs_file
  files_to_merge = ["react_ujs_mount.js"]

  EVENT_SUPPORT_OPTIONS.each do |event_support_option|
    if options[event_support_option]
      files_to_merge << "react_ujs_#{event_support_option}.js"
    end
  end

  files_to_merge << "react_ujs_event_setup.js"

  asset_dir = File.expand_path("../../../assets/javascripts", __FILE__)

  custom_ujs_content = files_to_merge
    .map { |filename| File.read(File.join(asset_dir, filename)) }
    .join("\n")

  new_ujs_path = options[:output]
  create_file(new_ujs_path, custom_ujs_content)
end