dynamic but not yet reactive text in handlebars

This commit is contained in:
Torsten 2023-02-07 17:07:18 +02:00
parent ef4a22709a
commit 6aa874fe64
3 changed files with 23 additions and 8 deletions

View File

@ -61,5 +61,6 @@ module VueR
end end
effect.call effect.call
end end
end end
end end

View File

@ -1,3 +1,5 @@
require 'opal-parser'
module VueR module VueR
class Mounter class Mounter
@ -11,8 +13,22 @@ module VueR
end end
def mount_Text elem def mount_Text elem
puts "Text: #{elem.text}" text = elem.text
puts "DYN text" if elem.text.include? "{{" puts text
scan = text.scan(/{{\s?([^}]*)\s?}}/)
return unless scan.length > 0
puts scan
raise "only one curly per text implemented not:#{scan.length}" if scan.length > 1
match = text.match(/{{\s?([^}]*)\s?}}/)
str_before = text[0 ... match.begin(0)]
str_after = text[ match.end(0) .. -1]
ruby = match[0][2 ... -2]
proc = Proc.new do
elem.text = str_before + @application.eval(ruby).to_s + str_after
end
proc.call
end end
def mount_Element(elem) def mount_Element(elem)

View File

@ -1,9 +1,10 @@
#app.flex.justify-center #app
.flex.flex-col .flex.justify-center
= @image.attributes = @image.attributes
.flex.justify-center
%a.underline{ e_click: "hi"} %a.underline{ e_click: "hi"}
{{Back}} {{ bg }}
%div{ r_class: 21 } %div{ r_class: 21 }
:opal :opal
class Clicker < VueR::Application class Clicker < VueR::Application
@ -11,7 +12,4 @@
end end
kanta = Clicker.new(bg: 'bg-cyan-200') kanta = Clicker.new(bg: 'bg-cyan-200')
puts kanta.bg
kanta.bg = "bg-cyan"
puts kanta.bg
kanta.mount("#app") kanta.mount("#app")