Skip to content

Commit

Permalink
allow functions to be passed to the internal render method
Browse files Browse the repository at this point in the history
  • Loading branch information
smtlaissezfaire committed May 5, 2010
1 parent feae0fb commit 2f6c435
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/jm.js
Expand Up @@ -294,9 +294,16 @@ jm.Builder.prototype = (function() {
};
});

builder.render = function(name, locals) {
var template_name = jm.templates[name];
this.text(jm.render(template_name, locals));
builder.render = function(name_or_code, locals) {
var template;

if (isString(name_or_code)) {
template = jm.templates[name_or_code];
} else {
template = name_or_code;
}

this.text(jm.render(template, locals));
};

builder.toHTML = function() {
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/spec.js
Expand Up @@ -227,6 +227,18 @@ describe("JM", function() {
result.should.equal("<p></p>");
});

it("should be able to render a partial which hasn't been previously registered", function() {
var a_partial = function(b) {
b.p();
};

var result = JM.render(function(b) {
b.render(a_partial);
});

result.should.equal("<p></p>");
});

it('should be able to pass locals to the partial', function() {
JM.register("a_partial", function(b, args) {
b.text(args.name);
Expand Down

0 comments on commit 2f6c435

Please sign in to comment.