Skip to content
Browse files

merge

  • Loading branch information...
2 parents 9eea2bc + 9d8082f commit 4333d37b06d9bde91e15f24a670bed66a54da6a0 @Filirom1 Filirom1 committed Oct 7, 2012
Showing with 17 additions and 9 deletions.
  1. +7 −0 example/underscore/templates/sample.with.dots.jst
  2. +8 −8 lib/index.js
  3. +2 −1 test/universalJstTest.js
View
7 example/underscore/templates/sample.with.dots.jst
@@ -0,0 +1,7 @@
+<h1><%= title %></h1>
+
+<% if (typeof foo !== 'undefined'){ %>
+ <% _.forEach(foo, function(value){ %>
+ <div><%= value %></div>
+ <% }); %>
+<% } %>
View
16 lib/index.js
@@ -1,10 +1,10 @@
/*jshint onevar: false*/
var fs = require('fs')
- , join = require('path').join
+ , path = require('path')
, glob = require("glob")
, _ = require("underscore")
, async = require('async')
- , ENGINES = join(__dirname, './engines/');
+ , ENGINES = path.join(__dirname, './engines/');
var defaults = exports.defaults = {
namespace: 'window.JST',
@@ -22,7 +22,7 @@ var handleError = exports.handleError = function( err, data ){
fs.readdirSync(ENGINES).forEach(function(file){
if(!/\.js$/.test(file)) return;
var engineName = file.replace('.js', '')
- , compiler = require(join(ENGINES, engineName));
+ , compiler = require(path.join(ENGINES, engineName));
// exports each engine.
exports[engineName] = build;
@@ -74,20 +74,20 @@ fs.readdirSync(ENGINES).forEach(function(file){
// Read each file, compile them, and append the result in the `compiledTemplates array`
function readFile(file, cb){
- var path = join(inputdir, file);
- fs.stat(path, function(err, stat){
+ var file = path.normalize(file)
+ , fpath = path.join(inputdir, file);
+ fs.stat(fpath, function(err, stat){
if(err) { handleError(err); return cb(); }
if(!stat.isFile()) {
if( options.verbose ) { handleError('Skip ' + file); }
return cb();
}
- fs.readFile(path, 'utf8', function(err, text){
+ fs.readFile(fpath, 'utf8', function(err, text){
if(err) { handleError(err); return cb() }
var subs = subTemplate( text )
- , nm = join(file).split('.')[0]
- .replace(/\\/g, '/'); // windows users should have the same JST key.
+ , nm = path.join(path.dirname(file), path.basename(file, path.extname(file))).replace(/\\/g, '/'); // windows users should have the same JST key.
if( options.verbose ) console.log('Building ' + options.namespace + '["' + nm + '"]');
if( subs ){
View
3 test/universalJstTest.js
@@ -40,13 +40,14 @@ vows.describe('Test universal JST').addBatch({
engines.underscore(example('underscore'), this.callback)
},
'Then an array is returned': function(arr){
- assert.equal(arr.length, 8);
+ assert.equal(arr.length, 9);
},
'Then the templates are valid': function(arr){
var str = arr.join('\n');
var window = {};
vm.runInNewContext(str, { window: window, _: _ });
assert.include(window.JST.sample({ title: 'hello', foo: [1,2,3] }), '<div>1</div>');
+ assert.include(window.JST["sample.with.dots"]({ title: 'hello', foo: [1,2,3] }), '<div>1</div>');
assert.include(window.JST.multiple({ title: 'hello' }), '<h1>hello</h1>');
assert.include(window.JST.multiple_header({ title: 'hello'}), '<h1>hello</h1>');
assert.include(window.JST.multiple_footer({ title: 'hello'}), '<h1>hello</h1>');

0 comments on commit 4333d37

Please sign in to comment.
Something went wrong with that request. Please try again.