mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Tags can take a function for their content.
This commit is contained in:
@@ -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>")
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user