Permalink
Browse files

增加norender标签,用此标签引用的文件不会经过任何渲染直接输出到客户端,可用于前后端都使用mustache的场景。

  • Loading branch information...
1 parent 6482bc9 commit 6e2a8ee27221a23b12c7aaeb8afac512e7c8d0a8 @xinyu198736 committed Dec 13, 2012
Showing with 20 additions and 13 deletions.
  1. +4 −1 README.md
  2. +16 −12 lib/index.js
View
@@ -1,8 +1,10 @@
mustache-node-plus
==================
-为express中间件封装了一下,最重要是添加了模板嵌套特性
+为为express中间件封装了一下,最重要是添加了模板嵌套特性,norender标签,和常用格式化方法
+ * 2012-12-13 增加norender标签,用此标签引用的文件不会经过任何渲染直接输出到客户端,可用于前后端都使用mustache的场景。
+ * todo 常用格式化方法
###install
```
@@ -26,6 +28,7 @@ template:
{include tpl="store/header.html"} <!-- relative path -->
<div id="content">
</div>
+ {norender tpl="store/item.html"} <!-- 里面的内容不会被渲染 -->
{include tpl="store/footer.html"}
</body>
```
View
@@ -1,20 +1,24 @@
var mustache = require("mustache");
-var fs = require("fs");
-var readFile = function (path) {
- var content = fs.readFileSync(path, "utf-8");
- return content.replace(/{include tpl="(.*?)"}/g, function (match, path) {
- return readFile(_mustache.prefix + path);
- });
-};
-var mustachePlus = function(path, options, fn) {
+var fs=require("fs");
+var readFile=function(path){
+ var content=fs.readFileSync(path,"utf-8");
+ return content.replace(/{include tpl="(.*?)"}/g,function(match,path){
+ return readFile(_mustache.prefix+path)
+ })
+}
+var _mustache = function(path, options, fn) {
+ var str=readFile(path);
try {
- var str=readFile(path);
if(str)
options.filename = path;
- fn(null, mustache.to_html(str, options));
+ var result=mustache.to_html(str, options)
+ result=result.replace(/{norender tpl="(.*?)"}/g,function(match,path){
+ return fs.readFileSync(_mustache.prefix+path,"utf-8")
+ })
+ fn(null, result);
} catch (err) {
fn(err);
}
};
-_mustache.prefix = "/";
-module.exports = mustachePlus;
+_mustache.prefix="/"
+module.exports=_mustache;

0 comments on commit 6e2a8ee

Please sign in to comment.