opal-connect 0.0.8 → 0.0.9

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: 9cff9dcf8a66a0ca2119adcf3fce943b40b03cba
4
- data.tar.gz: c875f500590d114afef77540202d8825291a9874
3
+ metadata.gz: f88b83b2a3997a5d494b41fedd83777c104a05c9
4
+ data.tar.gz: 1dcededce0860ec8c3314a74900950c17d862147
5
5
  SHA512:
6
- metadata.gz: 7e8fbfe0d1925ed42764343cec7ebd1629c56ec4ef980d8110a4dfd5b282967ad94faddfeb8b3137004ef88afce88b4bc2e4e17fd4da0ba249145f5f42a9aa0e
7
- data.tar.gz: 662b9cbeafd47b5f3b7b0a682315112b9e4473ee9214c11dcdd3d59ad7d30f193a947652d96291c2e38946da36152117b881f05e07679085c29ad1f287b1cc83
6
+ metadata.gz: 6094189c9f0a4c87911703e7968a42814a4ff6d90871472999f328cbfa9089c21cf7a7e2bef1e1ae40bf26571e6c4ec9b09ee367130fad5c7b83fde56f8a55b6
7
+ data.tar.gz: 6a7ba6691da29aed4eee614188414680ea040d1408b01caa0c19ddda88282ff9c41af6aede4d94ad40815b7861baf8be45c83a5d08d4cf5d9911bb31127c4dd2
@@ -7,7 +7,8 @@ module Opal
7
7
  module InstanceMethods
8
8
  def connect_event_instance_variables(event, _name, _selector)
9
9
  # gives you access to this, like jquery
10
- @this = dom event.current_target
10
+ @this = dom event.current_target
11
+ @event = event
11
12
  end
12
13
  end
13
14
 
@@ -25,6 +25,12 @@ module Opal
25
25
  end
26
26
  end
27
27
 
28
+ module ClassMethods
29
+ def html!(&block)
30
+ HTML::DSL.scope!(self).html!(&block).to_html
31
+ end
32
+ end
33
+
28
34
  # http://erikonrails.snowedin.net/?p=379
29
35
  class DSL
30
36
  def initialize(tag, *args, &block)
@@ -2,6 +2,12 @@ module Opal
2
2
  module Connect
3
3
  module ConnectPlugins
4
4
  module Scope
5
+ def self.configure(connect, options = false)
6
+ return unless options
7
+
8
+ connect.options[:scope] = options
9
+ end
10
+
5
11
  module InstanceMethods
6
12
  def scope(new_scope = false)
7
13
  if new_scope
@@ -23,8 +29,12 @@ module Opal
23
29
  end
24
30
 
25
31
  module ClassMethods
26
- def scope(scope, *args)
27
- new(*args).scope(scope)
32
+ def scope(new_scope = false, *args)
33
+ if new_scope
34
+ @_scope = new(*args).scope(new_scope || Connect.options[:scope])
35
+ else
36
+ @_scope
37
+ end
28
38
  end
29
39
  end
30
40
  end
@@ -19,7 +19,12 @@ module Opal
19
19
 
20
20
  def server(method = false, *args, &block)
21
21
  if RUBY_ENGINE != 'opal'
22
- method ||= Module.new(&block)
22
+
23
+ if method
24
+ include method
25
+ else
26
+ method = Module.new(&block)
27
+ end
23
28
 
24
29
  yield if block_given?
25
30
 
@@ -9,8 +9,11 @@ module Opal
9
9
  options = DEFAULT_OPTIONS.merge opts
10
10
 
11
11
  namespace name do
12
- Opal::Connect.setup
13
- Opal::Config.dynamic_require_severity = 'ignore'
12
+ return unless defined? Opal.append_path
13
+
14
+ Opal::Connect.write_plugins_file
15
+ Opal::Connect.write_entry_file
16
+
14
17
  Opal.append_path Dir.pwd
15
18
 
16
19
  opal_file_path = "#{Dir.pwd}/.connect/opal.js"
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module Connect
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
data/lib/opal/connect.rb CHANGED
@@ -19,70 +19,24 @@ module Opal
19
19
  class << self
20
20
  attr_accessor :pids
21
21
 
22
- def run(scope, server, opts = {})
23
- if ENV['CUTEST']
24
- scope.run server
25
- else
26
- @pids = []
27
- options = { env: { RACK_ENV: ENV['RACK_ENV']} }.merge opts
28
-
29
- envs = options[:env].to_a.map { |k, v| "#{k}=#{v}" }.join ' '
30
- pids << {
31
- name: 'webpack',
32
- pid: Process.spawn("#{envs} bundle exec rake webpack:run")
33
- }
34
-
35
- if (cutest = Connect.options[:cutest]) && pids.select { |pid| pid[:name] == 'cutest' }.empty?
36
- envs = cutest[:env].to_a.map { |k, v| "#{k}=#{v}" }.join ' '
37
- pids << {
38
- name: 'cutest',
39
- pid: Process.spawn("#{envs} #{cutest[:run]}")
40
- }
41
- end
42
-
43
- scope.send(:at_exit) { quit_pids }
44
-
45
- scope.run server
46
- end
47
- rescue
48
- quit_pids
49
- end
50
-
51
- def quit_pids
52
- begin
53
- while pids.length > 0
54
- Process.kill "QUIT", (pids.shift)[:pid]
55
- end
56
- rescue
57
- # process already dead
58
- end
59
- end
60
-
61
22
  def options
62
- @options ||= Connect::ConnectCache.new(
23
+ @_options ||= Connect::ConnectCache.new(
63
24
  hot_reload: false,
64
25
  url: '/connect',
65
26
  plugins: [],
66
- setup_ran: false,
67
27
  javascript: [],
68
- plugin_requires: []
28
+ plugin_requires: [],
29
+ setup_blocks: []
69
30
  )
70
31
  end
71
32
 
72
- def options=(opts)
73
- @options = opts
74
- end if RUBY_ENGINE == 'opal'
75
-
76
33
  def setup(&block)
77
34
  instance_exec(&block) if block_given?
78
35
 
79
36
  # make sure we include the default plugins with connect
80
37
  options[:plugins].each { |plug| Connect.plugin plug }
81
38
 
82
- unless RUBY_ENGINE == 'opal'
83
- write_plugins_file
84
- write_entry_file
85
- end
39
+ options[:setup_blocks].each { |b| Class.new { include Opal::Connect }.new.instance_exec(&b) }
86
40
  end
87
41
 
88
42
  def included(klass)
@@ -239,7 +193,12 @@ module Opal
239
193
  end
240
194
 
241
195
  def setup(&block)
242
- yield
196
+ if block_given?
197
+ @_setup_block = block
198
+ Connect.options[:setup_blocks] << @_setup_block
199
+ else
200
+ @_setup_block
201
+ end
243
202
  end
244
203
 
245
204
  # Load a new plugin into the current class. A plugin can be a module
@@ -252,23 +211,31 @@ module Opal
252
211
  included = (args.first == :included) ? args.shift : false
253
212
 
254
213
  raise ConnectError, "Cannot add a plugin to a frozen Connect class" if RUBY_ENGINE != 'opal' && frozen?
214
+
255
215
  if plugin.is_a?(Symbol)
256
216
  Connect.options[:plugins] << plugin unless Connect.options[:plugins].include? plugin
257
217
  plugin = ConnectPlugins.load_plugin(plugin)
258
218
  end
219
+
259
220
  plugin.load_dependencies(self, *args, &block) if !included && plugin.respond_to?(:load_dependencies)
221
+
260
222
  return unless plugin
223
+
261
224
  include(plugin::InstanceMethods) if defined?(plugin::InstanceMethods)
262
- extend(plugin::ClassMethods) if defined?(plugin::ClassMethods)
225
+ extend(plugin::ClassMethods) if defined?(plugin::ClassMethods)
226
+
263
227
  unless included
264
228
  Connect.extend(plugin::ConnectClassMethods) if defined?(plugin::ConnectClassMethods)
265
229
  Connect.include(plugin::ConnectInstanceMethods) if defined?(plugin::ConnectInstanceMethods)
266
230
  Connect.instance_exec(plugin, &plugin::ConnectSetup) if defined?(plugin::ConnectSetup)
231
+
267
232
  unless RUBY_ENGINE == 'opal'
268
233
  Connect.options[:javascript] << plugin::ConnectJavascript if defined?(plugin::ConnectJavascript)
269
234
  end
270
235
  end
236
+
271
237
  plugin.configure(self, *args, &block) if !included && plugin.respond_to?(:configure)
238
+
272
239
  nil
273
240
  end
274
241
 
@@ -307,7 +274,7 @@ module Opal
307
274
 
308
275
  Opal::Connect.start_events unless $connect_events_started
309
276
  end
310
- }
277
+ } if klass.class.name
311
278
  end
312
279
 
313
280
  def write_entry_file(klass = false, method = false, *options)
@@ -323,15 +290,23 @@ module Opal
323
290
 
324
291
  client_options = Base64.encode64 client_options.to_json
325
292
 
326
- code = "Opal::Connect.options = JSON.parse(Base64.decode64('#{client_options}'));"
327
- code = "#{code} Opal::Connect.setup;"
293
+ code = %{
294
+ options = JSON.parse(Base64.decode64('#{client_options}'));
295
+ options.each do |key, value|
296
+ Opal::Connect.options[key] = value
297
+ end
298
+ }
299
+ code = "#{code} Opal::Connect.options[:plugins].each { |plug| Opal::Connect.plugin plug };"
300
+
328
301
  if Connect.respond_to? :templates
329
302
  templates = Base64.encode64 Connect.templates.hash.to_json
330
303
  code = "#{code} Opal::Connect.templates = JSON.parse(Base64.decode64('#{templates}'));"
331
304
  end
305
+
332
306
  code = %{#{code} Opal::Connect.server_methods = JSON.parse(
333
307
  Base64.decode64('#{Base64.encode64 Connect.server_methods.to_json}')
334
308
  );}
309
+
335
310
  code = "#{code} #{Connect.options[:entry]}" if Connect.options[:entry]
336
311
 
337
312
 
@@ -360,6 +335,8 @@ module Opal
360
335
  }
361
336
  end
362
337
 
338
+ code = "#{code} Opal::Connect.options[:setup_blocks].each { |b| Class.new { include Opal::Connect }.new.instance_exec(&b) }"
339
+
363
340
  FileUtils.mkdir_p(File.dirname(path))
364
341
  File.write(path, build(code))
365
342
  end
@@ -368,10 +345,6 @@ module Opal
368
345
  end
369
346
  end
370
347
 
371
- if RUBY_ENGINE == 'opal'
372
- require ".connect/plugins"
373
- end
374
-
375
348
  extend ConnectPlugins::Base::ClassMethods
376
349
  plugin ConnectPlugins::Base
377
350
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-connect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-05 00:00:00.000000000 Z
11
+ date: 2016-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal