Class: Reactrb::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Reactrb::InstallGenerator
- Defined in:
- lib/generators/reactrb/install_generator.rb
Instance Method Summary collapse
- #add_config ⇒ Object
- #add_gems ⇒ Object
- #create_components_directory ⇒ Object
- #create_manifests ⇒ Object
- #inject_engine_to_routes ⇒ Object
- #inject_react_file_js ⇒ Object
Instance Method Details
#add_config ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/generators/reactrb/install_generator.rb', line 65 def add_config application 'config.assets.paths << ::Rails.root.join(\'app\', \'models\').to_s' application 'config.autoload_paths += %W(#{config.root}/app/views/components)' if [:'reactive-record'] || [:all] application 'config.autoload_paths += %W(#{config.root}/app/models/public)' end application 'config.eager_load_paths += %W(#{config.root}/app/views/components)' if [:'reactive-record'] || [:all] application 'config.eager_load_paths += %W(#{config.root}/app/models/public)' end application 'config.watchable_files.concat Dir["#{config.root}/app/views/**/*.rb"]', env: :development application 'config.react.variant = :development', env: :development end |
#add_gems ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/generators/reactrb/install_generator.rb', line 80 def add_gems gem 'reactrb' gem 'react-rails', '>= 1.3.0' gem 'opal-rails', '>= 0.8.1' gem 'therubyracer', platforms: :ruby # optional gems if [:'reactrb-router'] || [:all] gem 'react-router-rails', '~> 0.13.3' gem 'reactrb-router' end gem 'reactive-record', '>= 0.8.0' if [:'reactive-record'] || [:all] end |
#create_components_directory ⇒ Object
31 32 33 34 35 36 |
# File 'lib/generators/reactrb/install_generator.rb', line 31 def create_components_directory create_file 'app/views/components/.keep', '' if [:'reactive-record'] || [:all] create_file 'app/models/public/.keep', '' end end |
#create_manifests ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/generators/reactrb/install_generator.rb', line 38 def create_manifests create_file 'app/views/components.rb', <<-FILE # app/views/components.rb require 'opal' require 'react' require 'reactrb' if React::IsomorphicHelpers.on_opal_client? require 'opal-jquery' require 'browser' require 'browser/interval' require 'browser/delay' # add any additional requires that can ONLY run on client here end #{"require 'reactrb-router'\nrequire 'react_router'" if [:'reactive-router'] || [:all]} #{'require \'reactive-record\'' if [:'reactive-record'] || [:all]} #{'require \'models\'' if [:'reactive-record'] || [:all]} require_tree './components' FILE if [:'reactive-record'] || [:all] create_file 'app/models/models.rb', <<-FILE # app/models/models.rb require_tree './public' FILE end end |
#inject_engine_to_routes ⇒ Object
25 26 27 28 29 |
# File 'lib/generators/reactrb/install_generator.rb', line 25 def inject_engine_to_routes if [:'reactive-record'] || [:all] route 'mount ReactiveRecord::Engine => \'/rr\'' end end |
#inject_react_file_js ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/generators/reactrb/install_generator.rb', line 9 def inject_react_file_js inject_into_file 'app/assets/javascripts/application.js', after: "// about supported directives.\n" do <<-'JS' //= require 'components' //= require 'react_ujs' JS end inject_into_file 'app/assets/javascripts/application.js', after: "//= require jquery_ujs\n" do <<-'JS' Opal.load('components'); JS end end |