wedge 0.1.24 → 0.1.26

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: 7cd9d55e9e4a4e2552a9161a708dd2ca7ed3b9f9
4
- data.tar.gz: c47e4e82a4a15245592838be2b34bf7b0d5f6c84
3
+ metadata.gz: 78f40ecf9915213fae0d4d1e04a9b540d2d3478d
4
+ data.tar.gz: a14f6a410247c07a2622382cd7f0167286b13fab
5
5
  SHA512:
6
- metadata.gz: 9570eae6b1a09a342bb2fee0a664e6eb81706c46725ed755caa6fa044fbd36c27ca11be168b04b864b99734b36509219bfd12776eba6490301848e5214b1e654
7
- data.tar.gz: e26f5afdf65df26d7f139456e9f7a78b0705714af66789318269dbbab7f72edbfef294d5c936b0e6fdfdc784143dfa1db63190af25df1933a377c7a25858a86d
6
+ metadata.gz: 863fe684a8d673637de4a47553bac75278a8343d875bd84bca7223709885d5c4617cc4ab936e9da639e08cf12b44f07860938c1b872f37e2c3fb2d533e7fbb05
7
+ data.tar.gz: 397aea986f9d2f14da80e80988d51a2ae3f02cb167435c6d2c51502bba822a57e2de0bbf02b78691ada2c64983f9777356bddda313c0987a9eb70c50611ff137
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in BrowserIO.gemspec
4
4
  gemspec
5
5
 
6
- gem 'opal', github: 'opal/opal'
6
+ gem 'opal'
7
7
  gem 'opal-jquery', github: 'opal/opal-jquery'
8
8
  gem 'opal-rspec-cj'
9
9
  gem 'binding_of_caller'
data/Rakefile CHANGED
@@ -9,26 +9,28 @@ require 'bundler'
9
9
  require 'bundler/gem_tasks'
10
10
  require 'bundler/setup'
11
11
 
12
- require 'config/boot'
13
- require 'tilt/erubis'
14
- require 'opal/rspec/rake_task'
15
-
16
- Opal.append_path File.expand_path('../lib', __FILE__)
17
- Opal.append_path File.expand_path('../playground/app', __FILE__)
18
- Opal.append_path File.expand_path('../playground/public', __FILE__)
19
-
20
- Opal::RSpec::RakeTask.new('opal:rspec', Playground) do |s|
21
- s.index_path = 'spec/index.html.erb'
22
- end
23
-
24
- task default: [:test]
25
-
26
- require 'rspec/core/rake_task'
27
- RSpec::Core::RakeTask.new('ruby:rspec')
28
-
29
- task :test do
30
- puts "--------------------------\nRun specs in Ruby\n--------------------------"
31
- Rake::Task['ruby:rspec'].invoke
32
- puts "--------------------------\nRun specs in Opal\n--------------------------"
33
- Rake::Task['opal:rspec'].invoke
12
+ if current_task['default'] || current_task['test'] || current_task[/:rspec/]
13
+ require 'config/boot'
14
+ require 'tilt/erubis'
15
+ require 'opal/rspec/rake_task'
16
+
17
+ Opal.append_path File.expand_path('../lib', __FILE__)
18
+ Opal.append_path File.expand_path('../playground/app', __FILE__)
19
+ Opal.append_path File.expand_path('../playground/public', __FILE__)
20
+
21
+ Opal::RSpec::RakeTask.new('opal:rspec', Playground) do |s|
22
+ s.index_path = 'spec/index.html.erb'
23
+ end
24
+
25
+ task default: [:test]
26
+
27
+ require 'rspec/core/rake_task'
28
+ RSpec::Core::RakeTask.new('ruby:rspec')
29
+
30
+ task :test do
31
+ puts "--------------------------\nRun specs in Ruby\n--------------------------"
32
+ Rake::Task['ruby:rspec'].invoke
33
+ puts "--------------------------\nRun specs in Opal\n--------------------------"
34
+ Rake::Task['opal:rspec'].invoke
35
+ end
34
36
  end
data/lib/wedge.rb CHANGED
@@ -60,11 +60,46 @@ class Wedge
60
60
  DOM.new html
61
61
  end
62
62
 
63
- def script_tag
64
- "<script src='#{assets_url_with_host}/wedge.js'></script>"
65
- end
66
-
67
63
  unless RUBY_ENGINE == 'opal'
64
+ # def script_tag
65
+ # # note: ?body=1 is a hack for sprockets to make source maps work # correctly.
66
+ # "<script src='#{assets_url_with_host}/wedge.js#{Wedge.config.debug ? '?body=1' : ''}' type='text/javascript'></script>"
67
+ # end
68
+
69
+ def script_tag name = 'wedge'
70
+ sprockets = Wedge.config.opal[:server].sprockets
71
+ prefix = Wedge.config.opal[:server].prefix
72
+ asset = sprockets[name]
73
+ raise "Cannot find asset: #{name}" if asset.nil?
74
+ scripts = []
75
+
76
+ get_asset_urls(name).each do |url|
77
+ scripts << %{<script src="#{url}"></script>}
78
+ end
79
+
80
+ scripts << %{<script>#{Wedge::Opal::Processor.load_asset_code(sprockets, name)}</script>}
81
+
82
+ scripts.join "\n"
83
+ end
84
+
85
+ def get_asset_urls name
86
+ sprockets = Wedge.config.opal[:server].sprockets
87
+ prefix = Wedge.config.opal[:server].prefix
88
+ asset = sprockets[name]
89
+ raise "Cannot find asset: #{name}" if asset.nil?
90
+ urls = []
91
+
92
+ if Wedge.config.opal[:server].debug
93
+ asset.to_a.map do |dependency|
94
+ urls << %{#{prefix}/#{dependency.logical_path}?body=1}
95
+ end
96
+ else
97
+ urls << %{#{prefix}/#{name}.js}
98
+ end
99
+
100
+ urls
101
+ end
102
+
68
103
  def javascript_cache
69
104
  @javascript_cache ||= IndifferentHash.new
70
105
  end
@@ -146,31 +181,57 @@ class Wedge
146
181
  build(path_name, options).to_s
147
182
  end
148
183
  else
149
- url = "#{Wedge.assets_url_with_host}/#{options[:path]}.js"
184
+ # note: ?body=1 is a hack for sprockets to make source maps work # correctly.
185
+ # url = "#{url}?body=1" if Wedge.config.debug
150
186
  cache = options[:cache_assets]
151
187
 
152
- `jQuery.ajax({ url: url, dataType: "script", cache: cache }).done(function() {`
153
- # fix: at the moment to_js called from the server will set the class
154
- # store for whatever method it calls. we need to think of a better idea
155
- # for global and local data store.
156
- Wedge.config.component_class[options[:name]].config.store = options[:store].indifferent
188
+ if !Wedge.config.debug
189
+ url = "#{Wedge.assets_url_with_host}/#{options[:path]}.js"
157
190
 
158
- if initialize_args = options.delete(:initialize_args)
159
- comp = Wedge[options[:name], *initialize_args]
160
- else
161
- comp = Wedge[options[:name]]
162
- end
191
+ `jQuery.ajax({ url: url, dataType: "script", cache: cache }).done(function() {`
192
+ trigger_javascript_loaded path_name, options
193
+ `}).fail(function(jqxhr, settings, exception){ window.console.log(exception); })`
194
+ else
195
+ url = "#{Wedge.assets_url_with_host}/wedge/list_assets.call"
196
+ payload = { path_name: path_name}
197
+ headers = {
198
+ 'X-CSRF-TOKEN' => Element.find('meta[name=_csrf]').attr('content'),
199
+ }
200
+ HTTP.post(url, dataType: 'json', headers: headers, payload: payload) do |response|
201
+ res = JSON.from_object(`response`)
202
+
203
+ res[:body][:urls].each do |url|
204
+ `jQuery.ajax({url: url, dataType: "script", cache: cache, async: false})`
205
+ end
163
206
 
164
- if options[:method_args].any?
165
- comp.send(options[:method_called], options[:method_args])
166
- else
167
- comp.send(options[:method_called])
207
+ code = res[:body][:code]
208
+ `jQuery.globalEval(code);`
209
+
210
+ trigger_javascript_loaded path_name, options
168
211
  end
212
+ end
213
+ end
214
+ end
215
+
216
+ def trigger_javascript_loaded path_name, options
217
+ # fix: at the moment to_js called from the server will set the class
218
+ # store for whatever method it calls. we need to think of a better idea
219
+ # for global and local data store.
220
+ Wedge.config.component_class[options[:name]].config.store = options[:store].indifferent
169
221
 
170
- Wedge.trigger_browser_events
222
+ if initialize_args = options.delete(:initialize_args)
223
+ comp = Wedge[options[:name], *initialize_args]
224
+ else
225
+ comp = Wedge[options[:name]]
226
+ end
171
227
 
172
- `}).fail(function(jqxhr, settings, exception){ window.console.log(exception); })`
228
+ if options[:method_args].any?
229
+ comp.send(options[:method_called], options[:method_args])
230
+ else
231
+ comp.send(options[:method_called])
173
232
  end
233
+
234
+ Wedge.trigger_browser_events
174
235
  end
175
236
 
176
237
  def config
@@ -196,7 +196,6 @@ class Wedge
196
196
  'X-CSRF-TOKEN' => Element.find('meta[name=_csrf]').attr('content'),
197
197
  'X-WEDGE-METHOD-REQUEST' => meth
198
198
  },
199
- async: false,
200
199
  payload: payload) do |response|
201
200
 
202
201
  # We set the new csrf token
data/lib/wedge/config.rb CHANGED
@@ -36,7 +36,8 @@ class Wedge
36
36
  server_methods: [],
37
37
  initialize_args: [],
38
38
  plugins: [],
39
- allowed_client_data: %w(name path method_args method_called store tmpl key cache_assets assets_key assets_url assets_url_with_host)
39
+ opal: {},
40
+ allowed_client_data: %w(debug name path method_args method_called store tmpl key cache_assets assets_key assets_url assets_url_with_host)
40
41
  }.merge(opts))
41
42
  end
42
43
 
@@ -11,24 +11,25 @@ class Wedge
11
11
  settings.each { |k, v| Wedge.config.send "#{k}=", v }
12
12
  end
13
13
 
14
- @opal = { server: Wedge::Opal::Server.new { |s|
14
+ Wedge.config.opal = { server: Wedge::Opal::Server.new { |s|
15
15
  s.prefix = Wedge.config.assets_url
16
16
  s.debug = Wedge.config.debug
17
17
  s.append_path "#{Dir.pwd}/#{Wedge.config.app_dir}"
18
18
  }}
19
19
 
20
20
  if Wedge.config.debug
21
- @opal[:sprockets] = @opal[:server].sprockets
22
- @opal[:maps_prefix] = "#{Wedge.config.assets_url}/__OPAL_SOURCE_MAPS__"
23
- @opal[:maps_app] = Opal::SourceMapServer.new @opal[:sprockets], @opal[:maps_prefix]
21
+ Wedge.config.opal[:sprockets] = Wedge.config.opal[:server].sprockets
22
+ Wedge.config.opal[:maps_prefix] = "#{Wedge.config.assets_url}/__OPAL_SOURCE_MAPS__"
23
+ Wedge.config.opal[:maps_app] = Opal::SourceMapServer.new Wedge.config.opal[:sprockets], Wedge.config.opal[:maps_prefix]
24
24
 
25
- Wedge::Opal::Sprockets::SourceMapHeaderPatch.inject! @opal[:maps_prefix]
25
+ Wedge::Opal::Sprockets::SourceMapHeaderPatch.inject! Wedge.config.opal[:maps_prefix]
26
26
  end
27
27
  end
28
28
 
29
29
  @app = app
30
30
  @scope = self.class.scope
31
31
  @skip_call = !self.class.skip_call.nil?? self.class.skip_call : Wedge.config.skip_call_middleware
32
+ @opal = Wedge.config.opal
32
33
  end
33
34
 
34
35
  def call(env)
@@ -88,7 +89,13 @@ class Wedge
88
89
  method_called = data.delete(:__wedge_method__)
89
90
  method_args = data.delete(:__wedge_args__)
90
91
 
91
- if method_args == '__wedge_data__' && data
92
+
93
+ if wedge_path == 'wedge/list_assets'
94
+ res = {
95
+ urls: Wedge.get_asset_urls(data[:path_name]),
96
+ code: Wedge::Opal::Processor.load_asset_code(Wedge.config.opal[:server].sprockets, data[:path_name])
97
+ }
98
+ elsif method_args == '__wedge_data__' && data
92
99
  method_args = [data]
93
100
  res = Wedge.scope!(scope, method_called)[name].send(method_called, *method_args) || ''
94
101
  else
@@ -14,8 +14,7 @@ class Wedge
14
14
  %w'ability_list current_user'.each do |type|
15
15
  config.compile_str ||= ''
16
16
  path = Wedge.config.component_class[:"#{type}"].config.path
17
- code = File.read("#{Dir.pwd}/#{Wedge.config.app_dir}/#{path}.rb")
18
- config.compile_str << Opal.original_compile("require 'wedge/plugins/#{type}'; #{code}")
17
+ config.compile_str << Wedge.javascript(path)
19
18
  end if for_client
20
19
  end
21
20
 
data/lib/wedge/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Wedge
2
- VERSION = '0.1.24'
2
+ VERSION = '0.1.26'
3
3
  end
@@ -16,7 +16,7 @@ class Playground
16
16
 
17
17
  head.add_child assets [:css, :default]
18
18
  html.add_child assets [:js, :default]
19
- html.add_child Wedge.script_tag
19
+ html.add_child Wedge.script_tag 'wedge'
20
20
 
21
21
  inline_tags.each do |tag|
22
22
  html.add_child tag
data/wedge.gemspec CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "opal"
22
- spec.add_runtime_dependency "opal-jquery"
21
+ spec.add_runtime_dependency "opal", '~> 0.8.0.rc1'
22
+ spec.add_runtime_dependency "opal-jquery", '~> 0.3.0'
23
23
  spec.add_runtime_dependency "nokogiri"
24
24
 
25
25
  spec.add_development_dependency 'rspec'
@@ -27,7 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "rake"
28
28
  spec.add_development_dependency "awesome_print"
29
29
  spec.add_development_dependency "yard"
30
- spec.add_development_dependency "phantomjs.rb"
31
30
  spec.add_development_dependency 'roda'
32
31
 
33
32
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wedge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.24
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-01 00:00:00.000000000 Z
11
+ date: 2015-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.8.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.8.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: opal-jquery
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -122,20 +122,6 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: phantomjs.rb
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
125
  - !ruby/object:Gem::Dependency
140
126
  name: roda
141
127
  requirement: !ruby/object:Gem::Requirement