roda-component 0.1.33 → 0.1.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fcaa4c0679c09e6a9069c746125953d2b99ff0a
4
- data.tar.gz: 371d39e0be53e7a81630ab70da3c4b2729c65218
3
+ metadata.gz: 9619f6a2faccd6bdc5c5807da80281688b65fb7b
4
+ data.tar.gz: 41c4d0675c13804033f5827b28371d92d4a3959f
5
5
  SHA512:
6
- metadata.gz: 00b04cc7fb8befcc3d4539bac1659301df76124f18f4ee4a87f9bc164bd103769016e27fc3fea1b528d6f5a53035cfd16e205c09457cf0d5853d7dabad415822
7
- data.tar.gz: db05cde6ce3cf267299e9ae88a3dc342b607a86f350302bb706120518ce251171089e383d281c698b4a616dd847089298dbd2407450b09977fab7ccc8ae4a003
6
+ metadata.gz: 6a908cb1261aad8d41fd009fd1564c687d08f53643da59ac0beb5d1026bdb365f45e31c0257f33767c662123cdc8f14a89a7cde852a28f6d99d6b9d1bee0c8b6
7
+ data.tar.gz: 2bd4aadf95c10e0604b7e6bbe60b1b6bf6e1d954ac7f6740c7f97547c859ae074a94f24232f3e205cde14fb63d6d52c4f83abf0046d05c937029be44fe7246eb
@@ -105,10 +105,11 @@ class Roda
105
105
  end
106
106
 
107
107
  class Component
108
- attr_accessor :scope, :cache
108
+ def initialize(data = false)
109
+ end
109
110
 
110
- def initialize(scope = false)
111
- @scope = scope
111
+ def _initialize(scope = false)
112
+ @_scope = scope
112
113
 
113
114
  if client? && !$component_opts[:faye][:"#{self.class._name}"]
114
115
  $component_opts[:faye][:"#{self.class._name}"] = true
@@ -135,11 +136,19 @@ class Roda
135
136
  trigger :disconnect
136
137
  end
137
138
  end
139
+
138
140
  end
139
141
 
140
142
  class << self
141
143
  attr_accessor :_name
142
144
 
145
+ def new(*args, &block)
146
+ obj = self.allocate
147
+ obj.instance_variable_set :@_scope, args.shift
148
+ obj.send :initialize, *args, &block
149
+ obj
150
+ end
151
+
143
152
  if RUBY_ENGINE == 'ruby'
144
153
  def inherited(subclass)
145
154
  super
@@ -396,13 +405,13 @@ class Roda
396
405
 
397
406
  if RUBY_ENGINE == 'opal'
398
407
  def component name, options = {}, &block
399
- comp = load_component name
400
-
401
- action = options.delete(:call) || :display
402
- trigger = options.delete(:trigger) || false
408
+ action = options.delete(:call)
409
+ trigger = options.delete(:trigger)
403
410
  js = options.delete(:js)
404
411
  args = options.delete(:args)
405
412
 
413
+ comp = load_component name, options
414
+
406
415
  # call action
407
416
  # TODO: make sure the single method parameter isn't a block
408
417
  if trigger
@@ -411,7 +420,7 @@ class Roda
411
420
  else
412
421
  comp_response = comp.trigger trigger, options
413
422
  end
414
- else
423
+ elsif action
415
424
  # We want to make sure it's not a method that already exists in ruba
416
425
  # otherwise that would give us a false positive.
417
426
  if comp.methods.include? action
@@ -421,12 +430,16 @@ class Roda
421
430
  end
422
431
  end
423
432
 
424
- comp_response
433
+ if trigger || action
434
+ comp_response
435
+ else
436
+ comp
437
+ end
425
438
  end
426
439
  end
427
440
 
428
- def load_component name
429
- component_opts[:class_name][name].split('::').inject(Object) {|o,c| o.const_get(c)}.new self
441
+ def load_component name, options = {}
442
+ component_opts[:class_name][name].split('::').inject(Object) {|o,c| o.const_get(c)}.new self. options
430
443
  end
431
444
 
432
445
  def render_fields data, options = {}
@@ -531,8 +544,16 @@ class Roda
531
544
  end
532
545
  end
533
546
 
547
+ def render *args, &block
548
+ display *args, &block
549
+ end
550
+
534
551
  private
535
552
 
553
+ def scope
554
+ @_scope
555
+ end
556
+
536
557
  def from_server?
537
558
  if request
538
559
  !request.env.include?('HTTP_X_RODA_COMPONENT_ON_SERVER')
@@ -1,5 +1,5 @@
1
1
  class Roda
2
2
  class Component
3
- VERSION = "0.1.33"
3
+ VERSION = "0.1.34"
4
4
  end
5
5
  end
@@ -63,13 +63,15 @@ class Roda
63
63
  request.env['loaded_component_js'] ||= []
64
64
  end
65
65
 
66
- def load_component name
67
- Object.const_get(
66
+ def load_component name, options = {}
67
+ c = Object.const_get(
68
68
  component_opts[:class_name][name.to_s]
69
- ).new self
69
+ )
70
+
71
+ c.new self, options
70
72
  end
71
73
 
72
- def load_component_js comp, action = :display, options = {}
74
+ def load_component_js comp, action = false, options = {}
73
75
  # grab a copy of the cache
74
76
  cache = comp.class.cache.dup
75
77
  # remove html and dom cache as we don't need that for the client
@@ -87,6 +89,8 @@ class Roda
87
89
  }.uniq.first.gsub("#{Dir.pwd}/#{component_opts[:path]}", '').gsub(/\.rb\Z/, '.js')
88
90
 
89
91
  js = <<-EOF
92
+ action = '#{action || 'false'}'
93
+
90
94
  unless $faye
91
95
  $faye = Roda::Component::Faye.new('/faye')
92
96
  end
@@ -100,10 +104,14 @@ class Roda
100
104
  $component_opts[:comp][:"#{comp_name}"] = true
101
105
  `$.getScript("/#{component_opts[:assets_route]}#{file_path}", function(){`
102
106
  Document.ready? do
103
- c = $component_opts[:comp][:"#{comp_name}"] = #{comp.class}.new
107
+ if action != 'false'
108
+ c = $component_opts[:comp][:"#{comp_name}"] = #{comp.class}.new
109
+ else
110
+ c = $component_opts[:comp][:"#{comp_name}"] = #{comp.class}.new(JSON.parse(Base64.decode64('#{options}')))
111
+ end
104
112
  c.instance_variable_set(:@_cache, JSON.parse(Base64.decode64('#{cache}')))
105
113
  c.events.trigger_jquery_events
106
- c.#{action}(JSON.parse(Base64.decode64('#{options}')))
114
+ c.#{action}(JSON.parse(Base64.decode64('#{options}'))) if action != 'false'
107
115
  end
108
116
  `});`
109
117
  end
@@ -113,13 +121,15 @@ class Roda
113
121
  end
114
122
 
115
123
  def component name, options = {}, &block
116
- comp = load_component name
117
-
118
- action = options.delete(:call) || :display
119
- trigger = options.delete(:trigger) || false
124
+ action = options.delete(:call)
125
+ trigger = options.delete(:trigger)
120
126
  js = options.delete(:js)
121
127
  args = options.delete(:args)
122
128
 
129
+ action = :display if js && !action
130
+
131
+ comp = load_component name, options
132
+
123
133
  # call action
124
134
  # TODO: make sure the single method parameter isn't a block
125
135
  if trigger
@@ -128,7 +138,7 @@ class Roda
128
138
  else
129
139
  comp_response = comp.trigger trigger, options
130
140
  end
131
- else
141
+ elsif action
132
142
  # We want to make sure it's not a method that already exists in ruba
133
143
  # otherwise that would give us a false positive.
134
144
  if comp.respond_to?(action) && !"#{comp.method(action)}"[/\(Kernel\)/]
@@ -146,17 +156,21 @@ class Roda
146
156
  end
147
157
  end
148
158
 
149
- load_component_js comp, action, options
159
+ if trigger || action
160
+ load_component_js comp, action, options
150
161
 
151
- if js && comp_response.is_a?(Roda::Component::DOM)
152
- comp_response = comp_response.to_xml
153
- end
162
+ if js && comp_response.is_a?(Roda::Component::DOM)
163
+ comp_response = comp_response.to_xml
164
+ end
154
165
 
155
- if comp_response.is_a?(String) && js
156
- comp_response << component_js
157
- end
166
+ if comp_response.is_a?(String) && js
167
+ comp_response << component_js
168
+ end
158
169
 
159
- comp_response
170
+ comp_response
171
+ else
172
+ comp
173
+ end
160
174
  end
161
175
  alias :comp :component
162
176
  alias :roda_component :component
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.33
4
+ version: 0.1.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-06 00:00:00.000000000 Z
11
+ date: 2015-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal