Tags can take a function for their content.

This commit is contained in:
Nathan Sobo
2011-12-27 15:57:29 -06:00
parent 22167faf28
commit e570c5d454
2 changed files with 15 additions and 1 deletions

View File

@@ -14,3 +14,9 @@ fdescribe "Builder", ->
builder.tag 'ol'
expect(builder.toHtml()).toBe("<ol></ol>")
it "can generate tags with content", ->
builder.tag 'ol', ->
builder.tag 'li'
builder.tag 'li'
expect(builder.toHtml()).toBe("<ol><li></li><li></li></ol>")

View File

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