starting to refine the Replaceable type. Most types should be a replaceable.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
###
|
||||
|
||||
json_types_uninitialized = require "./JsonTypes"
|
||||
|
||||
# some dom implementations may call another dom.method that simulates the behavior of another.
|
||||
@@ -364,4 +364,3 @@ module.exports = (HB)->
|
||||
types['XmlType'] = XmlType
|
||||
|
||||
json_types
|
||||
###
|
||||
65
lib/Types/Xml.coffee
Normal file
65
lib/Types/Xml.coffee
Normal file
@@ -0,0 +1,65 @@
|
||||
class YXml
|
||||
|
||||
constructor: (tagname, attributes = {}, children = [], classes = {})->
|
||||
@_xml = {}
|
||||
if not tagname?
|
||||
throw new Error "You must specify a tagname"
|
||||
@_xml.tagname = tagname
|
||||
if attributes.constructor isnt Object
|
||||
throw new Error "The attributes must be specified as a Object"
|
||||
for a_name, a of attributes
|
||||
if a.constructor isnt String
|
||||
throw new Error "The attributes must be of type String!"
|
||||
@_xml.attributes = attributes
|
||||
if classes.constructor isnt Object
|
||||
throw new Error "The classes must be specified as an Array"
|
||||
@_xml.classes = classes
|
||||
_classes = @_xml.attributes.class
|
||||
delete @_xml.attributes.class
|
||||
if _classes?
|
||||
for c_name, c in _classes.split(" ")
|
||||
if c.length > 0
|
||||
@_xml.classes[c_name] = c
|
||||
if children.constructor isnt Array
|
||||
throw new Error "You must specify the children as an Array that contains Strings and Y.Xml objects only"
|
||||
|
||||
_name: "Xml"
|
||||
|
||||
_getModel: (types, ops)->
|
||||
if not @_model?
|
||||
@_model = new ops.MapManager(@).execute()
|
||||
@_model.val("attributes", new Y.Object(@_xml.attributes))
|
||||
.val("classes", new Y.Object(@_xml.classes))
|
||||
.val("tagname", @_xml.tagname)
|
||||
.val("children", @_xml.children)
|
||||
|
||||
delete @_xml
|
||||
@_model
|
||||
|
||||
_setModel: (@_model)->
|
||||
delete @_xml
|
||||
|
||||
attr: (name, value)->
|
||||
if arguments.length > 1
|
||||
if value.constructor isnt Strings
|
||||
throw new Error "The attributes must be of type String!"
|
||||
@_model.val("attributes").val(name, value)
|
||||
@
|
||||
else if arguments.length > 0
|
||||
@_model.val("attributes").val(name)
|
||||
else
|
||||
@_model.val("attributes").val()
|
||||
|
||||
addClass: (name)->
|
||||
@_model.val("classes").val(name, true)
|
||||
@
|
||||
|
||||
removeClass: (name)->
|
||||
@_model.val("classes").delete(name)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user