vue-compiler 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ require 'v8'
2
+
3
+
4
+
5
+ module Vue
6
+
7
+ class Compiler
8
+
9
+ COMPILER = File.join(File.dirname(__FILE__),'../..','js/vue-compile-template.js')
10
+
11
+ class << self
12
+
13
+ def _reset
14
+ @__ctx = nil
15
+ end
16
+
17
+ def _ctx
18
+ @__ctx ||= begin
19
+ cxt = V8::Context.new
20
+ cxt.load COMPILER
21
+ cxt
22
+ end
23
+ end
24
+
25
+ def compile(template,options={})
26
+ obj = _ctx[:VueTemplateCompiler][:compile].call(template.to_s)
27
+ obj[:render]
28
+ end
29
+
30
+ # returns keys ["template", "script", "styles", "customBlocks"]
31
+ # :template=> {"type", "content", "start", "attrs", "end"}
32
+ # :script =>
33
+
34
+ def parseComponent(file, options={})
35
+ obj = _ctx[:VueTemplateCompiler][:parseComponent].call(file.to_s)
36
+ {:script=>obj[:script]}
37
+ end
38
+
39
+
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,36 @@
1
+ # transform vue objects by compiling the templates into render functions.
2
+
3
+ require 'vue/compiler'
4
+
5
+ class VueSprocketsCompiler
6
+
7
+ # compile templates under this path.
8
+ def self.set_root(path=nil)
9
+ path = '/' + path unless path[0,1] == '/'
10
+ @root = path
11
+ end
12
+
13
+ def self.call(input)
14
+ source = input[:data]
15
+ load_path = input[:load_path]
16
+ filename = input[:filename]
17
+
18
+ path = filename[load_path.length..-1]
19
+
20
+ if !@root || (path[0..@root.length-1] == @root)
21
+ js = source.gsub( /template\s*:\s*"(.*?[^\\])"/m ) do |match|
22
+ src = $1.gsub("\\n","\n")
23
+ src = src.gsub("\\\"","\"")
24
+ src = src.gsub("\\\'","\'")
25
+ src = src.gsub("\\t","\t")
26
+ "render : function(){" + Vue::Compiler.compile(src) + "}"
27
+ end
28
+ {:data=>js}
29
+ else
30
+ nil
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ Sprockets.register_postprocessor('application/javascript', VueSprocketsCompiler)
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vue-compiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Clive Andrews
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: therubyracer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: vue-template-compiler functionality in a gem - compile and parse your
28
+ vue.js templates and components
29
+ email:
30
+ - gems@realitybites.eu
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files:
34
+ - README.md
35
+ - LICENSE
36
+ files:
37
+ - LICENSE
38
+ - README.md
39
+ - js/vue-compile-template.js
40
+ - lib/vue/compiler.rb
41
+ - lib/vue/sprockets.rb
42
+ homepage: ''
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.6.11
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: vue-template-compiler functionality in a gem
66
+ test_files: []