Skip to content

Commit

Permalink
Removing JsRender integration (it appears that JsRender itself is no …
Browse files Browse the repository at this point in the history
…longer backward compatible with jquery-tmpl)
  • Loading branch information
SteveSanderson committed Nov 17, 2011
1 parent e20cc9e commit 63d53d4
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions src/templating/jquery.tmpl/jqueryTmplTemplateEngine.js
Expand Up @@ -5,13 +5,10 @@
// Note that as of Knockout 1.3, we only support jQuery.tmpl 1.0.0pre and later,
// which KO internally refers to as version "2", so older versions are no longer detected.
var jQueryTmplVersion = this.jQueryTmplVersion = (function() {
if ((typeof(jQuery) == "undefined") || !(jQuery['tmpl']|| jQuery['render']))
if ((typeof(jQuery) == "undefined") || !(jQuery['tmpl']))
return 0;
// Since it exposes no official version number, we use our own numbering system. To be updated as jquery-tmpl evolves.
try {
if (jQuery['render'])
return 3; // Current preview of jsRender

if (jQuery['tmpl']['tag']['tmpl']['open'].toString().indexOf('__') >= 0) {
// Since 1.0.0pre, custom tags should append markup to an array called "__"
return 2; // Final version of jquery.tmpl
Expand All @@ -27,11 +24,7 @@
}

function executeTemplate(compiledTemplate, data, jQueryTemplateOptions) {
if (jQueryTmplVersion < 3)
return jQuery['tmpl'](compiledTemplate, data, jQueryTemplateOptions);

var renderedHtml = jQuery['render'](compiledTemplate, data, jQueryTemplateOptions);
return jQuery(ko.utils.parseHtmlFragment(renderedHtml));
return jQuery['tmpl'](compiledTemplate, data, jQueryTemplateOptions);
}

this['renderTemplateSource'] = function(templateSource, bindingContext, options) {
Expand All @@ -43,8 +36,7 @@
if (!precompiled) {
var templateText = templateSource.text() || "";
// Wrap in "with($whatever.koBindingContext) { ... }"
var contextContainer = jQueryTmplVersion == 2 ? "$item" : "$ctx";
templateText = "{{ko_with " + contextContainer + ".koBindingContext}}" + templateText + "{{/ko_with}}";
templateText = "{{ko_with $item.koBindingContext}}" + templateText + "{{/ko_with}}";

precompiled = jQuery['template'](null, templateText);
templateSource['data']('precompiled', precompiled);
Expand All @@ -67,16 +59,13 @@
document.write("<script type='text/html' id='" + templateName + "'>" + templateMarkup + "</script>");
};

if (jQueryTmplVersion >= 2) {
var tagContainer = jQueryTmplVersion == 2 ? "tmpl" : "tmplSettings";
jQuery[tagContainer]['tag']['ko_code'] = {
open: "__.push($1 || '');"
};
jQuery[tagContainer]['tag']['ko_with'] = {
open: "with($1) {",
close: "} "
};
}
jQuery['tmpl']['tag']['ko_code'] = {
open: "__.push($1 || '');"
};
jQuery['tmpl']['tag']['ko_with'] = {
open: "with($1) {",
close: "} "
};
};

ko.jqueryTmplTemplateEngine.prototype = new ko.templateEngine();
Expand Down

0 comments on commit 63d53d4

Please sign in to comment.