Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug 684958 (async, part): Ensure private functions have _ prefix

  • Loading branch information...
commit 3d5a5ff2187f0a363cd7c89cb78f7bb24dd168aa 1 parent b61ccde
@joewalker authored
Showing with 40 additions and 40 deletions.
  1. +40 −40 lib/gcli/ui/domtemplate.js
View
80 lib/gcli/ui/domtemplate.js
@@ -8,7 +8,7 @@ define(function(require, exports, module) {
var domtemplate = exports;
-// WARNING: do not 'use_strict' without reading the notes in envEval;
+// WARNING: do not 'use_strict' without reading the notes in _envEval();
/**
* A templater that allows one to quickly template DOM nodes.
@@ -38,11 +38,11 @@ Templater.prototype.processNode = function(node, data) {
// some types of processing from happening, and foreach must come first
// because it defines new data on which 'if' might depend.
if (node.hasAttribute('foreach')) {
- this.processForEach(node, data);
+ this._processForEach(node, data);
return;
}
if (node.hasAttribute('if')) {
- if (!this.processIf(node, data)) {
+ if (!this._processIf(node, data)) {
return;
}
}
@@ -58,15 +58,15 @@ Templater.prototype.processNode = function(node, data) {
try {
if (name === 'save') {
// Save attributes are a setter using the node
- value = this.stripBraces(value);
- this.property(value, data, node);
+ value = this._stripBraces(value);
+ this._property(value, data, node);
node.removeAttribute('save');
} else if (name.substring(0, 2) === 'on') {
// Event registration relies on property doing a bind
- value = this.stripBraces(value);
- var func = this.property(value, data);
+ value = this._stripBraces(value);
+ var func = this._property(value, data);
if (typeof func !== 'function') {
- this.handleError('Expected ' + value +
+ this._handleError('Expected ' + value +
' to resolve to a function, but got ' + typeof func);
}
node.removeAttribute(name);
@@ -78,7 +78,7 @@ Templater.prototype.processNode = function(node, data) {
} else {
// Replace references in all other attributes
var newValue = value.replace(/\$\{[^}]*\}/g, function(path) {
- return this.envEval(path.slice(2, -1), data, value);
+ return this._envEval(path.slice(2, -1), data, value);
}.bind(this));
// Remove '_' prefix of attribute names so the DOM won't try
// to use them before we've processed the template
@@ -103,7 +103,7 @@ Templater.prototype.processNode = function(node, data) {
}
if (node.nodeType === Node.TEXT_NODE) {
- this.processTextNode(node, data);
+ this._processTextNode(node, data);
}
} finally {
this.stack.pop();
@@ -113,20 +113,20 @@ Templater.prototype.processNode = function(node, data) {
/**
* Handle <x if="${...}">
* @param node An element with an 'if' attribute
- * @param data The data to use with envEval
+ * @param data The data to use with _envEval()
* @returns true if processing should continue, false otherwise
*/
-Templater.prototype.processIf = function(node, data) {
+Templater.prototype._processIf = function(node, data) {
this.stack.push('if');
try {
var originalValue = node.getAttribute('if');
- var value = this.stripBraces(originalValue);
+ var value = this._stripBraces(originalValue);
var recurse = true;
try {
- var reply = this.envEval(value, data, originalValue);
+ var reply = this._envEval(value, data, originalValue);
recurse = !!reply;
} catch (ex) {
- this.handleError('Error with \'' + value + '\'', ex);
+ this._handleError('Error with \'' + value + '\'', ex);
recurse = false;
}
if (!recurse) {
@@ -143,9 +143,9 @@ Templater.prototype.processIf = function(node, data) {
* Handle <x foreach="param in ${array}"> and the special case of
* <loop foreach="param in ${array}">
* @param node An element with a 'foreach' attribute
- * @param data The data to use with envEval
+ * @param data The data to use with _envEval()
*/
-Templater.prototype.processForEach = function(node, data) {
+Templater.prototype._processForEach = function(node, data) {
this.stack.push('foreach');
try {
var originalValue = node.getAttribute('foreach');
@@ -154,12 +154,12 @@ Templater.prototype.processForEach = function(node, data) {
var paramName = 'param';
if (value.charAt(0) === '$') {
// No custom loop variable name. Use the default: 'param'
- value = this.stripBraces(value);
+ value = this._stripBraces(value);
} else {
// Extract the loop variable name from 'NAME in ${ARRAY}'
var nameArr = value.split(' in ');
paramName = nameArr[0].trim();
- value = this.stripBraces(nameArr[1].trim());
+ value = this._stripBraces(nameArr[1].trim());
}
node.removeAttribute('foreach');
try {
@@ -192,7 +192,7 @@ Templater.prototype.processForEach = function(node, data) {
}
};
- var reply = this.envEval(value, data, originalValue);
+ var reply = this._envEval(value, data, originalValue);
if (Array.isArray(reply)) {
reply.forEach(function(data, i) {
processAll('' + i, data);
@@ -206,7 +206,7 @@ Templater.prototype.processForEach = function(node, data) {
}
node.parentNode.removeChild(node);
} catch (ex) {
- this.handleError('Error with \'' + value + '\'', ex);
+ this._handleError('Error with \'' + value + '\'', ex);
}
} finally {
this.stack.pop();
@@ -218,9 +218,9 @@ Templater.prototype.processForEach = function(node, data) {
* sections parsed out. We replace the node by altering node.parentNode but
* we could probably use a DOM Text API to achieve the same thing.
* @param node The Text node to work on
- * @param data The data to use in calls to envEval
+ * @param data The data to use in calls to _envEval()
*/
-Templater.prototype.processTextNode = function(node, data) {
+Templater.prototype._processTextNode = function(node, data) {
// Replace references in other attributes
var value = node.data;
// We can't use the string.replace() with function trick (see generic
@@ -240,9 +240,9 @@ Templater.prototype.processTextNode = function(node, data) {
return;
}
if (part.charAt(0) === '$') {
- part = this.envEval(part.slice(1), data, node.data);
+ part = this._envEval(part.slice(1), data, node.data);
}
- // It looks like this was done a few lines above but see envEval
+ // It looks like this was done a few lines above but see _envEval()
if (part === null) {
part = "null";
}
@@ -264,9 +264,9 @@ Templater.prototype.processTextNode = function(node, data) {
* @param str the string to check.
* @return The string stripped of ${ and }, or untouched if it does not match
*/
-Templater.prototype.stripBraces = function(str) {
+Templater.prototype._stripBraces = function(str) {
if (!str.match(/\$\{.*\}/g)) {
- this.handleError('Expected ' + str + ' to match ${...}');
+ this._handleError('Expected ' + str + ' to match ${...}');
return str;
}
return str.slice(2, -1);
@@ -276,9 +276,9 @@ Templater.prototype.stripBraces = function(str) {
* Combined getter and setter that works with a path through some data set.
* For example:
* <ul>
- * <li>property('a.b', { a: { b: 99 }}); // returns 99
- * <li>property('a', { a: { b: 99 }}); // returns { b: 99 }
- * <li>property('a', { a: { b: 99 }}, 42); // returns 99 and alters the
+ * <li>_property('a.b', { a: { b: 99 }}); // returns 99
+ * <li>_property('a', { a: { b: 99 }}); // returns { b: 99 }
+ * <li>_property('a', { a: { b: 99 }}, 42); // returns 99 and alters the
* input data to be { a: { b: 42 }}
* </ul>
* @param path An array of strings indicating the path through the data, or
@@ -289,7 +289,7 @@ Templater.prototype.stripBraces = function(str) {
* @return The value pointed to by <tt>path</tt> before any
* <tt>newValue</tt> is applied.
*/
-Templater.prototype.property = function(path, data, newValue) {
+Templater.prototype._property = function(path, data, newValue) {
this.stack.push(path);
try {
if (typeof path === 'string') {
@@ -306,10 +306,10 @@ Templater.prototype.property = function(path, data, newValue) {
return value;
}
if (!value) {
- this.handleError('Can\'t find path=' + path);
+ this._handleError('Can\'t find path=' + path);
return null;
}
- return this.property(path.slice(1), value, newValue);
+ return this._property(path.slice(1), value, newValue);
} finally {
this.stack.pop();
}
@@ -328,13 +328,13 @@ Templater.prototype.property = function(path, data, newValue) {
* @return The return value of the script, or the error message if the script
* execution failed.
*/
-Templater.prototype.envEval = function(script, env, context) {
+Templater.prototype._envEval = function(script, env, context) {
with (env) {
try {
this.stack.push(context);
return eval(script);
} catch (ex) {
- this.handleError('Template error evaluating \'' + script + '\'' +
+ this._handleError('Template error evaluating \'' + script + '\'' +
' environment=' + Object.keys(env).join(', '), ex);
return script;
} finally {
@@ -349,11 +349,11 @@ Templater.prototype.envEval = function(script, env, context) {
* @param message the error message to report.
* @param ex optional associated exception.
*/
-Templater.prototype.handleError = function(message, ex) {
- this.logError(message);
- this.logError('In: ' + this.stack.join(' > '));
+Templater.prototype._handleError = function(message, ex) {
+ this._logError(message);
+ this._logError('In: ' + this.stack.join(' > '));
if (ex) {
- this.logError(ex);
+ this._logError(ex);
}
};
@@ -363,7 +363,7 @@ Templater.prototype.handleError = function(message, ex) {
* environments.
* @param message the error message to report.
*/
-Templater.prototype.logError = function(message) {
+Templater.prototype._logError = function(message) {
console.log(message);
};
Please sign in to comment.
Something went wrong with that request. Please try again.