diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-04-01 17:41:19 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-04-01 17:41:19 +0100 |
| commit | ed3b8e8d620405cd813c08ddd73cecd645d67f09 (patch) | |
| tree | e3f81d8c30a7909ee3d4bf2f520bf3635f5b15c9 /lib | |
| parent | bd8b2786247308c7bd82dc3cda627a23b4898958 (diff) | |
Add a proper attributes value for HTML elements
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/html-generator.js | 11 | ||||
| -rw-r--r-- | lib/style-reader.js | 5 | ||||
| -rw-r--r-- | lib/styles.js | 11 |
3 files changed, 11 insertions, 16 deletions
diff --git a/lib/html-generator.js b/lib/html-generator.js index 065d1d2..179d6d0 100644 --- a/lib/html-generator.js +++ b/lib/html-generator.js @@ -79,14 +79,9 @@ function HtmlGenerator() { function writeElement(stackElement) { stackElement.written = true; var element = stackElement.element; - if (element["class"]) { - var attributeString = util.format(' %s="%s"', "class", element["class"]); - } else { - var attributeString = ""; - } - if (element.href) { - attributeString += util.format(' href="%s"', escapeHtml(element.href)); - } + var attributeString = _.map(element.attributes, function(value, key) { + return util.format(' %s="%s"', key, value); + }).join(""); fragments.push(util.format("<%s%s>", element.tagName, attributeString)); } diff --git a/lib/style-reader.js b/lib/style-reader.js index a566826..9e23abd 100644 --- a/lib/style-reader.js +++ b/lib/style-reader.js @@ -33,14 +33,15 @@ function read(string) { capture(lop.rules.zeroOrMore(classRule)), capture(freshRule) ).map(function(tagName, classNames, fresh) { + var attributes = {}; var options = {}; if (classNames.length > 0) { - options["class"] = classNames.join(" "); + attributes["class"] = classNames.join(" "); } if (fresh) { options["fresh"] = true; } - return styles.element(tagName, options); + return styles.element(tagName, attributes, options); }); var styleRule = lop.rules.then( diff --git a/lib/styles.js b/lib/styles.js index cbe36d4..737bdcb 100644 --- a/lib/styles.js +++ b/lib/styles.js @@ -4,8 +4,8 @@ exports.topLevelElement = topLevelElement; exports.elements = elements; exports.element = element; -function topLevelElement(tagName) { - return elements([element(tagName, {fresh: true})]); +function topLevelElement(tagName, attributes) { + return elements([element(tagName, attributes, {fresh: true})]); } function elements(elementStyles) { @@ -18,12 +18,11 @@ function elements(elementStyles) { }); } -function element(tagName, options) { +function element(tagName, attributes, options) { options = options || {}; return { tagName: tagName, - fresh: options.fresh, - "class": options["class"], - href: options.href + attributes: attributes || {}, + fresh: options.fresh }; } |
