rewrite eval as send, removes parser
This commit is contained in:
parent
951ced7734
commit
e6e6265e26
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@
|
||||
/dummy/log/*.log
|
||||
/dummy/storage/
|
||||
/dummy/tmp/
|
||||
/dummy/public/assets/
|
||||
|
@ -6,7 +6,6 @@
|
||||
%a.underline{ e_click: "bg_change" , r_class: 'back'}
|
||||
{{ back }}
|
||||
:opal
|
||||
puts "here1"
|
||||
class Clicker < VueR::Application
|
||||
def bg_change
|
||||
self.state = !self.state
|
||||
@ -16,8 +15,5 @@
|
||||
end
|
||||
end
|
||||
|
||||
puts "here2"
|
||||
click = Clicker.new(bg: 'bg-cyan-200' , state: true)
|
||||
click.mount("#app")
|
||||
|
||||
puts "here3"
|
||||
|
@ -26,7 +26,7 @@ Rails.application.configure do
|
||||
|
||||
# Compress CSS using a preprocessor.
|
||||
# config.assets.css_compressor = :sass
|
||||
|
||||
# config.assets.js_compressor = :terser
|
||||
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
||||
config.assets.compile = false
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user