Skip to content

Commit

Permalink
Added support for number & boolean
Browse files Browse the repository at this point in the history
Aded support for number and boolean to be added to html attribute when a
function is used
  • Loading branch information
moappi committed May 2, 2016
1 parent 21f20ff commit 96fe3e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
32 changes: 21 additions & 11 deletions lib/json2html.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ var json2html = {
//Get the transform value associated with this key
// added as key could be children or html
var _transform = transform[key];

//Determine what kind of object this is
// array & function => children
// other => html
Expand All @@ -161,19 +161,29 @@ var json2html = {
//Get the result from the function
var temp = _transform.call(obj, obj, index);

//Make sure we have an object result with the props
// html (string), events (array)
// OR a string (then just append it to the children)
if(typeof temp === 'object') {
//make sure this object is a valid json2html response object
if(temp.html !== undefined && temp.events !== undefined) children = json2html._append(children,temp);
} else if(typeof temp === 'string') {
//Determine what type of object was returned
switch(typeof temp){

//append the result directly to the html of the children
children.html += temp;
//Only returned by json2html.transform or $.json2html calls
case 'object':
//make sure this object is a valid json2html response object
// we ignore all other objects (since we don't know how to represent them in html)
if(temp.html !== undefined && temp.events !== undefined) children = json2html._append(children,temp);
break;

//Not supported
case 'function':
case 'undefined':
break;

//Append to html
// string, number, boolean
default:
children.html += temp;
break;
}
} else {

//Create the html attribute for this element
html = json2html._getValue(obj,transform,key,index);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"name": "node-json2html",
"description": "node-json2html - HTML Templating using JSON2HTML",
"version": "1.1.0",
"version": "1.1.1",
"homepage": "http://json2html.com",
"repository": {
"url": "git://github.com/moappi/node-json2html.git"
Expand Down

0 comments on commit 96fe3e1

Please sign in to comment.