vue-compiler 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/README.md +63 -11
- data/lib/vue/compiler.rb +14 -2
- data/lib/vue/sprockets.rb +15 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70c572dc52fb6abc136900505b5e0bfe0372e531
|
4
|
+
data.tar.gz: 190edf373a5722f083252f5ced0a6dec5230fa8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 717f8071e778fc97d4adc1332269bf75cdf33cc15e5cc42254f21ca94e85741571ab5cc59083e0a3f126ac8b695d9bfc9064550cda7e1f7a6c4a2739f76a9a5c
|
7
|
+
data.tar.gz: 1d4b00dc793d3bf428079af4c6dc57ea2205236bfde08bae435d5e536f4a2d6e3000810fdb998d7628cfdc3ca7fc247b1d923ca31d500af43ca4bf7a400d3cf4
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
## Vue Version
|
2
2
|
|
3
|
-
2.4.0
|
3
|
+
2.4.0
|
4
4
|
|
5
5
|
## INSTALLATION
|
6
6
|
|
@@ -9,30 +9,82 @@
|
|
9
9
|
|
10
10
|
## COMPILE A TEMPLATE
|
11
11
|
|
12
|
-
require 'vue/compiler'
|
12
|
+
require 'vue/compiler'
|
13
13
|
|
14
14
|
|
15
|
-
Vue::Compiler.compile "<div><span>{{ msg }}</span></div>"
|
15
|
+
Vue::Compiler.compile "<div><span>{{ msg }}</span></div>"
|
16
16
|
|
17
|
-
=> "with(this){return _c('div',[_c('span',[_v(_s(msg))])])}"
|
17
|
+
=> "with(this){return _c('div',[_c('span',[_v(_s(msg))])])}"
|
18
18
|
|
19
19
|
|
20
20
|
## PARSE A SFC
|
21
21
|
|
22
|
-
Vue::Compiler.parseComponent "<template><div><span>{{ msg }}</span></div></template>"
|
22
|
+
Vue::Compiler.parseComponent "<template><div><span>{{ msg }}</span></div></template>"
|
23
23
|
|
24
24
|
## CREATE RENDER FUNCTION
|
25
25
|
|
26
26
|
replace the template string with the render function in your Vue Object.
|
27
27
|
|
28
|
-
render:function(){
|
29
|
-
|
30
|
-
}
|
28
|
+
render:function(){
|
29
|
+
with(this){return _c('div',[_c('span',[_v(_s(msg))])])}
|
30
|
+
}
|
31
31
|
|
32
32
|
## SPROCKETS
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
this will replace any template strings within an object in your regular javascript assets with a render function.
|
35
|
+
|
36
|
+
NOTE The template must be contained with double quotes !!
|
37
|
+
|
38
|
+
this will NOT compile .vue extension single file components !!
|
39
|
+
|
40
|
+
### example
|
41
|
+
|
42
|
+
in assets/js/app/index.coffee
|
43
|
+
|
44
|
+
this.app = new Vue({
|
45
|
+
el: '#app'
|
46
|
+
|
47
|
+
template: """
|
48
|
+
<div>
|
49
|
+
<div class="header">
|
50
|
+
<h1 >{{msg}}</h1>
|
51
|
+
</div>
|
52
|
+
</div>
|
53
|
+
"""
|
54
|
+
|
55
|
+
data:
|
56
|
+
msg:"hello from vue"
|
57
|
+
})
|
58
|
+
|
59
|
+
|
60
|
+
or of you prefer in javascript assets/js/app/index.js
|
61
|
+
|
62
|
+
var app = new Vue({
|
63
|
+
el: '#app',
|
64
|
+
template: "<div>\n <div class=\"header\">\n <h1 >{{msg}}</h1>\n </div>\n</div>",
|
65
|
+
data: { msg: "hello from vue" }
|
66
|
+
});
|
67
|
+
|
68
|
+
|
69
|
+
in your config.ru ..
|
70
|
+
|
71
|
+
require 'sprockets'
|
72
|
+
require 'vue/sprockets'
|
73
|
+
|
74
|
+
VueSprocketsCompiler.set_root '/app' # the relative path under which any js files will be processed
|
75
|
+
|
76
|
+
.....
|
77
|
+
.....
|
78
|
+
.....
|
79
|
+
map '/assets' do
|
80
|
+
environment = Sprockets::Environment.new
|
81
|
+
environment.append_path 'assets/js'
|
82
|
+
environment.append_path 'assets/css'
|
83
|
+
....
|
84
|
+
|
85
|
+
run environment
|
86
|
+
end
|
87
|
+
....
|
88
|
+
....
|
37
89
|
|
38
90
|
|
data/lib/vue/compiler.rb
CHANGED
@@ -22,9 +22,19 @@ module Vue
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
#def compile(template,options={})
|
26
|
+
# obj = _ctx[:VueTemplateCompiler][:compile].call(template.to_s)
|
27
|
+
# obj[:render]
|
28
|
+
#end
|
29
|
+
|
25
30
|
def compile(template,options={})
|
26
31
|
obj = _ctx[:VueTemplateCompiler][:compile].call(template.to_s)
|
27
|
-
|
32
|
+
{
|
33
|
+
:render=>obj[:render].to_s,
|
34
|
+
:staticRenderFns=>obj[:staticRenderFns].to_a,
|
35
|
+
:errors=>obj[:errors].to_s,
|
36
|
+
:tips=>obj[:tips].to_s
|
37
|
+
}
|
28
38
|
end
|
29
39
|
|
30
40
|
# returns keys ["template", "script", "styles", "customBlocks"]
|
@@ -33,7 +43,9 @@ module Vue
|
|
33
43
|
|
34
44
|
def parseComponent(file, options={})
|
35
45
|
obj = _ctx[:VueTemplateCompiler][:parseComponent].call(file.to_s)
|
36
|
-
{:script=>obj[:script]
|
46
|
+
{:script=>obj[:script].to_s,
|
47
|
+
:template=>obj[:template].to_s,
|
48
|
+
:styles=>obj[:styles].to_s}
|
37
49
|
end
|
38
50
|
|
39
51
|
|
data/lib/vue/sprockets.rb
CHANGED
@@ -9,6 +9,10 @@ class VueSprocketsCompiler
|
|
9
9
|
path = '/' + path unless path[0,1] == '/'
|
10
10
|
@root = path
|
11
11
|
end
|
12
|
+
|
13
|
+
def self.toFunction(code)
|
14
|
+
return 'function () {' + code + '}'
|
15
|
+
end
|
12
16
|
|
13
17
|
def self.call(input)
|
14
18
|
source = input[:data]
|
@@ -18,12 +22,20 @@ class VueSprocketsCompiler
|
|
18
22
|
path = filename[load_path.length..-1]
|
19
23
|
|
20
24
|
if !@root || (path[0..@root.length-1] == @root)
|
21
|
-
js = source.gsub( /template\s*:\s*"(.*?[^\\])"/m ) do |match|
|
22
|
-
|
25
|
+
js = source.gsub( /( *)template\s*:\s*"(.*?[^\\])"/m ) do |match|
|
26
|
+
spaces = "#{$1}"
|
27
|
+
src = $2.gsub("\\n","\n")
|
23
28
|
src = src.gsub("\\\"","\"")
|
24
29
|
src = src.gsub("\\\'","\'")
|
25
30
|
src = src.gsub("\\t","\t")
|
26
|
-
|
31
|
+
|
32
|
+
result = Vue::Compiler.compile(src)
|
33
|
+
out = ""
|
34
|
+
out += spaces + "render :" + toFunction(result[:render]) + ",\n"
|
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
|
27
39
|
end
|
28
40
|
{:data=>js}
|
29
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.
|
4
|
+
version: 0.1.3
|
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-
|
11
|
+
date: 2017-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: therubyracer
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: vue-template-compiler functionality in a gem - compile and parse your
|
28
|
-
vue.js templates
|
28
|
+
vue.js templates
|
29
29
|
email:
|
30
30
|
- gems@realitybites.eu
|
31
31
|
executables: []
|
@@ -39,7 +39,7 @@ files:
|
|
39
39
|
- js/vue-compile-template.js
|
40
40
|
- lib/vue/compiler.rb
|
41
41
|
- lib/vue/sprockets.rb
|
42
|
-
homepage:
|
42
|
+
homepage: https://github.com/realbite/vue-compiler
|
43
43
|
licenses:
|
44
44
|
- MIT
|
45
45
|
metadata: {}
|