Class: Vue::Compiler

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

Constant Summary collapse

JS_ROOT =
File.join(File.dirname(__FILE__),'../..','js')
COMPILER =
File.join(JS_ROOT,'vue-compile-template-2.4.js')

Class Method Summary collapse

Class Method Details

._compilerObject



27
28
29
30
31
32
# File 'lib/vue/compiler.rb', line 27

def _compiler
  version = _options[:version] || _options['version'] || '2.5'
  script = File.join(JS_ROOT,"vue-compile-template-#{version}.js")
  raise "invalid compile script #{script}" unless File.exist?(script)
  script
end

._ctxObject



34
35
36
37
38
39
40
# File 'lib/vue/compiler.rb', line 34

def _ctx
  @__ctx ||= begin
    ctx = V8::Context.new
    ctx.load  _compiler
    ctx
  end
end

._optionsObject



23
24
25
# File 'lib/vue/compiler.rb', line 23

def _options
  @options || {}
end

._resetObject



15
16
17
# File 'lib/vue/compiler.rb', line 15

def _reset
  @__ctx = nil
end

.compile(template, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/vue/compiler.rb', line 42

def compile(template,options={})
  obj = _ctx[:VueTemplateCompiler][:compile].call(template.to_s)
   {
     :render=>obj[:render].to_s,
     :staticRenderFns=>obj[:staticRenderFns].to_a,
     :errors=>obj[:errors].to_s,
     :tips=>obj[:tips].to_s
   }
end

.parseComponent(file, options = {}) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/vue/compiler.rb', line 52

def parseComponent(file, options={})
  obj = _ctx[:VueTemplateCompiler][:parseComponent].call(file.to_s)
  {:script=>obj[:script] && obj[:script][:content],
   :template=>obj[:template] && obj[:template][:content],
   :styles=>obj[:styles] && obj[:styles].map{ |s| s[:content] }
  }
end

.set_options(opts = {}) ⇒ Object



19
20
21
# File 'lib/vue/compiler.rb', line 19

def set_options(opts={})
   @options = opts
end