Class: Vue

Inherits:
Object
  • Object
show all
Defined in:
lib/vue.rb

Overview

“@ … @” for js_variable

"# ... #" for js_function
": ... :" for html_code

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Vue

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



13
14
15
16
17
18
19
20
# 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

Instance Attribute Details

#errorObject

Returns the value of attribute error.



8
9
10
# File 'lib/vue.rb', line 8

def error
  @error
end

#prefixObject

Returns the value of attribute prefix.



8
9
10
# File 'lib/vue.rb', line 8

def prefix
  @prefix
end

#suffixObject

Returns the value of attribute suffix.



8
9
10
# File 'lib/vue.rb', line 8

def suffix
  @suffix
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/vue.rb', line 8

def value
  @value
end

#value_propertyObject

Returns the value of attribute value_property.



8
9
10
# File 'lib/vue.rb', line 8

def value_property
  @value_property
end

Instance Method Details

#add_components(components_name, components) ⇒ Object

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



44
45
46
47
48
49
50
51
# 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) ⇒ Object

“name:function()…”



23
24
25
26
27
28
29
30
31
# 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

#applyObject



54
55
56
57
58
59
60
# 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