Skip to content

Commit

Permalink
Merge pull request #99 from smfoote/debugging-helpers
Browse files Browse the repository at this point in the history
Add debug helpers
  • Loading branch information
prashn64 committed Jul 20, 2015
2 parents 841069a + 8d860bf commit 9e78876
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
17 changes: 17 additions & 0 deletions dist/helpers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions dist/runtime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*eslint no-debugger:0 */

let emptyFrag = function() {
return document.createDocumentFragment();
};
Expand Down Expand Up @@ -50,6 +52,21 @@ let helpers = {
return truthTest(params, bodies, context, (left, right) => {
return left <= right;
});
},
contextDump(context, params) {
let formattedContext = JSON.stringify(context, null, 2);
if (params.to === 'console') {
console.log(formattedContext);
} else {
let frag = document.createDocumentFragment();
let pre = document.createElement('pre');
pre.appendChild(document.createTextNode(formattedContext));
frag.appendChild(pre);
return frag;
}
},
debugger() {
debugger;
}
};

Expand Down
14 changes: 12 additions & 2 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ let tornado = {
}
if (Array.isArray(val)) {
if (placeholderNode) {
let frag = document.createDocumentFragment();
let frag = this.createDocumentFragment();
for (let i = 0, item; (item = val[i]); i++) {
frag.appendChild(body(item));
}
Expand Down Expand Up @@ -308,6 +308,7 @@ let tornado = {
},

helperResult(placeholderNode, returnVal) {
returnVal = this.util.isNode(returnVal) ? returnVal : this.createDocumentFragment();
if (this.util.isPromise(returnVal)) {
returnVal.then(frag => {
if (placeholderNode) {
Expand Down Expand Up @@ -335,7 +336,7 @@ let tornado = {
block(name, idx, context, template) {
let renderer = this.getBlockRenderer(name, idx, template);
if (!renderer) {
let frag = document.createDocumentFragment();
let frag = this.createDocumentFragment();
frag.appendChild(document.createTextNode(''));
return frag;
}
Expand Down Expand Up @@ -541,6 +542,15 @@ let tornado = {
return !!val;
},

/**
* Determine if a value is a HTML Node
* @param {*} val The value in question
* @return {Boolean}
*/
isNode(val) {
return val instanceof Node;
},

/**
* Return the values of the object (sorted by key name) as an array
* @param {Object} obj The object from which the values are to be extracted
Expand Down

0 comments on commit 9e78876

Please sign in to comment.