-
Notifications
You must be signed in to change notification settings - Fork 0
/
goto.js
65 lines (55 loc) · 1.53 KB
/
goto.js
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
56
57
58
59
60
61
62
63
64
65
var tracker = new Tracker.Dependency
function _namespacer(path) {
this.template_path = path
}
Namespacer = new _namespacer('')
_namespacer.prototype.getTemplate = function(name) {
var path = this.getPath()
if (!path) {
path = ['']
} else {
path = path.split(':')
path.push('')
}
for (var i = 0; i < path.length; i++) {
var check = (path[i].length ? path[i] + '_' : path[i]) + name
if (undefined !== Template[check]) {
return check
}
}
return name
}
_namespacer.prototype.apply = function(name, tocall, arg, path) {
path = path.split(':')
path.forEach(function (p) {
var t = Template[p ? p + '_' + name : name]
if (!t) return
t[tocall].call(t, arg)
})
}
_namespacer.prototype.helpers = function(name, helpers, path) {
this.apply(name, 'helpers', helpers, path)
}
_namespacer.prototype.events = function(name, events, path) {
this.apply(name, 'events', events, path)
}
_namespacer.prototype.getPath = function() {
tracker.depend()
return this.template_path
}
_namespacer.prototype.setPath = function(name) {
if (name != this.template_path) {
tracker.changed()
}
this.template_path = name
}
Template.registerHelper("set_template_path", function(data) {
Namespacer.setPath(data)
})
Template.registerHelper("___goto", function() {
var args = Array.prototype.slice.call(arguments)
if (args[1] === '***noargs***') {
return {template: Namespacer.getTemplate(args[0]), data: Template.currentData()}
}
return {template: Namespacer.getTemplate(args[0]), data: args[1].hash}
})