class Vue::Compiler

Constants

JS_ROOT

Public Class Methods

_compiler() click to toggle source
# File lib/vue/compiler.rb, line 24
def _compiler
  version = _options[:version] || _options['version'] || '2.5'
  script = _options[:script] || File.join(JS_ROOT,"vue-compile-template-#{version}.js")
  raise "invalid compile script #{script}" unless File.exist?(script)
  script
end
_ctx() click to toggle source
# File lib/vue/compiler.rb, line 31
def _ctx
  @__ctx ||= ExecJS.compile( File.read(_compiler) + custom)
end
_options() click to toggle source
# File lib/vue/compiler.rb, line 20
def _options
  @options ||= {}
end
_reset() click to toggle source
# File lib/vue/compiler.rb, line 11
def _reset
  @__ctx = nil
  @options = {}
end
compile(template,options={}) click to toggle source
# File lib/vue/compiler.rb, line 60
def compile(template,options={})
  obj = _ctx.call("VXCompile",template.to_s)
   {
     :render=>obj["render"].to_s,
     :staticRenderFns=>obj["staticRenderFns"].to_a,
     :errors=>obj["errors"].to_a,
     :tips=>obj["tips"].to_a
   }
end
custom() click to toggle source
# File lib/vue/compiler.rb, line 36
      def custom
         <<-JS

            VXCompile = function(text){
              resp = VueTemplateCompiler.compile(text);
              return {
                render: resp.render,
                staticRenderFns: resp.staticRenderFns,
                errors:resp.errors,
                tips:resp.tips
              }
            }

            VXParse = function(text){
              resp = VueTemplateCompiler.parseComponent(text);
              return {
                script: resp.script ,
                template: resp.template ,
                styles:resp.styles
              }
            }
         JS
      end
parseComponent(file, options={}) click to toggle source
# File lib/vue/compiler.rb, line 70
def parseComponent(file, options={})
  obj = _ctx.call("VXParse",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={}) click to toggle source
# File lib/vue/compiler.rb, line 16
def set_options(opts={})
   @options = opts
end