hyperloop-config 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -1
- data/hyperloop-config.gemspec +13 -1
- data/lib/hyperloop-config.rb +0 -6
- data/lib/hyperloop-prerender-loader.rb.erb +1 -0
- data/lib/hyperloop/rail_tie.rb +15 -17
- data/lib/hyperloop/requires.rb +46 -28
- metadata +115 -4
- data/hyperloop-config-0.8.1.gem +0 -0
- data/lib/components.rb.erb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f732c8828c572f731b2515c7e4feef8cf1a63ce
|
4
|
+
data.tar.gz: 40b1671bcfa35dea5db6d2c9185901b831961509
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9ba99620f956083f59a4bd0b1829c341366b5c0f3c7a3e6b69c790ec7f0743e3ccb3348fff5f7b372700f7857068d9ea069802f1ff5cf207ed4c03b0ddaaf54
|
7
|
+
data.tar.gz: a015d311cd0127c840684fbcb4d9a1b7907becc073ca580a3747162b3e9374ac6837e95f9e1f6a0f67fe1250008f73fb8338156364f9edd3634204a8ffd5d39f
|
data/README.md
CHANGED
@@ -1,6 +1,27 @@
|
|
1
1
|
# Hyperloop::Configuration
|
2
2
|
|
3
|
-
This gem is used internally by other [Hyperloop](http://ruby-hyperloop.io) gems for keeping config settings.
|
3
|
+
This gem is used internally by other [Hyperloop](http://ruby-hyperloop.io) gems for keeping config settings, and for registering client side autoload requirements.
|
4
|
+
|
5
|
+
To indicate gems to be autoloaded on client side:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require 'hyperloop-config'
|
9
|
+
Hyperloop.require 'my-gem-name', gem: true
|
10
|
+
Hyperloop.require_gem 'my-gem_name' # short for above
|
11
|
+
Hyperloop.require_gem 'my-gem-name', server_only: true
|
12
|
+
Hyperloop.require_gem 'my-gem-name', client_only: true
|
13
|
+
Hyperloop.require 'path', tree: true # same as saying require_tree 'path' in a manifest file
|
14
|
+
Hyperloop.require 'asset_name' # same as saying require 'asset_name' in a manifest file
|
15
|
+
```
|
16
|
+
|
17
|
+
The difference between `require_gem`, and `require` is that require_gem can be used inside a gem file spec.
|
18
|
+
|
19
|
+
Once a gem file spec does a `Hyperloop.require_gem` the listed gem will be automatically added to the `hyperloop-loader` manifest. This means all you do is add a gem
|
20
|
+
to rails, and it will get sent on to the client (plus any other dependencies you care to require.)
|
21
|
+
|
22
|
+
The require method can be used in the hyperloop initializer as well to add code to the manifest (i.e. add a gem to that is not using Hyperloop.require_gem)
|
23
|
+
|
24
|
+
To define an initializer:
|
4
25
|
|
5
26
|
```ruby
|
6
27
|
module Hyperloop
|
data/hyperloop-config.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "hyperloop-config"
|
7
|
-
spec.version = "0.9.
|
7
|
+
spec.version = "0.9.1"
|
8
8
|
spec.authors = ["catmando"]
|
9
9
|
spec.email = ["mitch@catprint.com"]
|
10
10
|
|
@@ -21,4 +21,16 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.12"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
|
25
|
+
spec.add_development_dependency 'hyper-spec'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'timecop'
|
28
|
+
spec.add_development_dependency 'opal-rails'
|
29
|
+
spec.add_development_dependency 'sqlite3'
|
30
|
+
spec.add_development_dependency 'rails'
|
31
|
+
spec.add_development_dependency 'jquery-rails'
|
32
|
+
|
33
|
+
# Keep linter-rubocop happy
|
34
|
+
spec.add_development_dependency 'rubocop'
|
35
|
+
|
24
36
|
end
|
data/lib/hyperloop-config.rb
CHANGED
@@ -10,11 +10,5 @@ else
|
|
10
10
|
require 'hyperloop/rail_tie' if defined? Rails
|
11
11
|
Hyperloop.require 'opal', gem: true
|
12
12
|
Hyperloop.require 'hyperloop-config', gem: true
|
13
|
-
# class Sprockets::DirectiveProcessor
|
14
|
-
# def process_depend_on_config_directive(file)
|
15
|
-
# path = File.expand_path(file, "#{Rails.root}/config")
|
16
|
-
# resolve(path)
|
17
|
-
# end
|
18
|
-
# end
|
19
13
|
Opal.append_path(File.expand_path('../', __FILE__).untaint)
|
20
14
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= Hyperloop.generate_requires(:server, __FILE__) %>
|
data/lib/hyperloop/rail_tie.rb
CHANGED
@@ -6,9 +6,10 @@ module Hyperloop
|
|
6
6
|
def delete_first(a, e)
|
7
7
|
a.delete_at(a.index(e) || a.length)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
|
+
def auto_config=(on)
|
10
11
|
Rails.configuration.tap do |config|
|
11
|
-
if
|
12
|
+
if on
|
12
13
|
config.eager_load_paths += %W(#{config.root}/app/hyperloop/models)
|
13
14
|
config.autoload_paths += %W(#{config.root}/app/hyperloop/models)
|
14
15
|
# config.eager_load_paths += %W(#{config.root}/app/hyperloop/stores)
|
@@ -17,9 +18,6 @@ module Hyperloop
|
|
17
18
|
config.autoload_paths += %W(#{config.root}/app/hyperloop/operations)
|
18
19
|
|
19
20
|
config.assets.paths.unshift ::Rails.root.join('app', 'hyperloop').to_s
|
20
|
-
config.eager_load_paths += %W(#{config.root}/app/models/public)
|
21
|
-
config.autoload_paths += %W(#{config.root}/app/models/public)
|
22
|
-
config.assets.paths.unshift ::Rails.root.join('app', 'models').to_s
|
23
21
|
else
|
24
22
|
delete_first config.eager_load_paths, "#{config.root}/app/hyperloop/models"
|
25
23
|
delete_first config.autoload_paths, "#{config.root}/app/hyperloop/models"
|
@@ -29,31 +27,31 @@ module Hyperloop
|
|
29
27
|
delete_first config.autoload_paths, "#{config.root}/app/hyperloop/operations"
|
30
28
|
|
31
29
|
delete_first config.assets.paths, ::Rails.root.join('app', 'hyperloop').to_s
|
32
|
-
delete_first config.eager_load_paths, %W(#{config.root}/app/models/public)
|
33
|
-
delete_first config.autoload_paths, %W(#{config.root}/app/models/public)
|
34
|
-
delete_first config.assets.paths, ::Rails.root.join('app', 'models').to_s
|
35
30
|
end
|
36
31
|
end
|
37
32
|
super
|
38
33
|
end
|
39
34
|
end
|
40
35
|
|
41
|
-
def add_hyperloop_directories(config)
|
42
|
-
return if config.hyperloop.key?(:add_directories) && !config.hyperloop.add_directories
|
43
|
-
Hyperloop.require_tree('views/components')
|
44
|
-
Hyperloop.require_tree('hyperloop')
|
45
|
-
Hyperloop.require_gem 'opal-jquery', override_with: :opal_jquery, client_only: true # move to hyper-component once things are working
|
46
|
-
end
|
47
|
-
|
48
36
|
# note in case of problems with eager load paths have a look at
|
49
37
|
# https://github.com/opal/opal-rails/blob/master/lib/opal/rails/engine.rb
|
50
38
|
config.hyperloop = Options.new
|
51
39
|
|
52
40
|
config.before_configuration do |app|
|
53
|
-
config.hyperloop.
|
41
|
+
config.hyperloop.auto_config = true
|
54
42
|
end
|
43
|
+
|
44
|
+
FILES = {files: ['hyperloop-prerender-loader.js']}
|
45
|
+
|
55
46
|
config.after_initialize do |app|
|
56
|
-
|
47
|
+
next unless config.hyperloop.auto_config
|
48
|
+
Hyperloop.require_tree('hyperloop')
|
49
|
+
next unless config.respond_to?(:react)
|
50
|
+
if (opts = config.react.server_renderer_options)
|
51
|
+
opts.merge! FILES
|
52
|
+
else
|
53
|
+
config.react.server_renderer_options = FILES
|
54
|
+
end
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
data/lib/hyperloop/requires.rb
CHANGED
@@ -4,72 +4,90 @@ module Hyperloop
|
|
4
4
|
@requires ||= []
|
5
5
|
end
|
6
6
|
|
7
|
-
def require(value, gem: nil,
|
8
|
-
if
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
def require(value, gem: nil, instead_of: nil, client_only: nil, server_only: nil, tree: nil)
|
8
|
+
if instead_of
|
9
|
+
current_spec = requires.detect { |old_value, *_rest| instead_of == old_value }
|
10
|
+
if current_spec
|
11
|
+
current_spec[0] = value
|
12
|
+
else
|
13
|
+
raise [
|
14
|
+
"Could not substitute require '#{instead_of}' with '#{value}'. '#{instead_of}' not found.",
|
15
|
+
'The following requires are listed:',
|
16
|
+
*requires.collect { |old_value, *_rest| old_value }
|
17
|
+
].join("\n")
|
13
18
|
end
|
19
|
+
else
|
20
|
+
kind = if gem
|
21
|
+
:gem
|
22
|
+
elsif tree
|
23
|
+
:tree
|
24
|
+
end
|
25
|
+
requires << [value, !client_only, !server_only, kind]
|
14
26
|
end
|
15
|
-
kind = if gem
|
16
|
-
:gem
|
17
|
-
elsif tree
|
18
|
-
:tree
|
19
|
-
end
|
20
|
-
requires << [override_with, value, client_only, kind]
|
21
27
|
end
|
22
28
|
|
23
|
-
def
|
24
|
-
require(
|
29
|
+
def unrequire(value)
|
30
|
+
require(nil, instead_of: value)
|
25
31
|
end
|
26
32
|
|
27
|
-
def
|
28
|
-
require(value,
|
33
|
+
def require_tree(value, instead_of: nil, client_only: nil, server_only: nil)
|
34
|
+
require(value, instead_of: instead_of, client_only: client_only, server_only: server_only, tree: true)
|
35
|
+
end
|
36
|
+
|
37
|
+
def require_gem(value, instead_of: nil, client_only: nil, server_only: nil)
|
38
|
+
require(value, instead_of: instead_of, client_only: client_only, server_only: server_only, gem: true)
|
29
39
|
end
|
30
40
|
|
31
41
|
def generate_requires(mode, file)
|
32
42
|
puts "***** generating requires for #{mode} - #{file}"
|
33
|
-
requires.collect do |
|
43
|
+
requires.collect do |value, render_on_server, render_on_client, kind|
|
34
44
|
next unless value
|
35
|
-
next if
|
45
|
+
next if mode == :client && !render_on_client
|
46
|
+
next if mode == :server && !render_on_server
|
36
47
|
if kind == :tree
|
37
|
-
generate_require_tree(value,
|
48
|
+
generate_require_tree(value, render_on_server, render_on_client)
|
38
49
|
elsif kind == :gem
|
39
|
-
r = "require '#{value}' #{client_guard(
|
50
|
+
r = "require '#{value}' #{client_guard(render_on_server, render_on_client)}"
|
40
51
|
puts r
|
41
52
|
"puts \"#{r}\"; #{r}"
|
42
53
|
else
|
43
|
-
generate_directive(:require, value, file,
|
54
|
+
generate_directive(:require, value, file, render_on_server, render_on_client)
|
44
55
|
end
|
45
56
|
end.compact.join("\n")
|
46
57
|
end
|
47
58
|
|
48
|
-
def generate_directive(directive, to, file,
|
59
|
+
def generate_directive(directive, to, file, render_on_server, render_on_client)
|
49
60
|
gem_path = File.expand_path('../', file).split('/')
|
50
61
|
comp_path = Rails.root.join('app', 'hyperloop', to).to_s.split('/')
|
51
62
|
while comp_path.first == gem_path.first do
|
52
63
|
gem_path.shift
|
53
64
|
comp_path.shift
|
54
65
|
end
|
55
|
-
r = "#{directive} '#{(['.'] + ['..'] * gem_path.length + comp_path).join('/')}' #{client_guard(
|
66
|
+
r = "#{directive} '#{(['.'] + ['..'] * gem_path.length + comp_path).join('/')}' #{client_guard(render_on_server, render_on_client)}"
|
56
67
|
puts r
|
57
68
|
"puts \"#{r}\"; #{r}"
|
58
69
|
end
|
59
70
|
|
60
|
-
def generate_require_tree(path,
|
71
|
+
def generate_require_tree(path, render_on_server, render_on_client)
|
61
72
|
base_name = Rails.root.join('app', path).to_s+'/'
|
62
73
|
Dir.glob(Rails.root.join('app', path, '**', '*')).collect do |fname|
|
63
|
-
|
64
|
-
|
74
|
+
fname = fname.gsub(/^#{base_name}/, '')
|
75
|
+
fname = fname.gsub(/\.erb$/, '')
|
76
|
+
if fname =~ /(\.js$)|(\.rb$)/
|
77
|
+
fname = fname.gsub(/(\.js$)|(\.rb$)/, '')
|
78
|
+
r = "require '#{fname}' #{client_guard(render_on_server, render_on_client)}"
|
65
79
|
puts r
|
66
80
|
"puts \"#{r}\"; #{r}"
|
67
81
|
end
|
68
82
|
end.compact.join("\n")
|
69
83
|
end
|
70
84
|
|
71
|
-
def client_guard(
|
72
|
-
|
85
|
+
def client_guard(render_on_server, render_on_client)
|
86
|
+
if !render_on_server
|
87
|
+
'# CLIENT ONLY'
|
88
|
+
elsif !render_on_client
|
89
|
+
'# SERVER ONLY'
|
90
|
+
end
|
73
91
|
end
|
74
92
|
|
75
93
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyperloop-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- catmando
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -52,6 +52,118 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hyper-spec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: timecop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: opal-rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rails
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: jquery-rails
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
55
167
|
description:
|
56
168
|
email:
|
57
169
|
- mitch@catprint.com
|
@@ -65,12 +177,11 @@ files:
|
|
65
177
|
- LICENSE.txt
|
66
178
|
- README.md
|
67
179
|
- Rakefile
|
68
|
-
- hyperloop-config-0.8.1.gem
|
69
180
|
- hyperloop-config.gemspec
|
70
|
-
- lib/components.rb.erb
|
71
181
|
- lib/hyperloop-config.rb
|
72
182
|
- lib/hyperloop-loader.js
|
73
183
|
- lib/hyperloop-loader2.rb.erb
|
184
|
+
- lib/hyperloop-prerender-loader.rb.erb
|
74
185
|
- lib/hyperloop/client_readers.rb
|
75
186
|
- lib/hyperloop/client_stubs.rb
|
76
187
|
- lib/hyperloop/config_settings.rb
|
data/hyperloop-config-0.8.1.gem
DELETED
Binary file
|
data/lib/components.rb.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<%= Hyperloop.generate_requires(:prerendering, __FILE__) %>
|