Permalink
Browse files

fixed bug where attributes with value 'false' were not included in ou…

…tput
  • Loading branch information...
1 parent 3607d0c commit 443e2d1550e18dbf294b1a47190078c753778343 @joelvh committed Dec 7, 2012
Showing with 27 additions and 27 deletions.
  1. +11 −12 lib/ObjectTemplate.coffee
  2. +16 −15 lib/TemplateConfig.coffee
View
@@ -14,7 +14,7 @@ class ObjectTemplate
transform: (data) =>
node = @nodeToProcess data
- return null if !node?
+ return null unless node?
# process properties
switch sysmo.type node
@@ -41,23 +41,23 @@ class ObjectTemplate
context = @createMapStructure node
if @config.nestTemplate and (nested_key = @chooseKey(node))
- nested_context = {}
- nested_context[nested_key] = context;
- context = nested_context
+ nested_context = {}
+ nested_context[nested_key] = context;
+ context = nested_context
context
createMapStructure: (node) =>
context = {}
- return @chooseValue(node, context) if !@config.nestTemplate
+ return @chooseValue(node, context) unless @config.nestTemplate
# loop through properties to pick up any key/values that should be nested
for key, value of node when @config.processable node, value, key
# call @getNode() to register the use of the property on that node
- nested = @getNode(node, key)
- value = @chooseValue nested
+ nested = @getNode(node, key)
+ value = @chooseValue nested
@updateContext context, nested, value, key
context
@@ -85,7 +85,7 @@ class ObjectTemplate
# process mapping instructions
switch sysmo.type value
# string should be the path to a property on the current node
- when 'String' then filter = (node, path) => result = @getNode(node, path) or null
+ when 'String' then filter = (node, path) => @getNode(node, path)
# array gets multiple property values
when 'Array' then filter = (node, paths) => @getNode(node, path) for path in paths
# function is a custom filter for the node
@@ -112,7 +112,7 @@ class ObjectTemplate
@aggregateValue context, formatted.key, formatted.value
aggregateValue: (context, key, value) =>
- return context if !value?
+ return context unless value?
# if context is an array, just add the value
if sysmo.isArray(context)
@@ -136,7 +136,7 @@ class ObjectTemplate
@getNode node, @config.getPath()
getNode: (node, path) =>
- return null if !path
+ return null unless path
return node if path is '.'
@paths node, path
sysmo.getDeepValue node, path, true
@@ -154,8 +154,7 @@ class ObjectTemplate
index = @pathNodes.indexOf node
- if !path
- return if index isnt -1 then @pathCache[index] else []
+ return (if index isnt -1 then @pathCache[index] else []) unless path
if index is -1
paths = []
View
@@ -7,24 +7,24 @@ sysmo = require?('sysmo') || window?.Sysmo
class TemplateConfig
constructor: (config) ->
# if there is no node path, set to current node
- config.path or= '.'
+ config.path or= '.'
# ensure 'as' template exists
- config.as or= {}
+ config.as or= {}
# convert property name to array
- config.choose = [config.choose] if sysmo.isString config.choose
+ config.choose = [config.choose] if sysmo.isString config.choose
# include multiple templates to apply before this one
- config.include = [config.include] if sysmo.isString config.include
+ config.include = [config.include] if sysmo.isString config.include
# create settings
- @arrayToMap = !!config.key
+ @arrayToMap = !!config.key
# TODO: Need to implement converting a map to an array...
# This property was created to show how to specify converting maps to arrays
- @mapToArray = !@arrayToMap and config.key is false and !config.as
- @directMap = !!(@arrayToMap and config.value)
- @nestTemplate = !!config.nested
- @includeAll = !!config.all
+ @mapToArray = !@arrayToMap and config.key is false and !config.as
+ @directMap = !!(@arrayToMap and config.value)
+ @nestTemplate = !!config.nested
+ @includeAll = !!config.all
- @config = config
+ @config = config
getPath: =>
@config.path
@@ -71,7 +71,7 @@ class TemplateConfig
aggregate: (context, key, value, existing) =>
aggregator = @config.aggregate?[key] or @config.aggregate
- return false if !sysmo.isFunction(aggregator)
+ return false unless sysmo.isFunction(aggregator)
context[key] = aggregator(key, value, existing)
@@ -81,11 +81,12 @@ class TemplateConfig
# if key is a number, assume this is an array element and skip
if !sysmo.isNumber(key)
formatter = @config.format?[key] or @config.format
- pair = if sysmo.isFunction(formatter) then formatter(node, value, key) else {}
- else pair = {}
+ pair = if sysmo.isFunction(formatter) then formatter(node, value, key) else {}
+ else
+ pair = {}
- pair.key = key if 'key' not of pair
- pair.value = value if 'value' not of pair
+ pair.key = key if 'key' not of pair
+ pair.value = value if 'value' not of pair
pair
# register module (CommonJS/Node.js) or handle browser

0 comments on commit 443e2d1

Please sign in to comment.