Permalink
Browse files

fix build

  • Loading branch information...
1 parent 7fa6289 commit 60d8ef041985adf60d9fb7605e56ce432d99d14b @iamnoah committed Oct 17, 2011
Showing with 38 additions and 4 deletions.
  1. +16 −4 mustache.js
  2. +22 −0 test/qunit/mustache_test.js
View
@@ -1,9 +1,20 @@
-steal.plugins('jquery/view')
+steal.plugins('jquery/view','jquery/lang/json')
.then("./handlebars")
.then(function($) {
Handlebars.TemplateCache = {};
+ var replaceChar = steal.cleanId('/');
+
+ steal.build.types['text/mustache'] = function(script,loadScriptText) {
+ var text = script.text || loadScriptText(script.src),
+ id = script.id || script.getAttribute("id");
+ // there is a bug in steal when building on windows that causes it to
+ // put backslashes in there
+ id = id.replace(/\\/g,replaceChar);
+ return jQuery.View.registerScript("mustache", id, text);
+ };
+
$.View.register({
suffix: "mustache",
@@ -13,7 +24,7 @@ steal.plugins('jquery/view')
return function(data, helpers){
// a jquerymx view 'helper' is not the same thing as a handlebars 'helper' - can we proxy?
return Handlebars.TemplateCache[id](data);
- }
+ };
},
get: function(id, url){
@@ -27,9 +38,10 @@ steal.plugins('jquery/view')
}).responseText;
return this.renderer(id, text);
},
-
script: function(id, str){
- return "((function(){ Handlebars.TemplateCache["+id+"] = Handlebars.compile("+str+"); return function(data){return Mustache.TemplateCache[id](data)} })())";
+ return "((function(){ Handlebars.TemplateCache['"+id+"'] = Handlebars.compile("+
+ $.quoteString(str) +
+ "); return function(data){return Handlebars.TemplateCache['"+id+"'](data)} })())";
}
});
@@ -73,3 +73,25 @@ test("Ensure hookup model works",function() {
$('.model').remove();
});
+test("Ensure build works",function() {
+ function strip(str) {
+ return str.replace(/[\s\r\n]+/g,'');
+ }
+ var template = '<h1>{{header}}</h1>\
+<ul>\
+{{#item}}\
+<li><strong>{{name}}</strong></li>\
+{{/item}}\
+</ul>',
+ correctOutput = "<h1>Colors</h1>\
+<ul>\
+<li><strong>red</strong></li>\
+<li><strong>green</strong></li>\
+<li><strong>blue</strong></li>\
+</ul>";
+
+ eval(steal.build.types['text/mustache']({text:template,id:'test\\qunit\\like\\complex_mustache'}));
+ ok(Handlebars.TemplateCache['test_qunit_like_complex_mustache'],'template registered');
+ var testOutput = $.View("//test/qunit/like/complex.mustache", this.complexData);
+ equals(strip(correctOutput), strip(testOutput));
+});

0 comments on commit 60d8ef0

Please sign in to comment.