rewrite eval as send, removes parser
This commit is contained in:
@ -1,8 +1,6 @@
|
||||
require "opal"
|
||||
require "native"
|
||||
require 'opal'
|
||||
require 'native'
|
||||
require 'promise'
|
||||
require 'browser/setup/mini'
|
||||
require 'opal-parser'
|
||||
|
||||
require "vue_r/application"
|
||||
require "vue_r/mounter"
|
||||
|
@ -63,5 +63,29 @@ module VueR
|
||||
effect.call
|
||||
end
|
||||
|
||||
def send_self(expression)
|
||||
method , args = decompose(expression)
|
||||
puts "Sending #{method}(#{args.join(',')})"
|
||||
self.send method , *args
|
||||
end
|
||||
|
||||
def decompose(expression)
|
||||
matches = expression.match(/\b[^()]+\((.*)\)$/)
|
||||
return expression if matches.blank?
|
||||
method = expression.split("(").first
|
||||
return [method , [] ] if m[1].empty?
|
||||
args = m[1].split(",").collect{| arg | transform_arg(arg) }
|
||||
return [method , args]
|
||||
end
|
||||
|
||||
def transform_arg(arg)
|
||||
arg = arg.strip
|
||||
puts "Arg:#{arg}:"
|
||||
return true if arg == "true"
|
||||
return false if arg == "false"
|
||||
return nil if arg == "nil"
|
||||
return arg.to_i if arg == arg.to_to_s
|
||||
arg
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -21,7 +21,7 @@ module VueR
|
||||
ruby = match[0][2 ... -2]
|
||||
puts "Text: #{ruby}"
|
||||
proc = Proc.new do
|
||||
elem.text = str_before + @application.eval(ruby).to_s + str_after
|
||||
elem.text = str_before + @application.send_self(ruby).to_s + str_after
|
||||
end
|
||||
@application.watch_effect(proc)
|
||||
end
|
||||
@ -43,7 +43,7 @@ module VueR
|
||||
old_value = element[native_name]
|
||||
puts "Attribute: #{ruby}"
|
||||
proc = Proc.new do
|
||||
element[native_name] = old_value + " " + @application.eval(ruby).to_s
|
||||
element[native_name] = old_value + " " + @application.send_self(ruby).to_s
|
||||
end
|
||||
@application.watch_effect(proc)
|
||||
end
|
||||
@ -54,7 +54,7 @@ module VueR
|
||||
ruby = element[name]
|
||||
puts "Event: #{native_name}:#{ruby}"
|
||||
element.on!(native_name) do
|
||||
got = @application.eval(ruby)
|
||||
got = @application.send_self(ruby)
|
||||
puts "Clicked #{got}"
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user