Comparing version 0.0.8 to 0.0.9
{ | ||
"name": "xsalt", | ||
"main": "xsalt.js", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"homepage": "https://github.com/chocolatetoothpaste/xsalt", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "xsalt", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "A different kind of template engine", | ||
@@ -5,0 +5,0 @@ "main": "xsalt.js", |
@@ -22,2 +22,3 @@ # xsalt | ||
Also, the examples previously have examples where a lot of closing tags were omitted. These examples would work, but it is probably best to include closing tags to ensure you get the structure you are expecting. | ||
As with HTML in general, it is best if you close tags (that require closing) to ensure the output is what you expect. | ||
@@ -24,0 +25,0 @@ // Basic usage: prefix elements to process with "xs:" |
32
xsalt.js
@@ -10,4 +10,2 @@ (function(document) { | ||
// console.log(tmpl); | ||
// creating a sandbox for moving elements around | ||
@@ -51,6 +49,5 @@ var temp = document.createElement('div'); | ||
data.forEach(function(i) { | ||
var n = that.clone(node); | ||
// var n = that.clone(node); | ||
var n = node.cloneNode(true); | ||
// wish there was a cleaner way to do this but cloneNode won't let | ||
// the tagName be changed | ||
Array.prototype.forEach.call(node.attributes, function(v) { | ||
@@ -85,4 +82,7 @@ if( typeof that.parse[v.nodeName] === "function" ) { | ||
/** | ||
* The native methods for node cloning and replacement are working since tag | ||
* names are not sanitized until the final output, so these are not needed right | ||
* now. they are left here for future reference | ||
* Clones a node and it's attributes, trimming "xs:" from the tag name | ||
*/ | ||
@@ -92,3 +92,3 @@ xsalt.prototype.clone = function(node) { | ||
// compile is done, before returning result | ||
var tag = node.tagName.toLowerCase();//.replace('xs:', ''); | ||
var tag = node.tagName.toLowerCase(); | ||
var n = document.createElement(tag); | ||
@@ -108,3 +108,2 @@ | ||
* Replaces one node with another | ||
*/ | ||
@@ -116,3 +115,5 @@ xsalt.prototype.replace = function(node, n) { | ||
**/ | ||
/** | ||
@@ -123,4 +124,2 @@ * Compiles template and data together and returns a HTML string | ||
xsalt.prototype.compile = function( data, node, callback ) { | ||
var that = this; | ||
if( typeof node === "function" ) { | ||
@@ -139,7 +138,6 @@ callback = node; | ||
if( /^xs:/g.test( tag ) ) { | ||
// if( node[ii].hasAttribute('xs') ) { | ||
// collections have to be handled a little differently | ||
// the template node does not get replaced here since it has to be | ||
// "cloned" multiple times | ||
// iterative functions must handle this internally | ||
// iterative directives must handle this internally | ||
if( node[ii].hasAttribute('each') ) { | ||
@@ -154,3 +152,3 @@ var attr = node[ii].getAttribute('each'); | ||
this.parse.each.call(that, node[ii], set, callback); | ||
this.parse.each.call(this, node[ii], set, callback); | ||
} | ||
@@ -160,3 +158,5 @@ | ||
// hot swap the node to replace the "xs:" tag with the real one | ||
this.replace(node[ii], this.clone(node[ii])); | ||
// this.replace(node[ii], this.clone(node[ii])); | ||
var n = node[ii].cloneNode(true); | ||
node[ii].parentNode.replaceChild(n, node[ii]); | ||
@@ -178,3 +178,3 @@ // it is probably quicker (and easier to check) to iterate over | ||
this.parse[p].call(that, node[ii], key, set); | ||
this.parse[p].call(this, node[ii], key, set); | ||
@@ -199,7 +199,5 @@ if( typeof callback === "function" ) { | ||
var out = document.createElement('div'); | ||
// console.log(this.template.innerHTML) | ||
// clean up all remaing "xs:" and variant prefixes | ||
out.innerHTML = this.template.innerHTML.replace(/<(\/?)xs!?:/g, '<$1'); | ||
// console.log(out.innerHTML) | ||
@@ -206,0 +204,0 @@ return out.innerHTML; |
11889
102
194