-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (48 loc) · 1.6 KB
/
index.js
File metadata and controls
55 lines (48 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var through = require('through')
var toSource = require('tosource')
var rcu = require('rcu')
rcu.init(require('ractive'))
module.exports = function(file, options) {
var ext = options && options.extension
? options.extension
: 'ract';
if (!new RegExp('\\.' + ext + '$', 'i').test(file)) {
return through()
}
var source = ''
var stream = through(
function write(buf) {
source += buf
},
function end() {
try {
var component = rcu.parse(source)
var script
if (component.script) {
script = [
'var component = module',
component.script
]
if (component.template) {
script.push('component.exports.template = '+toSource(component.template))
}
if (component.css) {
script.push('component.exports.css = '+toSource(component.css))
}
this.queue(script.join('\n\n'))
} else {
script = []
script.push('exports.template = '+toSource(component.template))
if (component.css) {
script.push('exports.css = '+toSource(component.css))
}
this.queue(script.join('\n\n'))
}
this.queue(null)
} catch (ex) {
stream.emit('error', ex)
}
}
)
return stream
};