class Vue

“@ … @” for js_variable “# … #” for js_function “: … :” for html_code

Attributes

error[RW]
prefix[RW]
suffix[RW]
value[RW]
value_property[RW]

Public Class Methods

new(hash) click to toggle source

传入hash,被转换成js object 后进行eval 用法 {“@name@”=> whatever,×},`{name:function,*}` 目前基于eval实现性能堪忧

# File lib/vue.rb, line 13
def initialize(hash)
    @value_property = hash
    @value = hash.to_s.gsub(/=>/,":").gsub(/\"@/,"").gsub(/@\"/,"")
    #debug
    puts self.value
    @prefix = "`new Vue("
    @suffix = ")`"
end

Public Instance Methods

add_components(components_name,components) click to toggle source

“components,{”@name@“=>{”@template@“=>”:<h1>…<h1>:“}}”

# File lib/vue.rb, line 44
def add_components(components_name,components)
  self.value = self.value.chomp("}")
  tmp = ","+components_name+":"+components.to_s.gsub(/\":/,"\"").gsub(/:\"/,"\"").gsub(/=>/,":").gsub(/\"@/,"").gsub(/@\"/,"") + "}"
  puts tmp
  self.value += tmp
  #debug
  puts self.value
end
add_methods(methods_block_name,js_method) click to toggle source

“name:function(){…}”

# File lib/vue.rb, line 23
def add_methods(methods_block_name,js_method)
  self.value = self.value.chomp("}")
  tmp = ","+methods_block_name+":"+js_method.to_s.gsub(/=>/,":").gsub(/\"@/,"").gsub(/@\"/,"").gsub(/\"#/,"").gsub(/#\"/,"") + "}"
  puts tmp
  self.value += tmp
  #debug
  puts self.value

end
apply() click to toggle source
# File lib/vue.rb, line 54
def apply()
  source = self.prefix + self.value.gsub(/\\n/,"") + self.suffix
  #debug
  puts source
  return eval(source)
  puts "Error How did you get here????"
end