mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
Tags can take textual content.
This commit is contained in:
parent
e570c5d454
commit
b5a06c288e
@ -20,3 +20,12 @@ fdescribe "Builder", ->
|
||||
builder.tag 'li'
|
||||
|
||||
expect(builder.toHtml()).toBe("<ol><li></li><li></li></ol>")
|
||||
|
||||
it "can generate tags with text", ->
|
||||
builder.tag 'div', "hello"
|
||||
expect(builder.toHtml()).toBe("<div>hello</div>")
|
||||
|
||||
builder.reset()
|
||||
builder.tag 'div', 22
|
||||
expect(builder.toHtml()).toBe("<div>22</div>")
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
_ = require 'underscore'
|
||||
OpenTag = require 'template/open-tag'
|
||||
CloseTag = require 'template/close-tag'
|
||||
Text = require 'template/text'
|
||||
|
||||
module.exports =
|
||||
class Builder
|
||||
@ -14,12 +15,15 @@ class Builder
|
||||
options = @extractOptions(args)
|
||||
@openTag(name)
|
||||
options.content?()
|
||||
@text(options.text) if options.text
|
||||
@closeTag(name)
|
||||
|
||||
extractOptions: (args) ->
|
||||
options = {}
|
||||
for arg in args
|
||||
options.content = arg if _.isFunction(arg)
|
||||
options.text = arg if _.isString(arg)
|
||||
options.text = arg.toString() if _.isNumber(arg)
|
||||
options
|
||||
|
||||
openTag: (name) ->
|
||||
@ -28,6 +32,9 @@ class Builder
|
||||
closeTag: (name) ->
|
||||
@document.push(new CloseTag(name))
|
||||
|
||||
text: (string) ->
|
||||
@document.push(new Text(string))
|
||||
|
||||
reset: ->
|
||||
@document = []
|
||||
|
||||
|
6
src/stdlib/template/text.coffee
Normal file
6
src/stdlib/template/text.coffee
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports =
|
||||
class Text
|
||||
constructor: (@string) ->
|
||||
|
||||
toHtml: -> @string
|
||||
|
Loading…
Reference in New Issue
Block a user