riot_js-rails 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/riot_js/rails/processors/sprockets_processor_v3.rb +4 -2
- data/lib/riot_js/rails/railtie.rb +2 -2
- data/lib/riot_js/rails/version.rb +1 -1
- data/vendor/assets/javascripts/compiler/brackets.js +252 -0
- data/vendor/assets/javascripts/compiler/compiler.js +968 -10
- data/vendor/assets/javascripts/compiler/parsers.js +195 -21
- data/vendor/assets/javascripts/riot.js +1632 -569
- metadata +3 -3
- data/vendor/assets/javascripts/compiler/compiler_core.js +0 -234
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riot_js-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Jaroszewski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -135,8 +135,8 @@ files:
|
|
135
135
|
- lib/riot_js/rails/railtie.rb
|
136
136
|
- lib/riot_js/rails/version.rb
|
137
137
|
- riot_js-rails.gemspec
|
138
|
+
- vendor/assets/javascripts/compiler/brackets.js
|
138
139
|
- vendor/assets/javascripts/compiler/compiler.js
|
139
|
-
- vendor/assets/javascripts/compiler/compiler_core.js
|
140
140
|
- vendor/assets/javascripts/compiler/node_runner.js
|
141
141
|
- vendor/assets/javascripts/compiler/parsers.js
|
142
142
|
- vendor/assets/javascripts/riot.js
|
@@ -1,234 +0,0 @@
|
|
1
|
-
var BOOL_ATTR = ('allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,default,'+
|
2
|
-
'defaultchecked,defaultmuted,defaultselected,defer,disabled,draggable,enabled,formnovalidate,hidden,'+
|
3
|
-
'indeterminate,inert,ismap,itemscope,loop,multiple,muted,nohref,noresize,noshade,novalidate,nowrap,open,'+
|
4
|
-
'pauseonexit,readonly,required,reversed,scoped,seamless,selected,sortable,spellcheck,translate,truespeed,'+
|
5
|
-
'typemustmatch,visible').split(','),
|
6
|
-
// these cannot be auto-closed
|
7
|
-
VOID_TAGS = 'area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr'.split(','),
|
8
|
-
/*
|
9
|
-
Following attributes give error when parsed on browser with { exrp_values }
|
10
|
-
|
11
|
-
'd' describes the SVG <path>, Chrome gives error if the value is not valid format
|
12
|
-
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
|
13
|
-
*/
|
14
|
-
PREFIX_ATTR = ['style', 'src', 'd'],
|
15
|
-
|
16
|
-
LINE_TAG = /^<([\w\-]+)>(.*)<\/\1>/gim,
|
17
|
-
QUOTE = /=({[^}]+})([\s\/\>]|$)/g,
|
18
|
-
SET_ATTR = /([\w\-]+)=(["'])([^\2]+?)\2/g,
|
19
|
-
EXPR = /{\s*([^}]+)\s*}/g,
|
20
|
-
// (tagname) (html) (javascript) endtag
|
21
|
-
CUSTOM_TAG = /^<([\w\-]+)\s?([^>]*)>([^\x00]*[\w\/}"']>$)?([^\x00]*?)^<\/\1>/gim,
|
22
|
-
SCRIPT = /<script(?:\s+type=['"]?([^>'"]+)['"]?)?>([^\x00]*?)<\/script>/gi,
|
23
|
-
STYLE = /<style(?:\s+([^>]+))?>([^\x00]*?)<\/style>/gi,
|
24
|
-
CSS_SELECTOR = /(^|\}|\{)\s*([^\{\}]+)\s*(?=\{)/g,
|
25
|
-
HTML_COMMENT = /<!--.*?-->/g,
|
26
|
-
CLOSED_TAG = /<([\w\-]+)([^>]*)\/\s*>/g,
|
27
|
-
BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g,
|
28
|
-
LINE_COMMENT = /^\s*\/\/.*$/gm,
|
29
|
-
INPUT_NUMBER = /(<input\s[^>]*?)type=['"]number['"]/gm
|
30
|
-
|
31
|
-
function mktag(name, html, css, attrs, js) {
|
32
|
-
return 'riot.tag(\'' +
|
33
|
-
name + '\', \'' +
|
34
|
-
html + '\'' +
|
35
|
-
(css ? ', \'' + css + '\'' : '') +
|
36
|
-
(attrs ? ', \'' + attrs.replace(/'/g, "\\'") + '\'' : '') +
|
37
|
-
', function(opts) {' + js + '\n});'
|
38
|
-
}
|
39
|
-
|
40
|
-
function compileHTML(html, opts, type) {
|
41
|
-
|
42
|
-
if (!html) return ''
|
43
|
-
|
44
|
-
var brackets = riot.util.brackets,
|
45
|
-
b0 = brackets(0),
|
46
|
-
b1 = brackets(1)
|
47
|
-
|
48
|
-
// foo={ bar } --> foo="{ bar }"
|
49
|
-
html = html.replace(brackets(QUOTE), '="$1"$2')
|
50
|
-
|
51
|
-
// whitespace
|
52
|
-
html = opts.whitespace ? html.replace(/\r\n?|\n/g, '\\n') : html.replace(/\s+/g, ' ')
|
53
|
-
|
54
|
-
// strip comments
|
55
|
-
html = html.trim().replace(HTML_COMMENT, '')
|
56
|
-
|
57
|
-
// input type=numbr
|
58
|
-
html = html.replace(INPUT_NUMBER, '$1riot-type='+ b0 +'"number"'+ b1) // fake expression
|
59
|
-
|
60
|
-
// alter special attribute names
|
61
|
-
html = html.replace(SET_ATTR, function(full, name, _, expr) {
|
62
|
-
if (expr.indexOf(b0) >= 0) {
|
63
|
-
name = name.toLowerCase()
|
64
|
-
|
65
|
-
if (PREFIX_ATTR.indexOf(name) >= 0) name = 'riot-' + name
|
66
|
-
|
67
|
-
// IE8 looses boolean attr values: `checked={ expr }` --> `__checked={ expr }`
|
68
|
-
else if (BOOL_ATTR.indexOf(name) >= 0) name = '__' + name
|
69
|
-
}
|
70
|
-
|
71
|
-
return name + '="' + expr + '"'
|
72
|
-
})
|
73
|
-
|
74
|
-
// run expressions trough parser
|
75
|
-
if (opts.expr) {
|
76
|
-
html = html.replace(brackets(EXPR), function(_, expr) {
|
77
|
-
var ret = compileJS(expr, opts, type).trim().replace(/[\r\n]+/g, '').trim()
|
78
|
-
if (ret.slice(-1) == ';') ret = ret.slice(0, -1)
|
79
|
-
return b0 + ret + b1
|
80
|
-
})
|
81
|
-
}
|
82
|
-
|
83
|
-
// <foo/> -> <foo></foo>
|
84
|
-
html = html.replace(CLOSED_TAG, function(_, name, attr) {
|
85
|
-
var tag = '<' + name + (attr ? ' ' + attr.trim() : '') + '>'
|
86
|
-
|
87
|
-
// Do not self-close HTML5 void tags
|
88
|
-
if (VOID_TAGS.indexOf(name.toLowerCase()) == -1) tag += '</' + name + '>'
|
89
|
-
return tag
|
90
|
-
})
|
91
|
-
|
92
|
-
// escape single quotes
|
93
|
-
html = html.replace(/'/g, "\\'")
|
94
|
-
|
95
|
-
// \{ jotain \} --> \\{ jotain \\}
|
96
|
-
html = html.replace(brackets(/\\{|\\}/g), '\\$&')
|
97
|
-
|
98
|
-
// compact: no whitespace between tags
|
99
|
-
if (opts.compact) html = html.replace(/> </g, '><')
|
100
|
-
|
101
|
-
return html
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
|
-
function riotjs(js) {
|
107
|
-
|
108
|
-
// strip comments
|
109
|
-
js = js.replace(LINE_COMMENT, '').replace(BLOCK_COMMENT, '')
|
110
|
-
|
111
|
-
// ES6 method signatures
|
112
|
-
var lines = js.split('\n'),
|
113
|
-
es6Ident = ''
|
114
|
-
|
115
|
-
lines.forEach(function(line, i) {
|
116
|
-
var l = line.trim()
|
117
|
-
|
118
|
-
// method start
|
119
|
-
if (l[0] != '}' && ~l.indexOf('(')) {
|
120
|
-
var end = l.match(/[{}]$/),
|
121
|
-
m = end && line.match(/^(\s+)([$\w]+)\s*\(([$\w,\s]*)\)\s*\{/)
|
122
|
-
|
123
|
-
if (m && !/^(if|while|switch|for|catch|function)$/.test(m[2])) {
|
124
|
-
lines[i] = m[1] + 'this.' + m[2] + ' = function(' + m[3] + ') {'
|
125
|
-
|
126
|
-
// foo() { }
|
127
|
-
if (end[0] == '}') {
|
128
|
-
lines[i] += ' ' + l.slice(m[0].length - 1, -1) + '}.bind(this)'
|
129
|
-
|
130
|
-
} else {
|
131
|
-
es6Ident = m[1]
|
132
|
-
}
|
133
|
-
}
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
// method end
|
138
|
-
if (line.slice(0, es6Ident.length + 1) == es6Ident + '}') {
|
139
|
-
lines[i] = es6Ident + '}.bind(this);'
|
140
|
-
es6Ident = ''
|
141
|
-
}
|
142
|
-
|
143
|
-
})
|
144
|
-
|
145
|
-
return lines.join('\n')
|
146
|
-
|
147
|
-
}
|
148
|
-
|
149
|
-
function scopedCSS (tag, style, type) {
|
150
|
-
// 1. Remove CSS comments
|
151
|
-
// 2. Find selectors and separate them by conmma
|
152
|
-
// 3. keep special selectors as is
|
153
|
-
// 4. prepend tag and [riot-tag]
|
154
|
-
return style.replace(BLOCK_COMMENT, '').replace(CSS_SELECTOR, function (m, p1, p2) {
|
155
|
-
return p1 + ' ' + p2.split(/\s*,\s*/g).map(function(sel) {
|
156
|
-
var s = sel.trim()
|
157
|
-
var t = (/:scope/.test(s) ? '' : ' ') + s.replace(/:scope/, '')
|
158
|
-
return s[0] == '@' || s == 'from' || s == 'to' || /%$/.test(s) ? s :
|
159
|
-
tag + t + ', [riot-tag="' + tag + '"]' + t
|
160
|
-
}).join(',')
|
161
|
-
}).trim()
|
162
|
-
}
|
163
|
-
|
164
|
-
function compileJS(js, opts, type) {
|
165
|
-
if (!js) return ''
|
166
|
-
var parser = opts.parser || (type ? riot.parsers.js[type] : riotjs)
|
167
|
-
if (!parser) throw new Error('Parser not found "' + type + '"')
|
168
|
-
return parser(js.replace(/\r\n?/g, '\n'), opts)
|
169
|
-
}
|
170
|
-
|
171
|
-
function compileTemplate(lang, html) {
|
172
|
-
var parser = riot.parsers.html[lang]
|
173
|
-
if (!parser) throw new Error('Template parser not found "' + lang + '"')
|
174
|
-
return parser(html.replace(/\r\n?/g, '\n'))
|
175
|
-
}
|
176
|
-
|
177
|
-
function compileCSS(style, tag, type, scoped) {
|
178
|
-
if (type === 'scoped-css') scoped = 1
|
179
|
-
else if (riot.parsers.css[type]) style = riot.parsers.css[type](tag, style)
|
180
|
-
else if (type !== 'css') throw new Error('CSS parser not found: "' + type + '"')
|
181
|
-
if (scoped) style = scopedCSS(tag, style)
|
182
|
-
return style.replace(/\s+/g, ' ').replace(/\\/g, '\\\\').replace(/'/g, "\\'").trim()
|
183
|
-
}
|
184
|
-
|
185
|
-
function compile(src, opts) {
|
186
|
-
|
187
|
-
if (!opts) opts = {}
|
188
|
-
else {
|
189
|
-
|
190
|
-
if (opts.brackets) riot.settings.brackets = opts.brackets
|
191
|
-
|
192
|
-
if (opts.template) src = compileTemplate(opts.template, src)
|
193
|
-
}
|
194
|
-
|
195
|
-
src = src.replace(LINE_TAG, function(_, tagName, html) {
|
196
|
-
return mktag(tagName, compileHTML(html, opts), '', '', '')
|
197
|
-
})
|
198
|
-
|
199
|
-
return src.replace(CUSTOM_TAG, function(_, tagName, attrs, html, js) {
|
200
|
-
var style = '',
|
201
|
-
type = opts.type
|
202
|
-
|
203
|
-
if (html) {
|
204
|
-
|
205
|
-
// js wrapped inside <script> tag
|
206
|
-
if (!js.trim()) {
|
207
|
-
html = html.replace(SCRIPT, function(_, _type, script) {
|
208
|
-
if (_type) type = _type.replace('text/', '')
|
209
|
-
js = script
|
210
|
-
return ''
|
211
|
-
})
|
212
|
-
}
|
213
|
-
|
214
|
-
// styles in <style> tag
|
215
|
-
html = html.replace(STYLE, function(_, types, _style) {
|
216
|
-
var scoped = /(?:^|\s+)scoped(\s|=|$)/i.test(types),
|
217
|
-
type = types && types.match(/(?:^|\s+)type\s*=\s*['"]?([^'"\s]+)['"]?/i)
|
218
|
-
if (type) type = type[1].replace('text/', '')
|
219
|
-
style += (style ? ' ' : '') + compileCSS(_style.trim(), tagName, type || 'css', scoped)
|
220
|
-
return ''
|
221
|
-
})
|
222
|
-
}
|
223
|
-
|
224
|
-
return mktag(
|
225
|
-
tagName,
|
226
|
-
compileHTML(html, opts, type),
|
227
|
-
style,
|
228
|
-
compileHTML(attrs, ''),
|
229
|
-
compileJS(js, opts, type)
|
230
|
-
)
|
231
|
-
|
232
|
-
})
|
233
|
-
|
234
|
-
}
|