Merge branch 'master' into editor

This commit is contained in:
Danny Greg & Nathan Sobo
2012-01-19 18:54:34 -08:00
2 changed files with 50 additions and 1 deletions

View File

@@ -6,6 +6,11 @@ Text = require 'template/text'
module.exports =
class Builder
@render: (fn) ->
builder = new this
fn.call(builder)
builder.toFragment()
@elements:
normal: 'a abbr address article aside audio b bdi bdo blockquote body button
canvas caption cite code colgroup datalist dd del details dfn div dl dt em
@@ -18,6 +23,25 @@ class Builder
void: 'area base br col command embed hr img input keygen link meta param
source track wbr'.split /\s+/
@allElements: ->
@elements.normal.concat(@elements.void)
@buildTagClassMethod: (tagName) ->
this[tagName] = (args...) ->
@render ->
argsWithBoundFunctions = args.map (arg) =>
if _.isFunction(arg)
_.bind(arg, this)
else
arg
@tag(tagName, argsWithBoundFunctions...)
@buildTagInstanceMethod: (tagName) ->
@prototype[tagName] = (args...) -> @tag(tagName, args...)
@allElements().forEach (tagName) => @buildTagClassMethod(tagName)
@allElements().forEach (tagName) => @buildTagInstanceMethod(tagName)
constructor: ->
@reset()
@@ -37,7 +61,7 @@ class Builder
@document.push(new OpenTag(name, options.attributes))
if @elementIsVoid(name)
if (options.text? or options.content?)
throw new Error("Self-closing tag #{tag} cannot have text or content")
throw new Error("Self-closing tag #{name} cannot have text or content")
else
options.content?()
@text(options.text) if options.text