Skip to content
Browse files

Removed nested dtd object from create

  • Loading branch information...
1 parent ca68f1d commit 80c45e86f46cf9ef15b8f85354529cb79ca7312d @oozcitak committed Dec 22, 2013
Showing with 28 additions and 54 deletions.
  1. +6 −7 src/XMLBuilder.coffee
  2. +12 −14 src/XMLDocType.coffee
  3. +5 −6 src/XMLNode.coffee
  4. +2 −2 src/XMLStringifier.coffee
  5. +3 −25 test/doctype.coffee
View
13 src/XMLBuilder.coffee
@@ -18,9 +18,8 @@ module.exports = class XMLBuilder
# `options.encoding` Encoding declaration, e.g. UTF-8
# `options.standalone` standalone document declaration: true or false
#
- # `options.dtd` document type declaration with optional external subset
- # `options.dtd.pubID` the public identifier of the external subset
- # `options.dtd.sysID` the system identifier of the external subset
+ # `options.pubID` public identifier of the external subset
+ # `options.sysID` system identifier of the external subset
#
# `options.headless` whether XML declaration and doctype will be included: true or false
# `options.allowSurrogateChars` whether surrogates will be allowed: true or false
@@ -32,17 +31,17 @@ module.exports = class XMLBuilder
options ?= {}
# support legacy ext attribute
- if options.ext and not options.dtd
- options.dtd = options.ext
+ if options.ext and not options.sysID
+ options.sysID = options.ext
@stringify = new XMLStringifier options
# prolog
if not options.headless
@xmldec = new XMLDeclaration @, options
- if options.dtd?
- @doctype = new XMLDocType @, options.dtd
+ if options.pubID? or options.sysID?
+ @doctype = new XMLDocType @, options.pubID, options.sysID
root = new XMLElement @, 'doc'
root = root.element name
View
26 src/XMLDocType.coffee
@@ -8,21 +8,19 @@ module.exports = class XMLDocType
#
# `parent` the document object
#
- # `dtd` document type declaration with optional external subset
- # `dtd.pubID` the public identifier of the external subset
- # `dtd.sysID` the system identifier of the external subset
- constructor: (@parent, dtd) ->
- @stringify = @parent.stringify
+ # `pubID` public identifier of the external subset
+ # `sysID` system identifier of the external subset
+ constructor: (parent, pubID, sysID) ->
+ @documentObject = parent
+ @stringify = @documentObject.stringify
@children = []
- if not _.isObject dtd
- sysID = dtd
- dtd = {}
- dtd.sysID = sysID if sysID
+ if not sysID?
+ [sysID, pubID] = [pubID, sysID]
- @pubID = @stringify.xmlPubID dtd.pubID if dtd.pubID?
- @sysID = @stringify.xmlSysID dtd.sysID if dtd.sysID?
+ @pubID = @stringify.dtdPubID pubID if pubID?
+ @sysID = @stringify.dtdSysID sysID if sysID?
# Creates an element type declaration
@@ -54,12 +52,12 @@ module.exports = class XMLDocType
# Gets the root node
root: () ->
- @parent.root()
+ @documentObject.root()
# Gets the node representing the XML document
document: () ->
- return @parent
+ return @documentObject
# Converts to string
@@ -80,7 +78,7 @@ module.exports = class XMLDocType
r += space if pretty
# open tag
- r += '<!DOCTYPE ' + @parent.root().name
+ r += '<!DOCTYPE ' + @root().name
# external identifier
if @pubID and @sysID
View
11 src/XMLNode.coffee
@@ -195,12 +195,11 @@ module.exports = class XMLNode
# Creates the document type declaration
#
- # `dtd` document type declaration with optional external subset
- # `dtd.pubID` the public identifier of the external subset
- # `dtd.sysID` the system identifier of the external subset
- doctype: (dtd) ->
+ # `pubID` the public identifier of the external subset
+ # `sysID` the system identifier of the external subset
+ doctype: (pubID, sysID) ->
XMLDocType = require './XMLDocType'
- doctype = new XMLDocType @, dtd
+ doctype = new XMLDocType @, pubID, sysID
@document().doctype = doctype
return doctype
@@ -278,7 +277,7 @@ module.exports = class XMLNode
dat: (value) -> @cdata value
com: (value) -> @comment value
doc: () -> @document()
- dtd: (value) -> @doctype value
+ dtd: (pubID, sysID) -> @doctype pubID, sysID
e: (name, attributes, text) -> @element name, attributes, text
n: (name, attributes, text) -> @node name, attributes, text
t: (value) -> @text value
View
4 src/XMLStringifier.coffee
@@ -54,9 +54,9 @@ module.exports = class XMLStringifier
val
xmlStandalone: (val) ->
if val then "yes" else "no"
- xmlPubID: (val) ->
+ dtdPubID: (val) ->
'' + val or ''
- xmlSysID: (val) ->
+ dtdSysID: (val) ->
'' + val or ''
dtdElementValue: (val) ->
'' + val or ''
View
28 test/doctype.coffee
@@ -8,18 +8,7 @@ vows
.addBatch
'SYSTEM dtd from create()':
topic: () ->
- xmlbuilder.create('root', { dtd: { sysID: 'hello.dtd' }})
- .ele('node').txt('test')
-
- 'resulting XML': (topic) ->
- xml = '<?xml version="1.0"?>' +
- '<!DOCTYPE root SYSTEM "hello.dtd">' +
- '<root><node>test</node></root>'
- assert.strictEqual topic.end(), xml
-
- 'SYSTEM dtd from create() with dtd as string':
- topic: () ->
- xmlbuilder.create('root', { dtd: 'hello.dtd' })
+ xmlbuilder.create('root', { sysID: 'hello.dtd' })
.ele('node').txt('test')
'resulting XML': (topic) ->
@@ -30,18 +19,7 @@ vows
'Empty dtd from create()':
topic: () ->
- xmlbuilder.create('root', { dtd: {} })
- .ele('node').txt('test')
-
- 'resulting XML': (topic) ->
- xml = '<?xml version="1.0"?>' +
- '<!DOCTYPE root>' +
- '<root><node>test</node></root>'
- assert.strictEqual topic.end(), xml
-
- 'Empty dtd from create() with dtd as string':
- topic: () ->
- xmlbuilder.create('root', { dtd: '' })
+ xmlbuilder.create('root', { sysID: '' })
.ele('node').txt('test')
'resulting XML': (topic) ->
@@ -64,7 +42,7 @@ vows
'Internal and external dtd':
topic: () ->
xmlbuilder.create('root')
- .dtd({ sysID: 'hello.dtd' })
+ .dtd('hello.dtd')
.ele('img', 'EMPTY')
.att('img', 'height', 'CDATA', '#REQUIRED')
.att('img', 'visible', '(yes|no)', '#DEFAULT', "yes")

0 comments on commit 80c45e8

Please sign in to comment.
Something went wrong with that request. Please try again.