From e570c5d4541cef2d279fc7a7d27253e0bf2df52e Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 27 Dec 2011 15:57:29 -0600 Subject: [PATCH] Tags can take a function for their content. --- spec/stdlib/template/builder-spec.coffee | 6 ++++++ src/stdlib/template/builder.coffee | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/stdlib/template/builder-spec.coffee b/spec/stdlib/template/builder-spec.coffee index 4d552cd2c..28f1da96c 100644 --- a/spec/stdlib/template/builder-spec.coffee +++ b/spec/stdlib/template/builder-spec.coffee @@ -14,3 +14,9 @@ fdescribe "Builder", -> builder.tag 'ol' expect(builder.toHtml()).toBe("
    ") + it "can generate tags with content", -> + builder.tag 'ol', -> + builder.tag 'li' + builder.tag 'li' + + expect(builder.toHtml()).toBe("
    ") diff --git a/src/stdlib/template/builder.coffee b/src/stdlib/template/builder.coffee index ce3b7964c..41b6807cf 100644 --- a/src/stdlib/template/builder.coffee +++ b/src/stdlib/template/builder.coffee @@ -10,10 +10,18 @@ class Builder toHtml: -> _.map(@document, (x) -> x.toHtml()).join('') - tag: (name) -> + tag: (name, args...) -> + options = @extractOptions(args) @openTag(name) + options.content?() @closeTag(name) + extractOptions: (args) -> + options = {} + for arg in args + options.content = arg if _.isFunction(arg) + options + openTag: (name) -> @document.push(new OpenTag(name))