Class: ReactOnRails::Generators::ReactWithReduxGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- ReactOnRails::Generators::ReactWithReduxGenerator
- Defined in:
- lib/generators/react_on_rails/react_with_redux_generator.rb
Instance Method Summary collapse
- #add_redux_npm_dependencies ⇒ Object
- #add_redux_specific_messages ⇒ Object
- #copy_base_files ⇒ Object
- #copy_base_redux_files ⇒ Object
- #create_appropriate_templates ⇒ Object
- #create_redux_directories ⇒ Object
Instance Method Details
#add_redux_npm_dependencies ⇒ Object
62 63 64 |
# File 'lib/generators/react_on_rails/react_with_redux_generator.rb', line 62 def add_redux_npm_dependencies run "npm install redux react-redux" end |
#add_redux_specific_messages ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/generators/react_on_rails/react_with_redux_generator.rb', line 66 def # Override the generic messages with Redux-specific instructions require_relative "generator_messages" GeneratorMessages.output.clear GeneratorMessages.add_info( GeneratorMessages.(component_name: "HelloWorldApp") ) end |
#copy_base_files ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/react_on_rails/react_with_redux_generator.rb', line 20 def copy_base_files base_js_path = "redux/base" # Copy Redux-connected component to auto-registration structure copy_file("#{base_js_path}/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.client.jsx", "app/javascript/src/HelloWorldApp/ror_components/HelloWorldApp.client.jsx") copy_file("#{base_js_path}/app/javascript/bundles/HelloWorld/startup/HelloWorldApp.server.jsx", "app/javascript/src/HelloWorldApp/ror_components/HelloWorldApp.server.jsx") copy_file("#{base_js_path}/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css", "app/javascript/src/HelloWorldApp/components/HelloWorld.module.css") # Update import paths in client component ror_client_file = "app/javascript/src/HelloWorldApp/ror_components/HelloWorldApp.client.jsx" gsub_file(ror_client_file, "../store/helloWorldStore", "../store/helloWorldStore") gsub_file(ror_client_file, "../containers/HelloWorldContainer", "../containers/HelloWorldContainer") end |
#copy_base_redux_files ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/react_on_rails/react_with_redux_generator.rb', line 38 def copy_base_redux_files base_hello_world_path = "redux/base/app/javascript/bundles/HelloWorld" %w[actions/helloWorldActionCreators.js containers/HelloWorldContainer.js constants/helloWorldConstants.js reducers/helloWorldReducer.js store/helloWorldStore.js components/HelloWorld.jsx].each do |file| copy_file("#{base_hello_world_path}/#{file}", "app/javascript/src/HelloWorldApp/#{file}") end end |
#create_appropriate_templates ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/generators/react_on_rails/react_with_redux_generator.rb', line 51 def create_appropriate_templates base_path = "base/base" config = { component_name: "HelloWorldApp" } # Only create the view template - no manual bundle needed for auto registration template("#{base_path}/app/views/hello_world/index.html.erb.tt", "app/views/hello_world/index.html.erb", config) end |
#create_redux_directories ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/generators/react_on_rails/react_with_redux_generator.rb', line 11 def create_redux_directories # Create auto-registration directory structure for Redux empty_directory("app/javascript/src/HelloWorldApp/ror_components") # Create Redux support directories within the component directory dirs = %w[actions constants containers reducers store components] dirs.each { |name| empty_directory("app/javascript/src/HelloWorldApp/#{name}") } end |