mirror of
https://github.com/atom/atom.git
synced 2026-02-10 06:35:00 -05:00
Add template/Builder. It generates basic tags.
This commit is contained in:
25
src/stdlib/template/builder.coffee
Normal file
25
src/stdlib/template/builder.coffee
Normal file
@@ -0,0 +1,25 @@
|
||||
_ = require 'underscore'
|
||||
OpenTag = require 'template/open-tag'
|
||||
CloseTag = require 'template/close-tag'
|
||||
|
||||
module.exports =
|
||||
class Builder
|
||||
constructor: ->
|
||||
@reset()
|
||||
|
||||
toHtml: ->
|
||||
_.map(@document, (x) -> x.toHtml()).join('')
|
||||
|
||||
tag: (name) ->
|
||||
@openTag(name)
|
||||
@closeTag(name)
|
||||
|
||||
openTag: (name) ->
|
||||
@document.push(new OpenTag(name))
|
||||
|
||||
closeTag: (name) ->
|
||||
@document.push(new CloseTag(name))
|
||||
|
||||
reset: ->
|
||||
@document = []
|
||||
|
||||
7
src/stdlib/template/close-tag.coffee
Normal file
7
src/stdlib/template/close-tag.coffee
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports =
|
||||
class CloseTag
|
||||
constructor: (@name) ->
|
||||
|
||||
toHtml: ->
|
||||
"</#{@name}>"
|
||||
|
||||
7
src/stdlib/template/open-tag.coffee
Normal file
7
src/stdlib/template/open-tag.coffee
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports =
|
||||
class OpenTag
|
||||
constructor: (@name) ->
|
||||
|
||||
toHtml: ->
|
||||
"<#{@name}>"
|
||||
|
||||
Reference in New Issue
Block a user