Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add bin/jst

  • Loading branch information...
commit 02c9df7b9f681a0c4d44da7d56fb33b571757823 1 parent 081f915
@guileen authored
Showing with 29 additions and 6 deletions.
  1. +17 −0 bin/jst
  2. +8 −5 lib/jst.js
  3. +4 −1 package.json
View
17 bin/jst
@@ -0,0 +1,17 @@
+#!/usr/bin/env node
+
+var program = require('commander')
+ , fs = require('fs')
+ , jst = require('../index')
+
+program
+ .version(jst.version)
+ .parse(process.argv);
+
+var filenames = program.args;
+
+filenames.forEach(function(filename){
+ var template = fs.readFileSync(filename, 'utf8')
+
+ console.log(jst.compile(template, true));
+})
View
13 lib/jst.js
@@ -42,7 +42,7 @@ const prefixes = {
},
codere = /\{[%\{] (.+?) [%\}]\}/g;
-var compile = exports.compile = function(ctx) {
+var compile = exports.compile = function(ctx, isToCode) {
var m, i = 0, code = 'var out = ', last = 'n';
_options.useIt = /{{ (e\()?it\./.test(ctx);
@@ -83,12 +83,15 @@ var compile = exports.compile = function(ctx) {
code += '} ';
code += 'return out;';
- //console.log(code);
- var fn = new Function('it, filters', code);
+ if(isToCode) {
+ return 'function(it) { var filters = jst.filters;' + code + '}';
+ } else {
+ var fn = new Function('it, filters', code);
- return function(args) {
- return fn.call(this, args, filters.filters);
+ return function(args) {
+ return fn.call(this, args, filters.filters);
+ }
}
}
View
5 package.json
@@ -5,5 +5,8 @@
"author": "Shaun Li <shonhen@gmail.com>",
"keywords": ["template", "engine", "jst"],
"main": "./lib/jst.js",
- "dependencies": {"locales": ">0.0.1"}
+ "dependencies": {
+ "locales": ">0.0.1"
+ , "commander": ">0.0.1"
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.