Skip to content

Commit

Permalink
Updating the main API to support rendering a completed template from …
Browse files Browse the repository at this point in the history
…a template engine during the pre-Render call
  • Loading branch information
ifandelse committed Oct 28, 2011
1 parent 0f437a2 commit e212f84
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
7 changes: 5 additions & 2 deletions examples/shorthand/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ $(function(){
"Example",
$("#targetFancy"),
{
preRender: function(target) { $(target).children().remove().end().fadeOut().hide(); },
render: function(target, template) { $(target).append($.tmpl(template, model)).slideDown('slow'); },
preRender: function(target, template, setTemplate) {
$(target).children().remove().end().fadeOut().hide();
setTemplate($.tmpl(template, model));
},
render: function(target, template) { $(target).append(template).slideDown('slow'); },
postRender: toggleFancy
}
);
Expand Down
2 changes: 1 addition & 1 deletion examples/trafficcop/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>jQuery-tmpl Example</title>
<title>Traffic Cop Example</title>
<script type="text/javascript" src="../../ext/jquery-1.5.2.js"></script>
<script type="text/javascript" src="../../lib/infuser.js"></script>
<script type="text/javascript" src="jquery.tmpl.js"></script>
Expand Down
7 changes: 5 additions & 2 deletions examples/trafficcop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ var toggled = false,
"Example",
$("#target"),
{
render: function(target, template) {
$(target).append($.tmpl(template, menus[modelNum])).slideDown('slow');
preRender: function(target, template, setTemplate) {
setTemplate($.tmpl(template, menus[modelNum]));
},
render: function(target, template) {
$(target).append(template).slideDown('slow');
}
}
);
Expand Down
5 changes: 3 additions & 2 deletions lib/infuser.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ var infuser = {
infuse: function(templateId, targetDomElement, renderOptions) {
var options = $.extend({}, defaultRenderOptions, renderOptions);
this.get(templateId, function(template) {
options.preRender(targetDomElement);
options.render(targetDomElement, template);
var _template = template;
options.preRender(targetDomElement, _template, function(renderedTemplate) { _template = renderedTemplate; });
options.render(targetDomElement, _template);
options.postRender(targetDomElement);
});
}
Expand Down
Binary file modified lib/infuser.min.gz.js
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/infuser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ var infuser = {
infuse: function(templateId, targetDomElement, renderOptions) {
var options = $.extend({}, defaultRenderOptions, renderOptions);
this.get(templateId, function(template) {
options.preRender(targetDomElement);
options.render(targetDomElement, template);
var _template = template;
options.preRender(targetDomElement, _template, function(renderedTemplate) { _template = renderedTemplate; });
options.render(targetDomElement, _template);
options.postRender(targetDomElement);
});
}
Expand Down

0 comments on commit e212f84

Please sign in to comment.