compound-ex4
Version:
Compound-ex4 - MVC framework for NodeJS (ExpressJs 4 version), fork compoundjs(https://github.com/1602/compound)
86 lines (76 loc) • 3.21 kB
text/coffeescript
events = require './events'
nodes = require './nodes'
util = require './util'
{YAMLError} = require './errors'
class extends YAMLError
class
constructor: ({ , , , , } = {}) ->
= {}
= {}
= 0
= null
open: ->
if is null
new events.StreamStartEvent
= false
else if
throw new SerializerError 'serializer is closed'
else
throw new SerializerError 'serializer is already open'
close: ->
if is null
throw new SerializerError 'serializer is not opened'
else if not
new events.StreamEndEvent
= true
serialize: (node) ->
if is null
throw new SerializerError 'serializer is not opened'
else if
throw new SerializerError 'serializer is closed'
if node?
new events.DocumentStartEvent undefined, undefined, , ,
node
node
new events.DocumentEndEvent undefined, undefined,
= {}
= {}
= 0
anchor_node: (node) ->
if node.unique_id of
[node.unique_id] ?= node
else
[node.unique_id] = null
if node instanceof nodes.SequenceNode
item for item in node.value
else if node instanceof nodes.MappingNode
for [ key, value ] in node.value
key
value
generate_anchor: (node) ->
"id#{util.pad_left ++@last_anchor_id, '0', 4}"
serialize_node: (node, parent, index) ->
alias = [node.unique_id]
if node.unique_id of
new events.AliasEvent alias
else
[node.unique_id] = true
parent, index
if node instanceof nodes.ScalarNode
detected_tag = nodes.ScalarNode, node.value, [ true, false ]
default_tag = nodes.ScalarNode, node.value, [ false, true ]
implicit = [ node.tag == detected_tag, node.tag == default_tag ]
new events.ScalarEvent alias, node.tag, implicit, node.value, undefined, undefined, node.style
else if node instanceof nodes.SequenceNode
implicit = node.tag == nodes.SequenceNode, node.value, true
new events.SequenceStartEvent alias, node.tag, implicit, undefined, undefined, node.flow_style
item, node, index for item, index in node.value
new events.SequenceEndEvent
else if node instanceof nodes.MappingNode
implicit = node.tag == nodes.MappingNode, node.value, true
new events.MappingStartEvent alias, node.tag, implicit, undefined, undefined, node.flow_style
for [ key, value ] in node.value
key, node, null
value, node, key
new events.MappingEndEvent
()