UNPKG

1.87 kBJavaScriptView Raw
1(function() {
2 var LiquidEngine, Path, Q, exports, fs, grunt, plugin;
3
4 LiquidEngine = require("./liquid-ext");
5
6 Q = require("q");
7
8 fs = require("fs");
9
10 Path = require("path");
11
12 grunt = require("grunt");
13
14 plugin = function() {
15 var compile, engine, ensureCompiled, init, registerFunctions, registerHelper, render;
16 engine = null;
17 init = function(options) {
18 return engine = new LiquidEngine;
19 };
20 compile = function(src, options) {
21 return engine.extParse(src, function(layout, cb) {
22 var layoutSource, layoutSources;
23 layoutSources = Path.join(options.layoutdir, "" + layout + ".liquid");
24 layoutSource = grunt.file.expand(layoutSources)[0];
25 return Q(layoutSource).then(grunt.file.read).nodeify(cb);
26 });
27 };
28 ensureCompiled = function(template, options) {
29 if (typeof template === "string") {
30 return compile(template, options);
31 } else {
32 return template;
33 }
34 };
35 render = function(template, options) {
36 return ensureCompiled(template, options).then(function(template) {
37 return template.render(options);
38 });
39 };
40 registerFunctions = function(helperFunctions) {
41 return engine.registerFilters(helperFunctions);
42 };
43 registerHelper = function(helperName, helper) {
44 var o;
45 o = {};
46 o[helperName] = helper;
47 return registerFunctions(o);
48 };
49 return {
50 init: init,
51 compile: function(src, options, callback) {
52 return compile.apply(null, arguments).nodeify(callback);
53 },
54 render: function(template, options, callback) {
55 return render.apply(null, arguments).nodeify(callback);
56 },
57 registerFunctions: registerFunctions,
58 registerHelper: registerHelper,
59 liquid: LiquidEngine
60 };
61 };
62
63 module.exports = exports = plugin();
64
65}).call(this);