diff options
Diffstat (limited to 'lib/html-paths.js')
| -rw-r--r-- | lib/html-paths.js | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/html-paths.js b/lib/html-paths.js index 04bc655..4021887 100644 --- a/lib/html-paths.js +++ b/lib/html-paths.js @@ -1,5 +1,7 @@ var _ = require("underscore"); +var html = require("./html"); + exports.topLevelElement = topLevelElement; exports.elements = elements; exports.element = element; @@ -9,15 +11,27 @@ function topLevelElement(tagName, attributes) { } function elements(elementStyles) { - return elementStyles.map(function(elementStyle) { + return new HtmlPath(elementStyles.map(function(elementStyle) { if (_.isString(elementStyle)) { return element(elementStyle); } else { return elementStyle; } - }); + })); +} + +function HtmlPath(elements) { + this._elements = elements; } +HtmlPath.prototype.wrap = function wrap(children) { + var result = children(); + for (var index = this._elements.length - 1; index >= 0; index--) { + result = this._elements[index].wrapNodes(result); + } + return result; +}; + function element(tagName, attributes, options) { options = options || {}; return new Element(tagName, attributes, options); @@ -44,4 +58,12 @@ Element.prototype.matchesElement = function(element) { return this.tagNames[element.tagName] && _.isEqual(this.attributes || {}, element.attributes || {}); }; +Element.prototype.wrap = function wrap(generateNodes) { + return this.wrapNodes(generateNodes()); +}; + +Element.prototype.wrapNodes = function wrapNodes(nodes) { + return [html.elementWithTag(this, nodes)]; +}; + exports.empty = elements([]); |
