diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-04-08 21:04:44 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-04-08 21:04:44 +0100 |
| commit | a09303c9085c6eb17a0c943a7c1441d85ee3a5f2 (patch) | |
| tree | 9ba78003423b611315a5080d1c88af7e8edeb68f /lib | |
| parent | 3170803959a8264afb5088946bd8015869531906 (diff) | |
Use Object.create to simplify element handling in HtmlGenerator
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/html-generator.js | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/lib/html-generator.js b/lib/html-generator.js index 3825f9b..3705767 100644 --- a/lib/html-generator.js +++ b/lib/html-generator.js @@ -47,20 +47,19 @@ function HtmlGenerator() { } function stylePartMatchesStackElement(stylePart, stackElement) { - return stackElement && stylePart.tagName === stackElement.htmlPathElement.tagName; + return stackElement && stylePart.tagName === stackElement.tagName; } - function open(element) { - stack.push({ - htmlPathElement: element, - written: false - }); + function open(htmlPathElement) { + var stackElement = Object.create(htmlPathElement); + stackElement.written = false; + stack.push(stackElement); } function close() { - var stackElement = stack.pop(); - if (stackElement.written) { - fragments.push(util.format("</%s>", stackElement.htmlPathElement.tagName)); + var element = stack.pop(); + if (element.written) { + fragments.push(util.format("</%s>", element.tagName)); } } @@ -76,11 +75,10 @@ function HtmlGenerator() { }).forEach(writeElement); } - function writeElement(stackElement) { - stackElement.written = true; - var htmlPathElement = stackElement.htmlPathElement; - var attributeString = generateAttributeString(htmlPathElement.attributes) - fragments.push(util.format("<%s%s>", htmlPathElement.tagName, attributeString)); + function writeElement(element) { + element.written = true; + var attributeString = generateAttributeString(element.attributes) + fragments.push(util.format("<%s%s>", element.tagName, attributeString)); } function selfClosing(element) { |
