-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (25 loc) · 971 Bytes
/
index.js
File metadata and controls
31 lines (25 loc) · 971 Bytes
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
var fs = require('fs'),
path = require('path'),
hogan = require('hogan.js'),
rootFolder = path.resolve(path.dirname('')) + '/templates/mustache',
loaderUtils = require('loader-utils');
module.exports = function(source) {
'use strict';
var query = loaderUtils.parseQuery(this.query);
function inline_mustache_template(tmplPath) {
if (!tmplPath) {
return '';
}
var templates = {},
compiled = Hogan.compile(source);
compiled.partials.forEach(function (key, data) {
var template = fs.readFileSync(path.resolve(rootFolder, data.name));
templates[data.name] = template.toString();
});
templates.forEach(function (partial, template) {
source.replace('{{>' + partial + '}}', template);
});
return source;
}
return "define(['hogan'], function (Hogan) { return '" + inline_mustache_template(query.path) + "'})";
};