riotjs-rails 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile +2 -0
- data/LICENSE.md +21 -0
- data/Rakefile +1 -0
- data/Readme.md +19 -0
- data/lib/riotjs-rails.rb +10 -0
- data/lib/riotjs-rails/version.rb +5 -0
- data/riotjs-rails.gemspec +22 -0
- data/vendor/assets/javascripts/riot.js +689 -0
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3afcc6d3f0fb93859997d05e835ee6db0249aa9
|
4
|
+
data.tar.gz: 3b5176c3b3a83cb53defd47744450328db97d304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f38b2c14492883d2099e7aa8e6411ea77a9088393e1fb24bafc099d5044072468e052640081994501f31d77bc6bc72a4cff6a0d80e25c64565152017664eb4a6
|
7
|
+
data.tar.gz: a22e0f819fcb8620d5be77ce7a0e6f71c8859fa4dd9e8592d9a52b7ac869f60f137d2e9d76781234c5aceca47d0c6e81e36044f1c53cba6561ef141d5887cf87
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Adam Butler
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/Readme.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# riotjs-rails <a href="http://badge.fury.io/rb/riotjs-rails"><img src="https://badge.fury.io/rb/riotjs-rails@2x.png" alt="Gem Version" height="18"></a>
|
2
|
+
|
3
|
+
### About
|
4
|
+
|
5
|
+
Rails 3.1+ asset-pipeline gem to provide riot.js
|
6
|
+
|
7
|
+
### Setup
|
8
|
+
|
9
|
+
Have in your Gemfile:
|
10
|
+
|
11
|
+
gem 'riotjs-rails'
|
12
|
+
|
13
|
+
And, have in your application.js manifest:
|
14
|
+
|
15
|
+
//= require riot
|
16
|
+
|
17
|
+
## Contributing
|
18
|
+
|
19
|
+
Contributions are welcome, please follow [GitHub Flow](https://guides.github.com/introduction/flow/index.html)
|
data/lib/riotjs-rails.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "riotjs-rails/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "riotjs-rails"
|
7
|
+
s.version = Riot::Rails::VERSION
|
8
|
+
s.authors = ["Adam Butler"]
|
9
|
+
s.email = ["adam@lab.io"]
|
10
|
+
s.homepage = "https://github.com/adambutler/riotjs-rails"
|
11
|
+
s.summary = %q{riot.js asset pipeline provider/wrapper}
|
12
|
+
s.description = "A simple asset-pipeline wrapper for riot.js by moot"
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.rubyforge_project = "riotjs-rails"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,689 @@
|
|
1
|
+
/* Riot 2.0.2, @license MIT, (c) 2015 Muut Inc. + contributors */
|
2
|
+
|
3
|
+
;(function() {
|
4
|
+
|
5
|
+
var riot = { version: 'v2.0.2' }
|
6
|
+
|
7
|
+
'use strict'
|
8
|
+
|
9
|
+
riot.observable = function(el) {
|
10
|
+
var callbacks = {}
|
11
|
+
|
12
|
+
el.on = function(events, fn) {
|
13
|
+
if (typeof fn == 'function') {
|
14
|
+
events.replace(/\S+/g, function(name, pos) {
|
15
|
+
(callbacks[name] = callbacks[name] || []).push(fn)
|
16
|
+
fn.typed = pos > 0
|
17
|
+
})
|
18
|
+
}
|
19
|
+
return el
|
20
|
+
}
|
21
|
+
|
22
|
+
el.off = function(events, fn) {
|
23
|
+
if (events == '*') callbacks = {}
|
24
|
+
else if (fn) {
|
25
|
+
var arr = callbacks[events]
|
26
|
+
for (var i = 0, cb; (cb = arr && arr[i]); ++i) {
|
27
|
+
if (cb == fn) { arr.splice(i, 1); i-- }
|
28
|
+
}
|
29
|
+
} else {
|
30
|
+
events.replace(/\S+/g, function(name) {
|
31
|
+
callbacks[name] = []
|
32
|
+
})
|
33
|
+
}
|
34
|
+
return el
|
35
|
+
}
|
36
|
+
|
37
|
+
// only single event supported
|
38
|
+
el.one = function(name, fn) {
|
39
|
+
if (fn) fn.one = 1
|
40
|
+
return el.on(name, fn)
|
41
|
+
}
|
42
|
+
|
43
|
+
el.trigger = function(name) {
|
44
|
+
var args = [].slice.call(arguments, 1),
|
45
|
+
fns = callbacks[name] || []
|
46
|
+
|
47
|
+
for (var i = 0, fn; (fn = fns[i]); ++i) {
|
48
|
+
if (!fn.busy) {
|
49
|
+
fn.busy = 1
|
50
|
+
fn.apply(el, fn.typed ? [name].concat(args) : args)
|
51
|
+
if (fn.one) { fns.splice(i, 1); i-- }
|
52
|
+
fn.busy = 0
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
return el
|
57
|
+
}
|
58
|
+
|
59
|
+
return el
|
60
|
+
|
61
|
+
}
|
62
|
+
;(function(riot, evt) {
|
63
|
+
|
64
|
+
// browsers only
|
65
|
+
if (!this.top) return
|
66
|
+
|
67
|
+
var loc = location,
|
68
|
+
fns = riot.observable({}),
|
69
|
+
current = hash(),
|
70
|
+
win = window
|
71
|
+
|
72
|
+
function hash() {
|
73
|
+
return loc.hash.slice(1)
|
74
|
+
}
|
75
|
+
|
76
|
+
function emit(path) {
|
77
|
+
if (path.type) path = hash()
|
78
|
+
|
79
|
+
if (path != current) {
|
80
|
+
fns.trigger.apply(null, ['H'].concat(path.split('/')))
|
81
|
+
current = path
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
var r = riot.route = function(arg) {
|
86
|
+
// string
|
87
|
+
if (arg[0]) {
|
88
|
+
loc.hash = arg
|
89
|
+
emit(arg)
|
90
|
+
|
91
|
+
// function
|
92
|
+
} else {
|
93
|
+
fns.on('H', arg)
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
r.exec = function(fn) {
|
98
|
+
fn.apply(null, hash().split('/'))
|
99
|
+
}
|
100
|
+
|
101
|
+
win.addEventListener ? win.addEventListener(evt, emit, false) : win.attachEvent('on' + evt, emit)
|
102
|
+
|
103
|
+
})(riot, 'hashchange')
|
104
|
+
/*
|
105
|
+
|
106
|
+
//// How it works?
|
107
|
+
|
108
|
+
|
109
|
+
Three ways:
|
110
|
+
|
111
|
+
1. Expressions: tmpl('{ value }', data).
|
112
|
+
Returns the result of evaluated expression as a raw object.
|
113
|
+
|
114
|
+
2. Templates: tmpl('Hi { name } { surname }', data).
|
115
|
+
Returns a string with evaluated expressions.
|
116
|
+
|
117
|
+
3. Filters: tmpl('{ show: !done, highlight: active }', data).
|
118
|
+
Returns a space separated list of trueish keys (mainly
|
119
|
+
used for setting html classes), e.g. "show highlight".
|
120
|
+
|
121
|
+
|
122
|
+
// Template examples
|
123
|
+
|
124
|
+
tmpl('{ title || "Untitled" }', data)
|
125
|
+
tmpl('Results are { results ? "ready" : "loading" }', data)
|
126
|
+
tmpl('Today is { new Date() }', data)
|
127
|
+
tmpl('{ message.length > 140 && "Message is too long" }', data)
|
128
|
+
tmpl('This item got { Math.round(rating) } stars', data)
|
129
|
+
tmpl('<h1>{ title }</h1>{ body }', data)
|
130
|
+
|
131
|
+
|
132
|
+
// Falsy expressions in templates
|
133
|
+
|
134
|
+
In templates (as opposed to single expressions) all falsy values
|
135
|
+
except zero (undefined/null/false) will default to empty string:
|
136
|
+
|
137
|
+
tmpl('{ undefined } - { false } - { null } - { 0 }', {})
|
138
|
+
// will return: " - - - 0"
|
139
|
+
|
140
|
+
*/
|
141
|
+
|
142
|
+
riot._tmpl = (function() {
|
143
|
+
|
144
|
+
var cache = {},
|
145
|
+
|
146
|
+
// find variable names
|
147
|
+
re_vars = /("|').+?[^\\]\1|\.\w*|\w*:|\b(?:this|true|false|null|undefined|new|typeof|Number|String|Object|Array|Math|Date|JSON)\b|([a-z_]\w*)/gi
|
148
|
+
// [ 1 ][ 2 ][ 3 ][ 4 ][ 5 ]
|
149
|
+
// 1. skip quoted strings: "a b", 'a b', 'a \'b\''
|
150
|
+
// 2. skip object properties: .name
|
151
|
+
// 3. skip object literals: name:
|
152
|
+
// 4. skip reserved words
|
153
|
+
// 5. match var name
|
154
|
+
|
155
|
+
// build a template (or get it from cache), render with data
|
156
|
+
|
157
|
+
return function(str, data) {
|
158
|
+
return str && (cache[str] = cache[str] || tmpl(str))(data)
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
// create a template instance
|
163
|
+
|
164
|
+
function tmpl(s, p) {
|
165
|
+
p = (s || '{}')
|
166
|
+
|
167
|
+
// temporarily convert \{ and \} to a non-character
|
168
|
+
.replace(/\\{/g, '\uFFF0')
|
169
|
+
.replace(/\\}/g, '\uFFF1')
|
170
|
+
|
171
|
+
// split string to expression and non-expresion parts
|
172
|
+
.split(/({[\s\S]*?})/)
|
173
|
+
|
174
|
+
return new Function('d', 'return ' + (
|
175
|
+
|
176
|
+
// is it a single expression or a template? i.e. {x} or <b>{x}</b>
|
177
|
+
!p[0] && !p[2]
|
178
|
+
|
179
|
+
// if expression, evaluate it
|
180
|
+
? expr(p[1])
|
181
|
+
|
182
|
+
// if template, evaluate all expressions in it
|
183
|
+
: '[' + p.map(function(s, i) {
|
184
|
+
|
185
|
+
// is it an expression or a string (every second part is an expression)
|
186
|
+
return i % 2
|
187
|
+
|
188
|
+
// evaluate the expressions
|
189
|
+
? expr(s, 1)
|
190
|
+
|
191
|
+
// process string parts of the template:
|
192
|
+
: '"' + s
|
193
|
+
|
194
|
+
// preserve new lines
|
195
|
+
.replace(/\n/g, '\\n')
|
196
|
+
|
197
|
+
// escape quotes
|
198
|
+
.replace(/"/g, '\\"')
|
199
|
+
|
200
|
+
+ '"'
|
201
|
+
|
202
|
+
}).join(',') + '].join("")'
|
203
|
+
)
|
204
|
+
|
205
|
+
// bring escaped { and } back
|
206
|
+
.replace(/\uFFF0/g, '{')
|
207
|
+
.replace(/\uFFF1/g, '}')
|
208
|
+
|
209
|
+
)
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
// parse { ... } expression
|
215
|
+
|
216
|
+
function expr(s, n) {
|
217
|
+
s = s
|
218
|
+
|
219
|
+
// convert new lines to spaces
|
220
|
+
.replace(/\n/g, ' ')
|
221
|
+
|
222
|
+
// trim whitespace, curly brackets, strip comments
|
223
|
+
.replace(/^[{ ]+|[ }]+$|\/\*.+?\*\//g, '')
|
224
|
+
|
225
|
+
// is it an object literal? i.e. { key : value }
|
226
|
+
return /^\s*[\w-"']+ *:/.test(s)
|
227
|
+
|
228
|
+
// if object literal, return trueish keys
|
229
|
+
// e.g.: { show: isOpen(), done: item.done } -> "show done"
|
230
|
+
? '[' + s.replace(/\W*([\w-]+)\W*:([^,]+)/g, function(_, k, v) {
|
231
|
+
|
232
|
+
// safely execute vars to prevent undefined value errors
|
233
|
+
return v.replace(/\w[^,|& ]*/g, function(v) { return wrap(v, n) }) + '?"' + k + '":"",'
|
234
|
+
|
235
|
+
}) + '].join(" ")'
|
236
|
+
|
237
|
+
// if js expression, evaluate as javascript
|
238
|
+
: wrap(s, n)
|
239
|
+
|
240
|
+
}
|
241
|
+
|
242
|
+
|
243
|
+
// execute js w/o breaking on errors or undefined vars
|
244
|
+
|
245
|
+
function wrap(s, nonull) {
|
246
|
+
return '(function(v){try{v='
|
247
|
+
|
248
|
+
// prefix vars (name => data.name)
|
249
|
+
+ (s.replace(re_vars, function(s, _, v) { return v ? 'd.' + v : s })
|
250
|
+
|
251
|
+
// break the expression if its empty (resulting in undefined value)
|
252
|
+
|| 'x')
|
253
|
+
|
254
|
+
+ '}finally{return '
|
255
|
+
|
256
|
+
// default to empty string for falsy values except zero
|
257
|
+
+ (nonull ? '!v&&v!==0?"":v' : 'v')
|
258
|
+
|
259
|
+
+ '}}).call(d)'
|
260
|
+
}
|
261
|
+
|
262
|
+
})()
|
263
|
+
;(function(riot, doc) {
|
264
|
+
|
265
|
+
var tmpl = riot._tmpl,
|
266
|
+
all_tags = [],
|
267
|
+
tag_impl = {}
|
268
|
+
|
269
|
+
function each(nodes, fn) {
|
270
|
+
for (var i = 0; i < (nodes || []).length; i++) {
|
271
|
+
if (fn(nodes[i], i) === false) i--
|
272
|
+
}
|
273
|
+
}
|
274
|
+
|
275
|
+
function extend(obj, from) {
|
276
|
+
from && Object.keys(from).map(function(key) {
|
277
|
+
obj[key] = from[key]
|
278
|
+
})
|
279
|
+
return obj
|
280
|
+
}
|
281
|
+
|
282
|
+
function diff(arr1, arr2) {
|
283
|
+
return arr1.filter(function(el) {
|
284
|
+
return arr2.indexOf(el) < 0
|
285
|
+
})
|
286
|
+
}
|
287
|
+
|
288
|
+
function walk(dom, fn) {
|
289
|
+
dom = fn(dom) === false ? dom.nextSibling : dom.firstChild
|
290
|
+
|
291
|
+
while (dom) {
|
292
|
+
walk(dom, fn)
|
293
|
+
dom = dom.nextSibling
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
function mkdom(tmpl) {
|
299
|
+
var el = doc.createElement('div')
|
300
|
+
el.innerHTML = tmpl
|
301
|
+
return el
|
302
|
+
}
|
303
|
+
|
304
|
+
|
305
|
+
function update(expressions, instance) {
|
306
|
+
|
307
|
+
// allow recalculation of context data
|
308
|
+
instance.trigger('update')
|
309
|
+
|
310
|
+
each(expressions, function(expr) {
|
311
|
+
var tag = expr.tag,
|
312
|
+
dom = expr.dom
|
313
|
+
|
314
|
+
function remAttr(name) {
|
315
|
+
dom.removeAttribute(name)
|
316
|
+
}
|
317
|
+
|
318
|
+
// loops first: TODO remove from expressions arr
|
319
|
+
if (expr.loop) {
|
320
|
+
remAttr('each')
|
321
|
+
return loop(expr, instance)
|
322
|
+
}
|
323
|
+
|
324
|
+
// custom tag
|
325
|
+
if (tag) return tag.update ? tag.update() :
|
326
|
+
expr.tag = createTag({ tmpl: tag[0], fn: tag[1], root: dom, parent: instance })
|
327
|
+
|
328
|
+
|
329
|
+
var attr_name = expr.attr,
|
330
|
+
value = tmpl(expr.expr, instance)
|
331
|
+
|
332
|
+
if (value == null) value = ''
|
333
|
+
|
334
|
+
// no change
|
335
|
+
if (expr.value === value) return
|
336
|
+
expr.value = value
|
337
|
+
|
338
|
+
|
339
|
+
// text node
|
340
|
+
if (!attr_name) return dom.nodeValue = value
|
341
|
+
|
342
|
+
// attribute
|
343
|
+
if (!value && expr.bool || /obj|func/.test(typeof value)) remAttr(attr_name)
|
344
|
+
|
345
|
+
// event handler
|
346
|
+
if (typeof value == 'function') {
|
347
|
+
dom[attr_name] = function(e) {
|
348
|
+
|
349
|
+
// cross browser event fix
|
350
|
+
e = e || window.event
|
351
|
+
e.which = e.which || e.charCode || e.keyCode
|
352
|
+
e.target = e.target || e.srcElement
|
353
|
+
e.currentTarget = dom
|
354
|
+
|
355
|
+
// currently looped item
|
356
|
+
e.item = instance.__item || instance
|
357
|
+
|
358
|
+
// prevent default behaviour (by default)
|
359
|
+
if (value.call(instance, e) !== true) {
|
360
|
+
e.preventDefault && e.preventDefault()
|
361
|
+
e.returnValue = false
|
362
|
+
}
|
363
|
+
|
364
|
+
instance.update()
|
365
|
+
}
|
366
|
+
|
367
|
+
// show / hide / if
|
368
|
+
} else if (/^(show|hide|if)$/.test(attr_name)) {
|
369
|
+
remAttr(attr_name)
|
370
|
+
if (attr_name == 'hide') value = !value
|
371
|
+
dom.style.display = value ? '' : 'none'
|
372
|
+
|
373
|
+
// normal attribute
|
374
|
+
} else {
|
375
|
+
if (expr.bool) {
|
376
|
+
if (!value) return
|
377
|
+
value = attr_name
|
378
|
+
}
|
379
|
+
|
380
|
+
dom.setAttribute(attr_name, value)
|
381
|
+
}
|
382
|
+
|
383
|
+
})
|
384
|
+
|
385
|
+
instance.trigger('updated')
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
function parse(root) {
|
390
|
+
|
391
|
+
var named_elements = {},
|
392
|
+
expressions = []
|
393
|
+
|
394
|
+
walk(root, function(dom) {
|
395
|
+
|
396
|
+
var type = dom.nodeType,
|
397
|
+
value = dom.nodeValue
|
398
|
+
|
399
|
+
function addExpr(value, data) {
|
400
|
+
if (value ? value.indexOf('{') >= 0 : data) {
|
401
|
+
var expr = { dom: dom, expr: value }
|
402
|
+
expressions.push(extend(expr, data || {}))
|
403
|
+
}
|
404
|
+
}
|
405
|
+
|
406
|
+
// text node
|
407
|
+
if (type == 3 && dom.parentNode.tagName != 'STYLE') {
|
408
|
+
addExpr(value)
|
409
|
+
|
410
|
+
// element
|
411
|
+
} else if (type == 1) {
|
412
|
+
|
413
|
+
// loop?
|
414
|
+
value = dom.getAttribute('each')
|
415
|
+
|
416
|
+
if (value) {
|
417
|
+
addExpr(value, { loop: 1 })
|
418
|
+
return false
|
419
|
+
}
|
420
|
+
|
421
|
+
// custom tag?
|
422
|
+
var tag = tag_impl[dom.tagName.toLowerCase()]
|
423
|
+
|
424
|
+
// attributes
|
425
|
+
each(dom.attributes, function(attr) {
|
426
|
+
var name = attr.name,
|
427
|
+
value = attr.value
|
428
|
+
|
429
|
+
// named elements
|
430
|
+
if (/^(name|id)$/.test(name)) named_elements[value] = dom
|
431
|
+
|
432
|
+
// expressions
|
433
|
+
if (!tag) {
|
434
|
+
var bool = name.split('__')[1]
|
435
|
+
addExpr(value, { attr: bool || name, bool: bool })
|
436
|
+
if (bool) {
|
437
|
+
dom.removeAttribute(name)
|
438
|
+
return false
|
439
|
+
}
|
440
|
+
}
|
441
|
+
|
442
|
+
})
|
443
|
+
|
444
|
+
if (tag) addExpr(0, { tag: tag })
|
445
|
+
|
446
|
+
}
|
447
|
+
|
448
|
+
})
|
449
|
+
|
450
|
+
return { expr: expressions, elem: named_elements }
|
451
|
+
|
452
|
+
}
|
453
|
+
|
454
|
+
|
455
|
+
|
456
|
+
// create new custom tag (component)
|
457
|
+
function createTag(conf) {
|
458
|
+
|
459
|
+
var opts = conf.opts || {},
|
460
|
+
dom = mkdom(conf.tmpl),
|
461
|
+
mountNode = conf.root,
|
462
|
+
parent = conf.parent,
|
463
|
+
ast = parse(dom),
|
464
|
+
tag = { root: mountNode, opts: opts, parent: parent, __item: conf.item },
|
465
|
+
attributes = {}
|
466
|
+
|
467
|
+
// named elements
|
468
|
+
extend(tag, ast.elem)
|
469
|
+
|
470
|
+
// attributes
|
471
|
+
each(mountNode.attributes, function(attr) {
|
472
|
+
attributes[attr.name] = attr.value
|
473
|
+
})
|
474
|
+
|
475
|
+
function updateOpts() {
|
476
|
+
Object.keys(attributes).map(function(name) {
|
477
|
+
var val = opts[name] = tmpl(attributes[name], parent || tag)
|
478
|
+
if (typeof val == 'object') mountNode.removeAttribute(name)
|
479
|
+
})
|
480
|
+
}
|
481
|
+
|
482
|
+
updateOpts()
|
483
|
+
|
484
|
+
if (!tag.on) {
|
485
|
+
riot.observable(tag)
|
486
|
+
delete tag.off // off method not needed
|
487
|
+
}
|
488
|
+
|
489
|
+
if (conf.fn) conf.fn.call(tag, opts)
|
490
|
+
|
491
|
+
|
492
|
+
tag.update = function(data, _system) {
|
493
|
+
|
494
|
+
/*
|
495
|
+
If loop is defined on the root of the HTML template
|
496
|
+
the original parent is a temporary <div/> by mkdom()
|
497
|
+
*/
|
498
|
+
if (parent && dom && !dom.firstChild) {
|
499
|
+
mountNode = parent.root
|
500
|
+
dom = null
|
501
|
+
}
|
502
|
+
|
503
|
+
if (_system || doc.body.contains(mountNode)) {
|
504
|
+
extend(tag, data)
|
505
|
+
extend(tag, tag.__item)
|
506
|
+
updateOpts()
|
507
|
+
update(ast.expr, tag)
|
508
|
+
|
509
|
+
// update parent
|
510
|
+
!_system && tag.__item && parent.update()
|
511
|
+
return true
|
512
|
+
|
513
|
+
} else {
|
514
|
+
tag.trigger('unmount')
|
515
|
+
}
|
516
|
+
|
517
|
+
}
|
518
|
+
|
519
|
+
tag.update(0, true)
|
520
|
+
|
521
|
+
// append to root
|
522
|
+
while (dom.firstChild) {
|
523
|
+
if (conf.before) mountNode.insertBefore(dom.firstChild, conf.before)
|
524
|
+
else mountNode.appendChild(dom.firstChild)
|
525
|
+
}
|
526
|
+
|
527
|
+
|
528
|
+
tag.trigger('mount')
|
529
|
+
|
530
|
+
all_tags.push(tag)
|
531
|
+
|
532
|
+
return tag
|
533
|
+
}
|
534
|
+
|
535
|
+
|
536
|
+
function loop(expr, instance) {
|
537
|
+
|
538
|
+
// initialize once
|
539
|
+
if (expr.done) return
|
540
|
+
expr.done = true
|
541
|
+
|
542
|
+
var dom = expr.dom,
|
543
|
+
prev = dom.previousSibling,
|
544
|
+
root = dom.parentNode,
|
545
|
+
template = dom.outerHTML,
|
546
|
+
val = expr.expr,
|
547
|
+
els = val.split(/\s+in\s+/),
|
548
|
+
rendered = [],
|
549
|
+
checksum,
|
550
|
+
keys
|
551
|
+
|
552
|
+
|
553
|
+
if (els[1]) {
|
554
|
+
val = '{ ' + els[1]
|
555
|
+
keys = els[0].slice(1).trim().split(/,\s*/)
|
556
|
+
}
|
557
|
+
|
558
|
+
// clean template code
|
559
|
+
instance.one('mount', function() {
|
560
|
+
var p = dom.parentNode
|
561
|
+
if (p) {
|
562
|
+
root = p
|
563
|
+
root.removeChild(dom)
|
564
|
+
}
|
565
|
+
})
|
566
|
+
|
567
|
+
function startPos() {
|
568
|
+
return Array.prototype.indexOf.call(root.childNodes, prev) + 1
|
569
|
+
}
|
570
|
+
|
571
|
+
instance.on('updated', function() {
|
572
|
+
|
573
|
+
var items = tmpl(val, instance)
|
574
|
+
is_array = Array.isArray(items)
|
575
|
+
|
576
|
+
if (is_array) items = items.slice(0)
|
577
|
+
|
578
|
+
else {
|
579
|
+
|
580
|
+
if (!items) return // some IE8 issue
|
581
|
+
|
582
|
+
// detect Object changes
|
583
|
+
var testsum = JSON.stringify(items)
|
584
|
+
if (testsum == checksum) return
|
585
|
+
checksum = testsum
|
586
|
+
|
587
|
+
items = Object.keys(items).map(function(key, i) {
|
588
|
+
var item = {}
|
589
|
+
item[keys[0]] = key
|
590
|
+
item[keys[1]] = items[key]
|
591
|
+
return item
|
592
|
+
})
|
593
|
+
|
594
|
+
}
|
595
|
+
|
596
|
+
// remove redundant
|
597
|
+
diff(rendered, items).map(function(item) {
|
598
|
+
var pos = rendered.indexOf(item)
|
599
|
+
root.removeChild(root.childNodes[startPos() + pos])
|
600
|
+
rendered.splice(pos, 1)
|
601
|
+
})
|
602
|
+
|
603
|
+
// add new
|
604
|
+
diff(items, rendered).map(function(item, i) {
|
605
|
+
var pos = items.indexOf(item)
|
606
|
+
|
607
|
+
// string array
|
608
|
+
if (keys && !checksum) {
|
609
|
+
var obj = {}
|
610
|
+
obj[keys[0]] = item
|
611
|
+
obj[keys[1]] = i
|
612
|
+
item = obj
|
613
|
+
}
|
614
|
+
|
615
|
+
var tag = createTag({
|
616
|
+
before: root.childNodes[startPos() + pos],
|
617
|
+
parent: instance,
|
618
|
+
tmpl: template,
|
619
|
+
item: item,
|
620
|
+
root: root
|
621
|
+
})
|
622
|
+
|
623
|
+
instance.on('update', function() {
|
624
|
+
tag.update(0, true)
|
625
|
+
})
|
626
|
+
|
627
|
+
})
|
628
|
+
|
629
|
+
// assign rendered
|
630
|
+
rendered = items
|
631
|
+
|
632
|
+
})
|
633
|
+
|
634
|
+
}
|
635
|
+
|
636
|
+
riot.tag = function(name, tmpl, fn) {
|
637
|
+
fn = fn || noop,
|
638
|
+
tag_impl[name] = [tmpl, fn]
|
639
|
+
}
|
640
|
+
|
641
|
+
riot.mountTo = function(node, tagName, opts) {
|
642
|
+
var tag = tag_impl[tagName]
|
643
|
+
return tag && createTag({ tmpl: tag[0], fn: tag[1], root: node, opts: opts })
|
644
|
+
}
|
645
|
+
|
646
|
+
riot.mount = function(selector, opts) {
|
647
|
+
if (selector == '*') selector = Object.keys(tag_impl).join(', ')
|
648
|
+
|
649
|
+
var instances = []
|
650
|
+
|
651
|
+
each(doc.querySelectorAll(selector), function(node) {
|
652
|
+
if (node.riot) return
|
653
|
+
|
654
|
+
var tagName = node.tagName.toLowerCase(),
|
655
|
+
instance = riot.mountTo(node, tagName, opts)
|
656
|
+
|
657
|
+
if (instance) {
|
658
|
+
instances.push(instance)
|
659
|
+
node.riot = 1
|
660
|
+
}
|
661
|
+
})
|
662
|
+
|
663
|
+
return instances
|
664
|
+
}
|
665
|
+
|
666
|
+
// update everything
|
667
|
+
riot.update = function() {
|
668
|
+
return all_tags = all_tags.filter(function(tag) {
|
669
|
+
return !!tag.update()
|
670
|
+
})
|
671
|
+
}
|
672
|
+
|
673
|
+
})(riot, document)
|
674
|
+
|
675
|
+
|
676
|
+
// support CommonJS
|
677
|
+
if (typeof exports === 'object')
|
678
|
+
module.exports = riot
|
679
|
+
|
680
|
+
// support AMD
|
681
|
+
else if (typeof define === 'function' && define.amd)
|
682
|
+
define(function() { return riot })
|
683
|
+
|
684
|
+
// support browser
|
685
|
+
else
|
686
|
+
this.riot = riot
|
687
|
+
|
688
|
+
})();
|
689
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riotjs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Butler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple asset-pipeline wrapper for riot.js by moot
|
14
14
|
email:
|
@@ -16,7 +16,16 @@ email:
|
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
|
-
files:
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
22
|
+
- LICENSE.md
|
23
|
+
- Rakefile
|
24
|
+
- Readme.md
|
25
|
+
- lib/riotjs-rails.rb
|
26
|
+
- lib/riotjs-rails/version.rb
|
27
|
+
- riotjs-rails.gemspec
|
28
|
+
- vendor/assets/javascripts/riot.js
|
20
29
|
homepage: https://github.com/adambutler/riotjs-rails
|
21
30
|
licenses:
|
22
31
|
- MIT
|
@@ -42,3 +51,4 @@ signing_key:
|
|
42
51
|
specification_version: 4
|
43
52
|
summary: riot.js asset pipeline provider/wrapper
|
44
53
|
test_files: []
|
54
|
+
has_rdoc:
|