Class: Vue::Compiler
- Inherits:
-
Object
- Object
- Vue::Compiler
- 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
- ._compiler ⇒ Object
- ._ctx ⇒ Object
- ._options ⇒ Object
- ._reset ⇒ Object
- .compile(template, options = {}) ⇒ Object
- .parseComponent(file, options = {}) ⇒ Object
- .set_options(opts = {}) ⇒ Object
Class Method Details
._compiler ⇒ Object
27 28 29 30 31 32 |
# File 'lib/vue/compiler.rb', line 27 def _compiler version = [:version] || ['version'] || '2.5' script = File.join(JS_ROOT,"vue-compile-template-#{version}.js") raise "invalid compile script #{script}" unless File.exist?(script) script end |
._ctx ⇒ Object
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 |
._options ⇒ Object
23 24 25 |
# File 'lib/vue/compiler.rb', line 23 def @options || {} end |
._reset ⇒ Object
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,={}) 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, ={}) 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 (opts={}) @options = opts end |