vue-compiler 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/vue/compiler.rb CHANGED
@@ -3,30 +3,42 @@ require 'v8'
3
3
 
4
4
 
5
5
  module Vue
6
-
6
+
7
7
  class Compiler
8
-
9
- COMPILER = File.join(File.dirname(__FILE__),'../..','js/vue-compile-template.js')
10
-
8
+
9
+ JS_ROOT = File.join(File.dirname(__FILE__),'../..','js')
10
+
11
+ COMPILER = File.join(JS_ROOT,'vue-compile-template-2.4.js')
12
+
11
13
  class << self
12
-
14
+
13
15
  def _reset
14
16
  @__ctx = nil
15
17
  end
16
-
18
+
19
+ def set_options(opts={})
20
+ @options = opts
21
+ end
22
+
23
+ def _options
24
+ @options || {}
25
+ end
26
+
27
+ def _compiler
28
+ version = _options[:version] || _options['version'] || '2.5'
29
+ script = File.join(JS_ROOT,"vue-compile-template-#{version}.js")
30
+ raise "invalid compile script #{script}" unless File.exist?(script)
31
+ script
32
+ end
33
+
17
34
  def _ctx
18
35
  @__ctx ||= begin
19
- cxt = V8::Context.new
20
- cxt.load COMPILER
21
- cxt
36
+ ctx = V8::Context.new
37
+ ctx.load _compiler
38
+ ctx
22
39
  end
23
40
  end
24
-
25
- #def compile(template,options={})
26
- # obj = _ctx[:VueTemplateCompiler][:compile].call(template.to_s)
27
- # obj[:render]
28
- #end
29
-
41
+
30
42
  def compile(template,options={})
31
43
  obj = _ctx[:VueTemplateCompiler][:compile].call(template.to_s)
32
44
  {
@@ -37,20 +49,17 @@ module Vue
37
49
  }
38
50
  end
39
51
 
40
- # returns keys ["template", "script", "styles", "customBlocks"]
41
- # :template=> {"type", "content", "start", "attrs", "end"}
42
- # :script =>
43
-
44
52
  def parseComponent(file, options={})
45
53
  obj = _ctx[:VueTemplateCompiler][:parseComponent].call(file.to_s)
46
- {:script=>obj[:script].to_s,
47
- :template=>obj[:template].to_s,
48
- :styles=>obj[:styles].to_s}
54
+ {:script=>obj[:script] && obj[:script][:content],
55
+ :template=>obj[:template] && obj[:template][:content],
56
+ :styles=>obj[:styles] && obj[:styles].map{ |s| s[:content] }
57
+ }
49
58
  end
50
-
51
-
59
+
60
+
52
61
  end
53
-
62
+
54
63
  end
55
-
64
+
56
65
  end
data/lib/vue/sprockets.rb CHANGED
@@ -3,13 +3,13 @@
3
3
  require 'vue/compiler'
4
4
 
5
5
  class VueSprocketsCompiler
6
-
6
+
7
7
  # compile templates under this path.
8
8
  def self.set_root(path=nil)
9
9
  path = '/' + path unless path[0,1] == '/'
10
10
  @root = path
11
11
  end
12
-
12
+
13
13
  def self.toFunction(code)
14
14
  return 'function () {' + code + '}'
15
15
  end
@@ -22,20 +22,20 @@ class VueSprocketsCompiler
22
22
  path = filename[load_path.length..-1]
23
23
 
24
24
  if !@root || (path[0..@root.length-1] == @root)
25
- js = source.gsub( /( *)template\s*:\s*"(.*?[^\\])"/m ) do |match|
25
+ js = source.gsub( /(?<spaces>\s+)template\s*:\s*(?<quote>["`'])(?<code>.*?[^\\])\k<quote>/m ) do |match|
26
26
  spaces = "#{$1}"
27
- src = $2.gsub("\\n","\n")
27
+ src = $3.gsub("\\n","\n")
28
28
  src = src.gsub("\\\"","\"")
29
29
  src = src.gsub("\\\'","\'")
30
30
  src = src.gsub("\\t","\t")
31
-
31
+
32
32
  result = Vue::Compiler.compile(src)
33
- out = ""
34
- out += spaces + "render :" + toFunction(result[:render]) + ",\n"
33
+
34
+ out = spaces + "render :" + toFunction(result[:render]) + ",\n"
35
35
  out += spaces + "staticRenderFns :[" + (result[:staticRenderFns] || []).map{|f| toFunction(f)}.join(',') + "]"
36
- puts "ERROR: vue/sprockets #{filename} ==>\n#{result[:errors]}" if result[:errors].to_s != ""
37
- puts puts "TIP: vue/sprockets #{filename} ==>\n#{result[:tips]}" if result[:tips].to_s != ""
38
- out
36
+ puts "ERROR: vue/sprockets #{filename} ==>\n#{result[:errors]}" if result[:errors].to_s != ""
37
+ puts "TIP: vue/sprockets #{filename} ==>\n#{result[:tips]}" if result[:tips].to_s != ""
38
+ out
39
39
  end
40
40
  {:data=>js}
41
41
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vue-compiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clive Andrews
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-01 00:00:00.000000000 Z
11
+ date: 2018-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: therubyracer
@@ -36,7 +36,8 @@ extra_rdoc_files:
36
36
  files:
37
37
  - LICENSE
38
38
  - README.md
39
- - js/vue-compile-template.js
39
+ - js/vue-compile-template-2.4.js
40
+ - js/vue-compile-template-2.5.js
40
41
  - lib/vue/compiler.rb
41
42
  - lib/vue/sprockets.rb
42
43
  homepage: https://github.com/realbite/vue-compiler