* @api private
*/
init: function(markup) {
if (typeof markup != 'string')
return this.__super__(markup)
if (!(/<html>/.test(markup)))
markup = '<html><body>' + markup + '</body></html>'
this.document = libxml.parseString(markup)
this.arr = [this.document.root()]
return this.at(0).name()
},
/**
* Convert collection to a string.
* Search child elements with the given _xpath_.
*
* @return {string}
* @param {string} xpath
* @return {ElementCollection}
* @api public
*/
xpath: function(xpath) {
return $(this.reduce([], function(array, e){
$(e.find(xpath)).each(function(child){
array.push(child)
})
return array
}))
},
toString: function() {
return '[ElementCollection ' + this.arr + ']'
if (this.at(0) && this.at(0).doc)
return '[Collection <elements>]'
return this.__super__()
}
})
/**
* @api public
*/
var $ = exports.$ = function(arr) {
if (typeof arr == 'string') return new ElementCollection(arr)
return require('express/collection').$(arr)
if (arr instanceof Collection) return arr
return new ElementCollection(arr)
}
No newline at end of file
No newline at end of file