Class: ReactWebpackRails::Install::ExampleGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/react_webpack_rails/install/example_generator.rb

Instance Method Summary collapse

Instance Method Details

#controller_and_viewObject



23
24
25
26
27
# File 'lib/generators/react_webpack_rails/install/example_generator.rb', line 23

def controller_and_view
  copy_file 'examples/react_examples_controller.rb', 'app/controllers/react_examples_controller.rb'
  template = "examples/#{options.server_side ? 'ssr-' : ''}component_view.html.erb"
  copy_file template, 'app/views/react_examples/component.html.erb'
end

#es6_exampleObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/generators/react_webpack_rails/install/example_generator.rb', line 12

def es6_example
  copy_file 'react/components/hello-world-test.jsx', 'app/react/components/hello-world-test.jsx'
  copy_file 'react/components/hello-world.jsx', 'app/react/components/hello-world.jsx'
  inject_into_file 'app/react/index.js', after: "RWR.run();\n" do <<-'JS'.strip_heredoc

    import HelloWorld from './components/hello-world';
    RWR.registerComponent('HelloWorld', HelloWorld);
    JS
  end
end

#example_routeObject



29
30
31
# File 'lib/generators/react_webpack_rails/install/example_generator.rb', line 29

def example_route
  route "get 'react_examples/component', to: 'react_examples#component', as: :component"
end