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))