-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfind-partials.js
49 lines (45 loc) · 1.18 KB
/
find-partials.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
function findPartials (template) {
var allIncludes = template.match(/{[\s+]?(include)[^}]*}/g)
var allExtends = template.match(/{[\s+]?(extends)[^}]*}/g)
var allPartials = []
var actualIncludes = []
var t
var p
var k
var i
var params = []
if (allIncludes && allIncludes.length > 0) {
for (i = 0; i < allIncludes.length; i++) {
t = allIncludes[i].match(/{[\s+]?include(.*)}/)
if (t && t[1]) {
p = t[1]
allPartials.push(p)
}
}
}
if (allExtends && allExtends.length > 0) {
for (i = 0; i < allExtends.length; i++) {
t = allExtends[i].match(/{[\s+]?extends(.*)}/)
if (t && t[1]) {
p = t[1]
allPartials.push(p)
}
}
}
if (allPartials && allPartials.length > 0) {
for (i = 0; i < allPartials.length; i++) {
params = allPartials[i].match(/file=(.*)/)
if (params) {
k = params[1].trim().match(/['"](.*)['"]/)
} else {
k = allPartials[i].trim().match(/['"](.*)['"]/)
}
if (k) {
// If string has quotes.
actualIncludes.push(k[1].trim().replace(/^['"](.*)['"]$/, '$1'))
}
}
}
return actualIncludes
}
module.exports = findPartials