This repository was archived by the owner on Oct 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinstall_generator.rb
More file actions
109 lines (99 loc) · 3.55 KB
/
install_generator.rb
File metadata and controls
109 lines (99 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require 'rails/generators'
module Hyperloop
class InstallGenerator < Rails::Generators::Base
class_option :'hyper-mesh', type: :boolean
class_option :'opal-jquery', type: :boolean
class_option :'hyper-router', type: :boolean
class_option :all, type: :boolean
def inject_react_file_js
prepend_file 'app/assets/javascripts/application.js' do
<<-'JS'
// added by hyper-rails: These lines must preceed other requires especially turbo_links
//= require 'opal'
//= require 'react/react-source-browser'
//= require 'components'
//= require 'react_ujs'
JS
end
append_file 'app/assets/javascripts/application.js', "Opal.load('components');\n"
end
def inject_engine_to_routes
if options[:'hyper-mesh'] || options[:all]
route 'mount HyperMesh::Engine => \'/rr\''
end
end
def create_components_directory
create_file 'app/views/components/.keep', ''
if options[:'hyper-mesh'] || options[:all]
create_file 'app/models/public/.keep', ''
end
end
def create_policies_directory
if options[:'hyper-mesh'] || options[:all]
create_file 'app/policies/application_policy.rb', <<-RUBY
# app/policies/application_policy
# Policies regulate access to your public models
# The following policy will open up full access (but only in development)
# The policy system is very flexible and powerful. See the documentation
# for complete details.
class ApplicationPolicy
# Allow any session to connect:
always_allow_connection
# Send all attributes from all public models
regulate_all_broadcasts { |policy| policy.send_all }
# Allow all changes to public models
allow_change(to: :all, on: [:create, :update, :destroy]) { true }
end if Rails.env.development?
RUBY
end
end
def create_manifests
create_file 'app/views/components.rb', <<-FILE
# app/views/components.rb
require 'opal'
require 'hyper-react'
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 'hyper-router'\nrequire 'react_router'" if options[:'hyper-router'] || options[:all]}
#{'require \'hyper-mesh\'' if options[:'hyper-mesh'] || options[:all]}
#{'require \'models\'' if options[:'hyper-mesh'] || options[:all]}
require_tree './components'
FILE
if options[:'hyper-mesh'] || options[:all]
create_file 'app/models/models.rb', <<-FILE
# app/models/models.rb
require_tree './public' if RUBY_ENGINE == 'opal'
FILE
end
end
def add_config
application 'config.assets.paths << ::Rails.root.join(\'app\', \'models\').to_s'
if options[:'hyper-mesh'] || options[:all]
application 'config.autoload_paths += %W(#{config.root}/app/models/public)'
end
if options[:'hyper-mesh'] || options[: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
def add_gems
gem 'opal-rails'
gem 'opal-browser'
gem 'hyper-react'
gem 'therubyracer', platforms: :ruby
# optional gems
if options[:'hyper-router'] || options[:all]
gem 'react-router-rails', '~> 0.13.3'
gem 'hyper-router'
end
gem 'hyper-mesh' if options[:'hyper-mesh'] || options[:all]
end
end
end