summaryrefslogtreecommitdiffstats
path: root/lib/template/loader.js
blob: 6b54015ac8908a2fbe4ac6e2a30fcdbf4e6efbe9 (plain)
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
var nunjucks = require('nunjucks');
var location = require('../utils/location');

/*
Simple nunjucks loader which is passing the reponsability to the Output
*/

var Loader = nunjucks.Loader.extend({
    async: true,

    init: function(output, opts) {
        this.output = output;
    },

    getSource: function(sourceURL, callback) {
        this.output.onGetTemplate(sourceURL)
        .then(function(out) {
            // We disable cache since content is modified (shortcuts, ...)
            out.noCache = true;

            return out;
        })
        .nodeify(callback);
    },

    resolve: function(from, to) {
        return this.output.onResolveTemplate(from, to);
    },

    // Handle all files as relative, so that nunjucks pass responsability to 'resolve'
    isRelative: function(filename) {
        return location.isRelative(filename);
    }
});

module.exports = Loader;