+21
| MIT License | ||
| Copyright (c) 2017 zswang | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
| var handlebars = require('handlebars'); | ||
| /** | ||
| * handlebars 模板渲染 | ||
| * | ||
| * @param {string} content 文本内容 | ||
| * @param {Object} attrs 属性 | ||
| * @param {string} attrs.data 数据项 | ||
| * @param {Object} scope 作用域 | ||
| * @param {Function} scope.execImport 导入数据 | ||
| */ | ||
| module.exports = function processor(content, attrs, scope) { | ||
| if (!content) { | ||
| return content; | ||
| } | ||
| var render = handlebars.compile(content); | ||
| var data; | ||
| if (attrs.data) { | ||
| /*jslint evil: true */ | ||
| data = scope.execImport(attrs.data); | ||
| if (typeof data === 'string') { | ||
| data = new Function( | ||
| 'return (' + data + ');' | ||
| )(); | ||
| } | ||
| } | ||
| else { | ||
| data = null; | ||
| } | ||
| return render(data); | ||
| }; |
| /** | ||
| * @see http://nginx.org/en/docs/http/ngx_http_ssi_module.html | ||
| */ | ||
| var path = require('path'); | ||
| var fs = require('fs'); | ||
| module.exports = function processor(content, attrs, scope) { | ||
| if (!content) { | ||
| return content; | ||
| } | ||
| return content.replace(/<!--#include\s+file="([^"]*)"-->/g, function (all, filename) { | ||
| return fs.readFileSync(path.join(scope.getDirname(), filename)); | ||
| }); | ||
| }; |
+2
-2
@@ -7,4 +7,4 @@ /** | ||
| * zswang (http://weibo.com/zswang) | ||
| * @version 2.0.17 | ||
| * @date 2017-05-03 | ||
| * @version 2.1.7 | ||
| * @date 2017-07-31 | ||
| */ | ||
@@ -11,0 +11,0 @@ var fs = require('fs'); |
+2
-2
@@ -7,4 +7,4 @@ /** | ||
| * zswang (http://weibo.com/zswang) | ||
| * @version 2.0.17 | ||
| * @date 2017-05-03 | ||
| * @version 2.1.7 | ||
| * @date 2017-07-31 | ||
| */ | ||
@@ -11,0 +11,0 @@ var colors = require('colors'); |
+4
-3
| { | ||
| "name": "jdists", | ||
| "version": "2.0.17", | ||
| "version": "2.1.7", | ||
| "description": "Code block processing tools", | ||
@@ -31,5 +31,7 @@ "main": "lib/jdists.js", | ||
| "clean-css": "^3.4.19", | ||
| "handlebars": "^4.0.10", | ||
| "istanbul": "0.3.17", | ||
| "jade": "^1.11.0", | ||
| "jdists": "2.0.0", | ||
| "jdists": "2.0.17", | ||
| "jfogs": "^0.0.15", | ||
| "js-yaml": "^3.6.1", | ||
@@ -44,3 +46,2 @@ "jshint": "2.8.0", | ||
| "svgo": "^0.7.0", | ||
| "jfogs": "^0.0.15", | ||
| "uglify-js": "^2.7.3" | ||
@@ -47,0 +48,0 @@ }, |
77407
2.9%53
6%2107
1.98%18
5.88%7
16.67%14
7.69%