207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
# File 'lib/ruby-macrodroid/actions.rb', line 207
def initialize(obj={}, macro=nil)
$debug = true
puts ('obj: ' + obj.inspect).debug if $debug
h = if obj.is_a? Hash then
obj.merge({macro: macro})
elsif obj.is_a? Array
puts ('obj: ' + obj.inspect).debug if $debug
e, macro, h3 = obj
a = e.xpath('item/*')
h2 = if a.any? then
a.map do |node|
if node.name == 'description' then
if node.text.to_s =~ /: / then
node.text.to_s.split(/: +/,2).map(&:strip)
else
[:url, node.text.to_s]
end
else
[node.name.to_sym, node.text.to_s.strip]
end
end.to_h
else
txt = e.text('item/description')
{url: (txt || e.text)}
end
h2.merge(macro: macro).merge(h3)
end
puts ('h:' + h.inspect).debug if $debug
options = {
url_to_open: '',
http_get: true,
disable_url_encode: false,
block_next_action: false
}
return super(options.merge h) if h[:url_to_open]
if h[:macro].remote_url.nil? and (h[:url].nil? or h[:url].empty?) then
raise OpenWebPageActionError, 'remote_url not found'
end
url = if h[:url] and h[:url].length > 1 then
h[:url]
elsif h2 and h[:macro].remote_url and h[:identifier]
"%s/%s" % [h[:macro].remote_url.sub(/\/$/,''), h[:identifier]]
elsif (h[:identifier].nil? or h[:identifier].empty?)
h[:url_to_open] = h[:macro].remote_url.sub(/\/$/,'') + '/' +
h[:macro].title.downcase.gsub(/ +/,'-')
end
puts 'url: ' + url.inspect if $debug
if h2 then
h2.delete :identifier
h2.delete :url
if h2.any? then
url += '?' + \
URI.escape(h2.map {|key,value| "%s=%s" % [key, value]}.join('&'))
end
end
h[:url_to_open] = url
super(options.merge h)
end
|