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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbfe28115b632c56ba9de41cc1ddf85b03fca677
4
- data.tar.gz: ba129aab203299356c2a014f5c46f24195d58918
3
+ metadata.gz: 7f732c8828c572f731b2515c7e4feef8cf1a63ce
4
+ data.tar.gz: 40b1671bcfa35dea5db6d2c9185901b831961509
5
5
  SHA512:
6
- metadata.gz: 5ea1e85025c0ca6989ebe22b6d13867b66bd5e2db99febde06c7b438a5adcac6f69d618e1eb0324376318a3f2c413a167c32e2b0ca50db370ef530c54f600037
7
- data.tar.gz: 5e94e29e21f7e202d0a301924b6401578fcfb05025d5b449a2e3b54faf82a20d03c96457fb0ae6502be8a018b9326ad37cc5187f7fc948ea4c038ef764891ef6
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
@@ -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.0"
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
@@ -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__) %>
@@ -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
- def add_paths=(x)
9
+
10
+ def auto_config=(on)
10
11
  Rails.configuration.tap do |config|
11
- if x
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.add_paths = true
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
- add_hyperloop_directories(app.config)
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
@@ -4,72 +4,90 @@ module Hyperloop
4
4
  @requires ||= []
5
5
  end
6
6
 
7
- def require(value, gem: nil, override_with: nil, client_only: nil, tree: nil)
8
- if override_with
9
- define_class_method "#{override_with}=" do |value|
10
- requires.detect do |name, _value, _client_only, _kind|
11
- name == override_with
12
- end[1] = value
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 require_tree(value, override_with: nil, client_only: nil)
24
- require(value, override_with: override_with, client_only: client_only, tree: true)
29
+ def unrequire(value)
30
+ require(nil, instead_of: value)
25
31
  end
26
32
 
27
- def require_gem(value, override_with: nil, client_only: nil)
28
- require(value, override_with: override_with, client_only: client_only, gem: true)
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 |name, value, client_only, kind|
43
+ requires.collect do |value, render_on_server, render_on_client, kind|
34
44
  next unless value
35
- next if client_only && mode != :client
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, client_only)
48
+ generate_require_tree(value, render_on_server, render_on_client)
38
49
  elsif kind == :gem
39
- r = "require '#{value}' #{client_guard(client_only)}"
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, client_only)
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, client_only = false)
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(client_only)}"
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, client_only)
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
- if ['.js', '.rb', '.erb'].include? File.extname(fname)
64
- r = "require '#{fname.gsub(base_name, '')}' #{client_guard(client_only)}"
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(client_only)
72
- "# CLIENT ONLY" if client_only
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.0
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 00:00:00.000000000 Z
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
Binary file
@@ -1 +0,0 @@
1
- <%= Hyperloop.generate_requires(:prerendering, __FILE__) %>