Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
add import dumping.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Apr 3, 2014
1 parent 2961478 commit 1cc0a81
Showing 1 changed file with 39 additions and 12 deletions.
51 changes: 39 additions & 12 deletions x-dom-serializer.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,20 @@
this.propertyBlackList = Object.keys(node.__proto__);
},
dumpElement: function(node, indent) {
indent = indent || '';
var name = ''; //node.elementAttributes.name || '';
var html = '', indent = indent || '';
if (!node.querySelector('link[rel=import]')) {
html+= this.dumpImports(node, indent);
}
html += this.dumpChildren(node, indent);
//var name = ''; //node.elementAttributes.name || '';
//
// resolve properties to attributes before dumping
//var proto = this.dumpProto(node, indent + this.tab + this.tab);
//var script = 'Polymer(\'' + name +'\', ' + proto + ');';
//
var html = ''
//html += indent + '<polymer-element' + this.dumpElementAttributes(node) +
// '>\n' + indent + this.tab + '<template>\n';
//
//html += indent + this.dumpStyle(node, indent + this.tab + this.tab);
var childIndent = indent; // + this.tab + this.tab;
var children = '';
Array.prototype.forEach.call(node.children, function(c) {
if (this.elementBlackList.indexOf(c.localName) < 0) {
children += this.dumpTag(c, childIndent);
}
}, this);
html += children || (childIndent + '\n');
//
//html += indent + this.tab + '</template>\n' +
//indent + this.tab +'<script>\n' +
Expand All @@ -141,6 +135,15 @@
//indent + '</polymer-element>';
return html;
},
dumpChildren: function(node, indent) {
var children = '', indent = indent || '';
Array.prototype.forEach.call(node.children, function(c) {
if (this.elementBlackList.indexOf(c.localName) < 0) {
children += this.dumpTag(c, indent);
}
}, this);
return children || (indent + '\n');
},
dumpTextNode: function(node, indent) {
if (node.parentNode.localName === 'style') {
var style = node.parentNode;
Expand Down Expand Up @@ -250,6 +253,30 @@
'$1;\n') +
indent + '}';
return css;
},
dumpImports: function(element, indent) {
var n$ = element.querySelectorAll('*');
var imports = [], metas=[];
for (var i=0, l=n$.length, n, m; (i<l) && (n=n$[i]); i++) {
m = n.meta;
if (m && metas.indexOf(m) < 0) {
metas.push(m);
var f = m.getImports().content.cloneNode(true);
imports = imports.concat(f.querySelectorAll('link[rel=import]').array());
}
}
var href = window.location.origin + window.location.pathname;
var d = document.createElement('div'), urls=[];
for (var i=0, l=imports.length, n, h; (i<l) && (n=imports[i]); i++) {
h = n.href.replace(href, '').replace('components', '..');
if (urls.indexOf(h) < 0) {
urls.push(h);
n.setAttribute('href', h);
d.appendChild(n);
d.appendChild(document.createTextNode('\n'));
}
}
return d.innerHTML;
}
});
</script>
Expand Down

0 comments on commit 1cc0a81

Please sign in to comment.