roda-component 0.1.16 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/roda/component/version.rb +1 -1
- data/lib/roda/component.rb +14 -1
- data/lib/roda/plugins/component.rb +17 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6ee949a432159269d22a12ba98d86e352f46d5a
|
4
|
+
data.tar.gz: 5a07e83ab446cd2e71350b06240b3ef04623e17c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd87d95cb234b6161cb6e3a881bbcf89263c8e66f1e9b2aac1dc9fae8a66708675db7833abf4c82412fa0ee06087f45fe1d7ddf16fb7f55a38b978adedddeacb
|
7
|
+
data.tar.gz: 6c784e64507255430a245ad25c1e289fdfca84f7d8b36eefbec193e0bbb446504e62fdf9af4aee15256e9fa19979a7e2b2ac23779bce22208044503f3d28429f
|
data/lib/roda/component.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
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
|