roda-component 0.1.16 → 0.1.17

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: e05764f5a7a8fe5b77136f9891195edaca1359e2
4
- data.tar.gz: 1d11a49a6c6c760fa831f26467c98f5fc36f8837
3
+ metadata.gz: c6ee949a432159269d22a12ba98d86e352f46d5a
4
+ data.tar.gz: 5a07e83ab446cd2e71350b06240b3ef04623e17c
5
5
  SHA512:
6
- metadata.gz: f214e8ef5271ff4dff4cc64f90da2218169416ed066b75e1b757a62ad64413d375e8f46ce26330f8079560095ad1a5e25ff58f6c22a56e3841a3a0ddcb3e71ad
7
- data.tar.gz: 5091aee707250510f74705c00f842c79bde57a9fcaaf96a6106616302db4bdba578e7ab9f39d58fed1412ed158f4de1c6939545d4115d8a17ccfcf978bae312e
6
+ metadata.gz: fd87d95cb234b6161cb6e3a881bbcf89263c8e66f1e9b2aac1dc9fae8a66708675db7833abf4c82412fa0ee06087f45fe1d7ddf16fb7f55a38b978adedddeacb
7
+ data.tar.gz: 6c784e64507255430a245ad25c1e289fdfca84f7d8b36eefbec193e0bbb446504e62fdf9af4aee15256e9fa19979a7e2b2ac23779bce22208044503f3d28429f
@@ -1,5 +1,5 @@
1
1
  class Roda
2
2
  class Component
3
- VERSION = "0.1.16"
3
+ VERSION = "0.1.17"
4
4
  end
5
5
  end
@@ -91,7 +91,20 @@ class Roda
91
91
 
92
92
  def on_server &block
93
93
  if server?
94
+ m = Module.new(&block)
95
+
94
96
  yield
97
+
98
+ m.public_instance_methods(false).each do |meth|
99
+ alias_method :"original_#{meth}", :"#{meth}"
100
+ define_method "#{meth}" do |*args, &blk|
101
+ if blk
102
+ blk.call send("original_#{meth}", *args)
103
+ else
104
+ send("original_#{meth}", *args)
105
+ end
106
+ end
107
+ end
95
108
  else
96
109
  m = Module.new(&block)
97
110
 
@@ -105,7 +118,7 @@ class Roda
105
118
  'X-CSRF-TOKEN' => Element.find('meta[name=_csrf]').attr('content'),
106
119
  'X-RODA-COMPONENT-ON-SERVER' => true
107
120
  },
108
- payload: args.first) do |response|
121
+ payload: args) do |response|
109
122
 
110
123
  # We set the new csrf token
111
124
  xhr = Native(response.xhr)
@@ -69,7 +69,7 @@ class Roda
69
69
  ).new self
70
70
  end
71
71
 
72
- def load_component_js comp, action = :display
72
+ def load_component_js comp, action = :display, options = {}
73
73
  # grab a copy of the cache
74
74
  cache = comp.class.cache.dup
75
75
  # remove html and dom cache as we don't need that for the client
@@ -111,17 +111,26 @@ class Roda
111
111
  action = options.delete(:call) || :display
112
112
  trigger = options.delete(:trigger) || false
113
113
  js = options.delete(:js)
114
+ args = options.delete(:args)
114
115
 
115
116
  # call action
116
117
  # TODO: make sure the single method parameter isn't a block
117
118
  if trigger
118
- comp_response = comp.trigger trigger, options
119
+ if args
120
+ comp_response = comp.trigger trigger, *args
121
+ else
122
+ comp_response = comp.trigger trigger, options
123
+ end
119
124
  else
120
125
  # We want to make sure it's not a method that already exists in ruba
121
126
  # otherwise that would give us a false positive.
122
127
  if comp.respond_to?(action) && !"#{comp.method(action)}"[/\(Kernel\)/]
123
128
  if comp.method(action).parameters.length > 0
124
- comp_response = comp.send(action, options, &block)
129
+ if args
130
+ comp_response = comp.send(action, *args, &block)
131
+ else
132
+ comp_response = comp.send(action, options, &block)
133
+ end
125
134
  else
126
135
  comp_response = comp.send(action, &block)
127
136
  end
@@ -130,7 +139,7 @@ class Roda
130
139
  end
131
140
  end
132
141
 
133
- load_component_js comp, action
142
+ load_component_js comp, action, options
134
143
 
135
144
  if js && comp_response.is_a?(Roda::Component::DOM)
136
145
  comp_response = comp_response.to_xml
@@ -221,6 +230,10 @@ class Roda
221
230
  data = {}
222
231
  end
223
232
 
233
+ if data.is_a? Array
234
+ data = {args: data}
235
+ end
236
+
224
237
  case type
225
238
  when 'call'
226
239
  data[:call] = action
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj