2 次代码提交 489fd97eaf ... 820518d211

作者 SHA1 备注 提交日期
  Alex Gleason 820518d211 1.3.0 7 年之前
  Alex Gleason 8bbde1b9fa Add .njk file extension 7 年之前
共有 3 个文件被更改,包括 43 次插入8 次删除
  1. 7 7
      lib/helpers/raw.js
  2. 35 0
      lib/template/processors/njk.js
  3. 1 1
      package.json

+ 7 - 7
lib/helpers/raw.js

@@ -13,7 +13,7 @@ var TerraformError = exports.TerraformError = require("../error").TerraformError
  */
 
 var processors = exports.processors = {
-  "html": ["jade", "ejs", "md", "nunjucks"],
+  "html": ["jade", "ejs", "md", "nunjucks", "njk"],
   "css" : ["styl", "less", "scss", "sass"],
   "js"  : ["coffee"]
 }
@@ -161,7 +161,7 @@ var findNearestLayout = exports.findNearestLayout = function(rootPath, dirPath)
 
 /**
  * Find Default Layout
- * 
+ *
  * returns null if outputing json
  */
 
@@ -170,7 +170,7 @@ var findDefaultLayout = exports.findDefaultLayout = function(rootPath, filePath)
   if (arr.length > 2 && arr[1] == "json"){
     return null
   } else {
-    return findNearestLayout(rootPath, path.dirname(filePath))  
+    return findNearestLayout(rootPath, path.dirname(filePath))
   }
 }
 
@@ -528,11 +528,11 @@ exports.needsBrowserify = function(source) {
 
 /**
  * shouldApplyLayout
- * 
+ *
  * returns true if an HTML template engine does not include a partial/layout system and terraform should handle that
  */
- 
+
 exports.shouldApplyLayout = function(ext) {
-  var extsWithLayout = ["nunjucks"]
+  var extsWithLayout = ["nunjucks", "njk"]
   return (extsWithLayout.indexOf(ext) < 0)
-}
+}

+ 35 - 0
lib/template/processors/njk.js

@@ -0,0 +1,35 @@
+var nunjucks = require('nunjucks')
+var TerraformError = require("../../error").TerraformError
+var PartialTag = require('../../helpers/partial-nunjucks.js')
+
+module.exports = function(fileContents, options){
+
+  return {
+    compile: function(){
+      return function(locals) {
+        var env = nunjucks.configure(options.basedir)
+        
+        env.addExtension('LocalPartial', new PartialTag(locals))
+        
+        var template = nunjucks.compile(fileContents.toString(), env)
+        return template.render(locals)
+      }
+    },
+
+    parseError: function(error){
+      var arr = error.message.split("\n")
+      var path_arr = arr[0].split(":")
+
+      error.lineno   = parseInt(error.lineno || path_arr[path_arr.length -1] || -1)
+      error.message  = arr[arr.length - 1]
+      error.name     = error.name
+      error.source   = "NUNJUCKS"
+      error.dest     = "HTML"
+      error.filename = error.path || options.filename
+      error.stack    = fileContents.toString()
+
+      return new TerraformError(error)
+    }
+  }
+
+}

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "candlewax",
-  "version": "1.2.0",
+  "version": "1.3.0",
   "description": "pre-processor engine that powers the wick web server",
   "repository": {
     "type": "git",