Stephen McKamey avatar Stephen McKamey committed 7a8f2dd

- updating JSDocs

Comments (0)

Files changed (1)

  * @fileoverview duel.js: client-side template engine
  */
 
+/**
+ * @param {Array|Object|string|function(*,number,number):Array|Object|string} view The view template
+ * @returns {Template}
+ */
 var duel = (function() {
 
 	/**
 	/**
 	 * Renders the result as a string
 	 * 
-	 * @param {Array|Object|string} view The compiled view
+	 * @param {Array|Object|string} view The bound view
 	 * @returns {String}
 	 */
 	render,
 
 	/**
-	 * Builds DOM from JsonML
+	 * Builds the result as DOM
 	 * 
-	 * @param {Array} jml The JsonML structure to build
+	 * @param {Array} view The bound view
 	 * @returns {DOMElement}
 	 */
 	build;
-	
+
+	/* Types --------------------*/
+
 	/**
 	 * Wraps a binding result with rendering methods
 	 * 
 	 * @this {Unparsed}
 	 * @param {string} value The value
 	 */
-	function Unparsed(/*string*/ value) {
+	function Unparsed(value) {
 		this.value = value;
 	}
 
+	/**
+	 * @constant
+	 */
 	var NUL = 0,
-		FUN = 1,
-		ARY = 2,
-		OBJ = 3,
-		VAL = 4,
+	/**
+	 * @constant
+	 */
+	FUN = 1,
+	/**
+	 * @constant
+	 */
+	ARY = 2,
+	/**
+	 * @constant
+	 */
+	OBJ = 3,
+	/**
+	 * @constant
+	 */
+	VAL = 4,
 
-		FOR = "$for",
-		CHOOSE = "$choose",
-		IF = "$if",
-		ELSE = "$else",
-		INIT = "$init",
-		LOAD = "$load";
+	/**
+	 * @constant
+	 */
+	FOR = "$for",
+	/**
+	 * @constant
+	 */
+	CHOOSE = "$choose",
+	/**
+	 * @constant
+	 */
+	IF = "$if",
+	/**
+	 * @constant
+	 */
+	ELSE = "$else",
+	/**
+	 * @constant
+	 */
+	INIT = "$init",
+	/**
+	 * @constant
+	 */
+	LOAD = "$load";
 
 	/**
 	 * Determines the type of the value
 		}
 	}
 
-	/* ToString methods --------------------*/
-
-	/**
-	 * @type {Object}
-	 */
-	var VOID_TAGS = (function(names) {
-			var tags = {};
-			while (names.length) {
-				tags[names.pop()] = true;
-			}
-			return tags;
-		})("area,base,basefont,br,col,frame,hr,img,input,isindex,keygen,link,meta,param,source,wbr".split(','));
+	/* Binding methods --------------------*/
 
 	/**
 	 * Appends a node to a parent
 		return result;
 	};
 
+	/* Rendering methods --------------------*/
+
+	/**
+	 * Void tag lookup 
+	 * @constant
+	 * @type {Object}
+	 */
+	var VOID_TAGS = (function(names) {
+			var tags = {};
+			while (names.length) {
+				tags[names.pop()] = true;
+			}
+			return tags;
+		})("area,base,basefont,br,col,frame,hr,img,input,isindex,keygen,link,meta,param,source,wbr".split(','));
+
 	/**
 	 * Encodes invalid literal characters in strings
 	 * 
 		return output.join("");
 	};
 
-	/* ToDom methods --------------------*/
+	/* DOM Building methods --------------------*/
 
-	//attribute name mapping
+	/**
+	 * Attribute name map
+	 * @constant
+	 * @type {Object}
+	 */
 	var ATTRMAP = {
 		rowspan : "rowSpan",
 		colspan : "colSpan",
 		// can add more attributes here as needed
 	},
 
-	// attribute duplicates
+	/**
+	 * Attribute duplicates map
+	 * @constant
+	 * @type {Object}
+	 */
 	ATTRDUP = {
 		enctype : "encoding",
 		onscroll : "DOMMouseScroll"
 		// can add more attributes here as needed
 	},
 
-	// event names
-	EVTS = (function(/*string[]*/ names) {
+	/**
+	 * Event names map
+	 * @constant
+	 * @type {Object}
+	 */
+	EVTS = (function(names) {
 		var evts = {};
 		while (names.length) {
 			var evt = names.pop();
 	}
 
 	/**
-	 * Applies JsonML to DOM
+	 * Applies node to DOM
 	 * 
 	 * @param {DOMElement} elem The element to append
-	 * @param {Array} jml The JsonML structure to build
+	 * @param {Array} node The node to build
 	 * @returns {DOMElement}
 	 */
-	function patch(elem, jml) {
+	function patch(elem, node) {
 
-		for (var i=1; i<jml.length; i++) {
-			var child = jml[i];
+		for (var i=1; i<node.length; i++) {
+			var child = node[i];
 			switch (getType(child)) {
 				case ARY:
 				case VAL:
 	}
 
 	/**
-	 * Builds DOM from JsonML
+	 * Builds the result as DOM
 	 * 
-	 * @param {Array} jml The JsonML structure to build
+	 * @param {Array} view The bound view
 	 * @returns {DOMElement}
 	 */
-	build = function(jml) {
+	build = function(view) {
 		try {
-			if (!jml) {
+			if (!view) {
 				return null;
 			}
-			if (typeof jml === "string") {
-				return document.createTextNode(jml);
+			if (typeof view === "string") {
+				return document.createTextNode(view);
 			}
-			if (jml instanceof Unparsed) {
-				return toDOM(jml.value);
+			if (view instanceof Unparsed) {
+				return toDOM(view.value);
 			}
 
-			var tag = jml[0]; // tagName
+			var tag = view[0]; // tagName
 			if (!tag) {
 				// correctly handle multiple-roots
 				// create a document fragment to hold elements
 				var frag = document.createDocumentFragment ?
 					document.createDocumentFragment() :
 					document.createElement("");
-				for (var i=1; i<jml.length; i++) {
-					appendChild(frag, build(jml[i]));
+				for (var i=1; i<view.length; i++) {
+					appendChild(frag, build(view[i]));
 				}
 
 				// trim extraneous whitespace
 
 			if (tag.toLowerCase() === "style" && document.createStyleSheet) {
 				// IE requires this interface for styles
-				patch(document.createStyleSheet(), jml);
+				patch(document.createStyleSheet(), view);
 				// in IE styles are effective immediately
 				return null;
 			}
 
-			var elem = patch(document.createElement(tag), jml);
+			var elem = patch(document.createElement(tag), view);
 
 			// trim extraneous whitespace
 			trimWhitespace(elem);
 			try {
 				// handle error with complete context
 				var err = (typeof duel.onerror === "function") ? duel.onerror : onError;
-				return err(ex, jml);
+				return err(ex, view);
 			} catch (ex2) {
 				return onError(ex2);
 			}
 		}
 	};
 
-	/* public methods --------------------*/
+	/* Factory methods --------------------*/
 
 	/**
 	 * @param {Array|Object|string|function(*,number,number):Array|Object|string} view The view template
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.