Permalink
Browse files

add 0.1.0 release to npm, name is "tenjin"

  • Loading branch information...
1 parent bb459d0 commit 6b8347ed3042409fd2475038c52842e67a35322c @fengmk2 fengmk2 committed Apr 30, 2011
Showing with 75 additions and 14 deletions.
  1. +2 −0 .gitignore
  2. +0 −6 README
  3. +17 −6 README.md
  4. +2 −0 index.js
  5. +17 −2 nTenjin.js
  6. +20 −0 package.json
  7. +17 −0 test/tenjin.test.js
View
@@ -0,0 +1,2 @@
+.project
+.settings
View
@@ -1,6 +0,0 @@
-#What is this?
-基于jsTenjin修改的高性能的支持node.js的模板解析引擎
-
-#Change from jsTenjin
-jsTenjin是使用`eval`来解析的,而nTenjin是使用 `new Function` 来解析的。速度主要差别在这里。
-nTenjin中变量必须由`it`来指定,例如`#{param}`要修改为`#{it.param}`,其他和jsTenjin完全一致。
View
@@ -1,20 +1,31 @@
-#What is this?
+## What is this?
+
基于[jsTenjin](http://www.kuwata-lab.com/tenjin/jstenjin-users-guide.html)修改的高性能的支持node.js的模板解析引擎
(A template engine base on [jsTenjin's](http://www.kuwata-lab.com/tenjin/jstenjin-users-guide.html) and more fase and support node.js )
-#Change from jsTenjin
+## Change from jsTenjin
+
+ jsTenjin是使用`eval`来解析的,而nTenjin是使用 `new Function` 来解析的(速度差别之一)。
+ jsTenjin是使用`Array.push`来构造字符串的,而nTenjin是使用 `String += str` 来构造字符串的(速度差别之二)。
+ nTenjin中变量必须由`it`来指定,例如`#{param}`要修改为`#{it.param}`,其他和jsTenjin完全一致。
-#Benchmarks
+## Benchmarks
+
at [here](http://jsperf.com/dom-vs-innerhtml-based-templating/142)
-#User's Guide
+## Install
+
+ $ sudo npm install tenjin
+
+## User's Guide
- var d = {name:'nTenjin'};
- nTenjin.render('Hello #{it.name}!', d);
+ var tenjin = require('tenjin');
+ tenjin.render('Hello #{it.name}!', {name:'nTenjin'});
note that the `it`
more detail at [jsTenjin User's Guide](http://www.kuwata-lab.com/tenjin/jstenjin-users-guide.html)
+
+## Use in express
+
+ app.register(".html", require('tenjin'));
View
@@ -0,0 +1,2 @@
+
+module.exports = require('../nTenjin');
View
@@ -10,10 +10,12 @@
*/
var nTenjin = {
-
+
+ version: '0.1.0',
+
_escape_table: { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' },
- _escape_func: function(m) { return nTenjin._escape_table[m] },
+ _escape_func: function(m) { return nTenjin._escape_table[m]; },
escapeXml: function(s) {
//if (s == null) return '';
@@ -135,6 +137,19 @@ nTenjin.render = function(template_str, context) {
return output;
};
+/**
+ * compile str to Function
+ *
+ * @param {String} str, template string
+ * @return {Function}
+ * @api public
+ */
+
+nTenjin.compile = function(str, options) {
+ var tpl = new nTenjin.Template();
+ return tpl.convert(str);
+};
+
/*
* node.js
*/
View
@@ -0,0 +1,20 @@
+{
+ "name": "tenjin",
+ "description": "A high performance template engine base on node.js.",
+ "version": "0.1.0",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/QLeelulu/nTenjin.git"
+ },
+ "author": "QLeelulu <qleelulu@gmail.com> (http://qleelulu.cnblogs.com/)",
+ "contributors": [
+ { "name": "fengmk2", "email": "fengmk2@gmail.com" }
+ ],
+ "main": "index.js",
+ "scripts": {
+ "test": "expresso test"
+ },
+ "engines": {
+ "node": "*"
+ }
+}
View
@@ -0,0 +1,17 @@
+/**
+ * Module dependencies.
+ */
+
+var tenjin = require('../nTenjin')
+ , assert = require('assert');
+
+module.exports = {
+ 'compile': function() {
+ var tpl = '<a href="#{it.url}">${it.title}</a>';
+ var fn = tenjin.compile(tpl, {debug: true});
+ assert.equal(typeof fn, 'function');
+ var html = fn({'url': 'urltest<>', 'title':'sdfsdfl <>!@#?#!@# &'});
+ assert.equal(html, '<a href="urltest<>">sdfsdfl &lt;&gt;!@#?#!@# &amp;</a>');
+ }
+};
+

0 comments on commit 6b8347e

Please sign in to comment.