Comparing version 0.8.1 to 0.9.0
{ | ||
"name": "razorleaf", | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"main": "razorleaf.js", | ||
@@ -5,0 +5,0 @@ "files": ["razorleaf.js"], |
@@ -442,3 +442,38 @@ "use strict"; | ||
function compileStatic(element) { | ||
var isVoid = voidTags.indexOf(element.name) !== -1; | ||
var startTag = "<" + element.name; | ||
var content = ""; | ||
for(var i = 0; i < element.children.length; i++) { | ||
var child = element.children[i]; | ||
if(child.type === "attribute") { | ||
startTag += " " + child.name + "=\"" + child.value.toAttributeValue() + "\""; | ||
} else if(child.type === "element") { | ||
var staticMarkup = compileStatic(child); | ||
if(staticMarkup === null) { | ||
return null; | ||
} | ||
content += staticMarkup; | ||
} else if(child.type === "string") { | ||
content += child.content.toContent(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
if(isVoid) { | ||
if(content) { | ||
throw new SyntaxError("Void element " + element.name + " cannot contain elements."); // TODO: Where‽ | ||
} | ||
return startTag + ">"; | ||
} | ||
return startTag + ">" + content + "</" + element.name + ">"; | ||
} | ||
function compileChildren(children) { | ||
@@ -459,2 +494,9 @@ var info = {attributes: false, content: false}; | ||
info.content = true; | ||
var staticMarkup = compileStatic(child); | ||
if(staticMarkup !== null) { | ||
return "__top.content += '" + staticMarkup + "';"; | ||
} | ||
var isVoid = voidTags.indexOf(child.name) !== -1; | ||
@@ -461,0 +503,0 @@ var children = compileChildren(child.children); |
14489
429