Class: ReactOnRails::Generators::ReactWithReduxGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_redux_yarn_dependenciesObject



47
48
49
# File 'lib/generators/react_on_rails/react_with_redux_generator.rb', line 47

def add_redux_yarn_dependencies
  run "yarn add redux react-redux"
end

#copy_base_filesObject



16
17
18
19
20
# File 'lib/generators/react_on_rails/react_with_redux_generator.rb', line 16

def copy_base_files
  base_js_path = "redux/base"
  base_files = %w[app/javascript/bundles/HelloWorld/components/HelloWorld.jsx]
  base_files.each { |file| copy_file("#{base_js_path}/#{file}", file) }
end

#copy_base_redux_filesObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/react_on_rails/react_with_redux_generator.rb', line 22

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
     startup/HelloWorldApp.jsx].each do |file|
       copy_file("#{base_hello_world_path}/#{file}",
                 "app/javascript/bundles/HelloWorld/#{file}")
     end
end

#create_appropriate_templatesObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/generators/react_on_rails/react_with_redux_generator.rb', line 35

def create_appropriate_templates
  base_path = "base/base"
  base_js_path = "#{base_path}/app/javascript"
  config = {
    component_name: "HelloWorldApp",
    app_relative_path: "../bundles/HelloWorld/startup/HelloWorldApp"
  }

  template("#{base_js_path}/packs/registration.js.tt", "app/javascript/packs/hello-world-bundle.js", config)
  template("#{base_path}/app/views/hello_world/index.html.erb.tt", "app/views/hello_world/index.html.erb", config)
end

#create_redux_directoriesObject



11
12
13
14
# File 'lib/generators/react_on_rails/react_with_redux_generator.rb', line 11

def create_redux_directories
  dirs = %w[actions constants containers reducers store startup]
  dirs.each { |name| empty_directory("app/javascript/bundles/HelloWorld/#{name}") }
end