Class: ReactOnRails::Generators::ReactNoReduxGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
GeneratorHelper, DemoPageConfig
Defined in:
lib/generators/react_on_rails/react_no_redux_generator.rb

Instance Method Summary collapse

Methods included from DemoPageConfig

#build_hello_server_view_config, #build_hello_world_view_config

Methods included from GeneratorHelper

#absolute_path_relative_to_destination, #add_documentation_reference, #add_npm_dependencies, #bundler_flag_given?, #component_extension, #configured_shakapacker_relative_path, #destination_config_path, #detect_react_version, #example_component_source_directory, #example_component_source_path, #explicit_bundler_choice, #gem_in_lockfile?, #package_json, #print_generator_messages, #pro_gem_installed?, #relative_stylesheet_import_path, #resolve_server_client_or_both_path, #root_route_present?, #rsc_plugin_class_name, #rsc_plugin_import_path, #rspack_bundler_default, #safe_generator_destination_path, #shakapacker_entrypoint_path, #shakapacker_path_config_value, #shakapacker_source_entry_path, #shakapacker_source_path, #shakapacker_stylesheet_path, #shakapacker_version_9_or_higher?, #unsafe_generator_destination_path?, #use_pro?, #use_rsc?, #use_tailwind?, #using_rspack?, #using_swc?

Instance Method Details

#copy_base_filesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/generators/react_on_rails/react_no_redux_generator.rb', line 31

def copy_base_files
  base_js_path = "base/base"
  tailwind_js_path = "base/tailwind"
  ext = component_extension(options)
  component_dir = example_component_source_directory("HelloWorld")

  # Determine which component files to copy based on TypeScript option
  client_component =
    "#{component_dir}/ror_components/HelloWorld.client.#{ext}"
  server_component =
    "#{component_dir}/ror_components/HelloWorld.server.#{ext}"
  client_component_template = "app/javascript/src/HelloWorld/ror_components/HelloWorld.client.#{ext}"

  # Source paths are relative to this generator's templates; only
  # destinations vary with the app's Shakapacker config.
  if use_tailwind?
    copy_file("#{tailwind_js_path}/#{client_component_template}", client_component)
  else
    copy_file("#{base_js_path}/#{client_component_template}", client_component)
    copy_file("#{base_js_path}/app/javascript/src/HelloWorld/ror_components/HelloWorld.module.css",
              "#{component_dir}/ror_components/HelloWorld.module.css")
  end

  copy_file("#{base_js_path}/app/javascript/src/HelloWorld/ror_components/HelloWorld.server.#{ext}",
            server_component)
end

#create_appropriate_templatesObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/generators/react_on_rails/react_no_redux_generator.rb', line 58

def create_appropriate_templates
  base_path = "base/base"

  # Only create the view template - no manual bundle needed for auto-bundling
  template("#{base_path}/app/views/hello_world/index.html.erb.tt",
           "app/views/hello_world/index.html.erb",
           build_hello_world_view_config(
             component_name: "HelloWorld",
             source_path: example_component_source_path("HelloWorld"),
             landing_page: new_app_landing_page_available?,
             redux: false,
             rsc_demo: false
           ))
end