Merge branch 'node-0.1.30'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parents 91805f7, 0cb8d12 · Browse files · 22 files·+181 added−388 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
22 files+181 added−388 removed
- tests:+9 added−109 removed
- other:+172 added−279 removed
Provenance
- Commit
f7d7c4a- Tree
3e32eb5- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent 1
91805f7- Parent 2
0cb8d12
22 files changed+181 added−388 removed
modified:examples/chat/app.js-2 removed
13 unmodified lines1415161718191819202160 unmodified lines13 unmodified lines use(Session, { lifetime: fiveMinutes, reapInterval: oneMinute }) set('root', __dirname)})
require('express/http')
var messages = [], utils = require('express/utils') get('/', function(){60 unmodified linesmodified:examples/upload/app.js+3 added-3 removed
23 unmodified lines24252627282928293031323333343536378 unmodified lines23 unmodified lines } })})
post('/upload', function(){ var self = thispost('/upload', function(){ var self = this; $(this.param('images')).each(function(image){ puts(image.filename + ' -> ' + image.tempfile) self.flash('info', 'Uploaded ' + image.filename) }) }) this.redirect('/upload')})
get('/public/*', function(file){8 unmodified linesmodified:lib/express/plugins/common-logger.js+1 added-1 removed
35 unmodified lines363738394040414243446 unmodified lines35 unmodified lines * Output log data. */ response: function(event) { puts([event.request.headers.host, puts([event.request.connection.remoteAddress, '-', '-', '[' + format(new Date) + ']', '"' + event.request.method.toUpperCase() + ' ' + (event.request.url.pathname || '/') + 6 unmodified linesmodified:lib/express/plugins/view.js+8 added-4 removed
3 unmodified lines4 /**5 * Module dependencies.6 */7 8-var posix = require('posix'),9- utils = require('express/utils')8+var utils = require('express/utils'),9+ fs = require('fs')10 11 /**12 * Supported template engines.13 */48 unmodified lines62 * @api public63 */64 65 render: function(view, options) {66+ 67+ var sys= require('sys');68+ 69 var self = this,70 options = options || {},71 path = set('views') + '/' + view,72 type = path.split('.').slice(-2)[0],3 unmodified lines76 self.contentType(ext)77 function render(content) {78 content = engine[type].render(content, options)79 if (layout)77- self.render(layout + '.' + type + '.' + ext, process.mixin(true, options, {80+ self.render(layout + '.' + type + '.' + ext, utils.mixin(true, options, {81 layout: false,82 locals: {83 body: content84 }3 unmodified lines88 }89 if (set('cache view contents') && self.cache.get(path))90 render(self.cache.get(path))91 else89- posix.cat(path).addCallback(function(content){92+ fs.readFile(path, function(e, content){93+ if (e) throw e94 set('cache view contents') ?95 render(self.cache.set(path, content)) :96 render(content)97 })6 unmodified linesmodified:lib/express/spec/mocks.js+3 added-3 removed
43 unmodified lines44 /**45 * Store _code_ and _headers_.46 */47 48- sendHeader: function(code, headers) {48+ writeHeader: function(code, headers) {49 this.status = code50 this.headers = headers51 },52 53 /**54 * Store _body_.55 */56 57- sendBody: function(body) {57+ write: function(body) {58 this.body = body59 },60 61 /**62 * Flag response as finished.63 */64 65- finish: function() {65+ close: function() {66 this.finished = true67 }68 })69 60 unmodified linesmodified:lib/express/collection.js+8 added-2 removed
1 2 // Express - Collection - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4 /**5+ * Module dependencies.6+ */7+ 8+var utils = require('express/utils')9+10+/**11 * Throw $break in order to stop iteration.12 */13 14 $break = '__break__'482 unmodified lines497 array.push(val)498 return array499 }))500 else495- return $(process.mixin(this.arr, $(other).arr))501+ return $(utils.mixin(this.arr, $(other).arr))502 },503 504 /**505 * Clone the collection.2 unmodified lines508 * @api public509 */510 511 clone: function() {506- return this.merge({})512+ return $(utils.clone(this.arr))513 },514 515 /**516 * Return the value of a random index.33 unmodified linesmodified:lib/express/core.js+51 added-51 removed
1 2 // Express - Core - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4-process.mixin(require('sys'))5-process.mixin(require('express/exceptions'))6-process.mixin(require('express/collection'))7-process.mixin(require('express/event'))8-process.mixin(require('express/request'))9-process.mixin(require('express/plugin'))10-process.mixin(require('express/dsl'))11-4 /**5 * Module dependencies.6 */7 8 var multipart = require('multipart'),9+ utils = require('express/utils'),10 events = require('events'),18- File = require('file').File,19- utils = require('express/utils')20- 11+ fs = require('fs')12+13+utils.mixin(require('sys'))14+utils.mixin(require('express/exceptions'))15+utils.mixin(require('express/collection'))16+utils.mixin(require('express/event'))17+utils.mixin(require('express/request'))18+utils.mixin(require('express/plugin'))19+utils.mixin(require('express/dsl'))20+21 // --- Route22 23 Route = Class({24 183 unmodified lines208 require('http')209 .createServer(function(request, response){210 request.body = ''211 request.setBodyEncoding('binary')212+ var callback= function(error, result) {213+ if(error) { // THIS is the same code as in the 'route' code, needs refactoring214+ if (request.accepts('html') && set('show exceptions'))215+ request.halt(500, require('express/pages/show-exceptions').render(request, error))216+ else217+ request.halt(500)218+ if (set('throw exceptions'))219+ throw error220+ } 221+ else self.route(request, response); 222+ };223 if (request.headers['content-type'] &&224 request.headers['content-type'].indexOf('multipart/form-data') !== -1) {214- var stream = new multipart.Stream(request),215- promise = new events.Promise,216- pendingFiles = 0217- request.params = { post: {}}218- promise.timeout(set('upload timeout') || 5000)219- stream.addListener('part', function(part){220- if (part.filename) {221- var file = new File(part.tempfile = '/tmp/express-' + Number(new Date) + utils.uid(), 'w', { encoding: 'binary' })222- ++pendingFiles223- part.pos = 0224- part.addListener('body', function(chunk){225- file.write(chunk, part.pos, 'binary').addErrback(function(){226- promise.emitError.apply(promise, arguments)227- })228- part.pos += chunk.length229- })230- .addListener('complete', function(){231- file.close().addCallback(function(){232- if (!--pendingFiles)233- promise.emitSuccess()234- }).addErrback(function(){235- promise.emitError.apply(promise, arguments)236- })237- utils.mergeParam(part.name, part, request.params.post)238- })239- }240- else241- part.buf = '',242- part243- .addListener('body', function(chunk){ part.buf += chunk })244- .addListener('complete', function(){245- if (part.buf.length)246- utils.mergeParam(part.name, part.buf, request.params.post)247- })248- }).addListener('complete', function(){249- if (!pendingFiles) promise.emitSuccess()250- promise.addCallback(function(){ self.route(request, response) })251- })225+ var mp= multipart.parse(request);226+ request.params= { post: {}};227+ mp.addListener("partBegin", function (part) { 228+ if( part.filename ) {229+ part.tempfile= '/tmp/express-' + Number(new Date) + utils.uid(); 230+ part.fileStream= fs.createWriteStream( part.tempfile ); 231+ }232+ else part.buf= '';233+ });234+ mp.addListener("partEnd", function (part) { 235+ if( part.name ) { // Not sure why this guard is needed, but otherwise we get an undefined part.name being passed?236+ if( part.fileStream ) { 237+ part.fileStream.close(); 238+ utils.mergeParam(part.name, {filename:part.filename, tempfile:part.tempfile}, request.params.post) 239+ }240+ else {241+ utils.mergeParam(part.name, part.buf, request.params.post) 242+ }243+ }244+ });245+ 246+ mp.addListener("body", function (chunk) {247+ if( mp.part.fileStream ) mp.part.fileStream.write(chunk) ;248+ else part.buf+= chunk;249+ });250+ mp.addListener("error", callback); 251+ mp.addListener("complete", callback);252 }253 else254 request255- .addListener('body', function(chunk){ request.body += chunk })256- .addListener('complete', function(){ self.route(request, response) })255+ .addListener('data', function(chunk){ request.body += chunk })256+ .addListener('end', callback )257 })258 .listen(this.port, this.host, this.backlog)259 puts('Express started at http://' + this.host + ':' + this.port + '/ in ' + Express.environment + ' mode')260 },63 unmodified linesdeleted:lib/express/element-collection.js-179 removed
1-2-// Express - ElementCollection - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3-4-/**5- * Module dependencies.6- */7-8-var libxml = require('libxmljs')9-10-// --- css2xpath11-12-/** version 0.1 2009-04-3013- * @author Andrea Giammarchi14- * @license Mit Style License15- * @project http://code.google.com/p/css2xpath/16- */17-var css2xpath=(function(){var b=[/\[([^\]~\$\*\^\|\!]+)(=[^\]]+)?\]/g,"[@$1$2]",/\s*,\s*/g,"|",/\s*(\+|~|>)\s*/g,"$1",/([a-zA-Z0-9\_\-\*])~([a-zA-Z0-9\_\-\*])/g,"$1/following-sibling::$2",/([a-zA-Z0-9\_\-\*])\+([a-zA-Z0-9\_\-\*])/g,"$1/following-sibling::*[1]/self::$2",/([a-zA-Z0-9\_\-\*])>([a-zA-Z0-9\_\-\*])/g,"$1/$2",/\[([^=]+)=([^'|"][^\]]*)\]/g,"[$1='$2']",/(^|[^a-zA-Z0-9\_\-\*])(#|\.)([a-zA-Z0-9\_\-]+)/g,"$1*$2$3",/([\>\+\|\~\,\s])([a-zA-Z\*]+)/g,"$1//$2",/\s+\/\//g,"//",/([a-zA-Z0-9\_\-\*]+):first-child/g,"*[1]/self::$1",/([a-zA-Z0-9\_\-\*]+):last-child/g,"$1[not(following-sibling::*)]",/([a-zA-Z0-9\_\-\*]+):only-child/g,"*[last()=1]/self::$1",/([a-zA-Z0-9\_\-\*]+):empty/g,"$1[not(*) and not(normalize-space())]",/([a-zA-Z0-9\_\-\*]+):not\(([^\)]*)\)/g,function(f,e,d){return e.concat("[not(",a(d).replace(/^[^\[]+\[([^\]]*)\].*$/g,"$1"),")]")},/([a-zA-Z0-9\_\-\*]+):nth-child\(([^\)]*)\)/g,function(f,e,d){switch(d){case"n":return e;case"even":return"*[position() mod 2=0 and position()>=0]/self::"+e;case"odd":return e+"[(count(preceding-sibling::*) + 1) mod 2=1]";default:d=(d||"0").replace(/^([0-9]*)n.*?([0-9]*)$/,"$1+$2").split("+");d[1]=d[1]||"0";return"*[(position()-".concat(d[1],") mod ",d[0],"=0 and position()>=",d[1],"]/self::",e)}},/:contains\(([^\)]*)\)/g,function(e,d){return"[contains(string(.),'"+d+"')]"},/\[([a-zA-Z0-9\_\-]+)\|=([^\]]+)\]/g,"[@$1=$2 or starts-with(@$1,concat($2,'-'))]",/\[([a-zA-Z0-9\_\-]+)\*=([^\]]+)\]/g,"[contains(@$1,$2)]",/\[([a-zA-Z0-9\_\-]+)~=([^\]]+)\]/g,"[contains(concat(' ',normalize-space(@$1),' '),concat(' ',$2,' '))]",/\[([a-zA-Z0-9\_\-]+)\^=([^\]]+)\]/g,"[starts-with(@$1,$2)]",/\[([a-zA-Z0-9\_\-]+)\$=([^\]]+)\]/g,function(f,e,d){return"[substring(@".concat(e,",string-length(@",e,")-",d.length-3,")=",d,"]")},/\[([a-zA-Z0-9\_\-]+)\!=([^\]]+)\]/g,"[not(@$1) or @$1!=$2]",/#([a-zA-Z0-9\_\-]+)/g,"[@id='$1']",/\.([a-zA-Z0-9\_\-]+)/g,"[contains(concat(' ',normalize-space(@class),' '),' $1 ')]",/\]\[([^\]]+)/g," and ($1)"],c=b.length;return function a(e){var d=0;while(d<c){e=e.replace(b[d++],b[d++])}return"//"+e}})();18-19-// --- ElementCollection20-21-ElementCollection = Collection.extend({22- 23- /**24- * Initialize with string of _markup_.25- *26- * @param {string} markup27- * @api private28- */29- 30- init: function(markup) {31- if (typeof markup != 'string')32- return this.__super__(markup)33- if (!(/<html>/.test(markup))) 34- markup = '<html><body>' + markup + '</body></html>'35- this.document = libxml.parseHtmlString(markup)36- this.arr = [this.document.root()]37- },38- 39- /**40- * Return the first element's name.41- *42- * @return {string}43- * @api public44- */45- 46- name: function() {47- return this.at(0).name()48- },49- 50- /**51- * Search child elements with the given _xpath_.52- *53- * @param {string} xpath54- * @return {ElementCollection}55- * @api public56- */57- 58- xpath: function(xpath) {59- // TODO: refactor with flatten()60- return $(this.reduce([], function(array, e){61- $(e.find(xpath)).each(function(child){62- array.push(child)63- })64- return array65- }))66- },67- 68- /**69- * Search child elements with the given css _selector_70- *71- * @param {string} selector72- * @return {ElementCollection}73- * @api public74- */75- 76- search: function(selector) {77- return this.xpath(css2xpath(selector))78- },79- 80- /**81- * Return collection of children.82- *83- * @return {ElementCollection}84- * @api public85- */86- 87- children: function() {88- // TODO: refactor with flatten()89- return $(this.reduce([], function(array, e){90- $(e.children()).each(function(child){91- array.push(child)92- })93- return array94- }))95- },96- 97- /**98- * Return collection of parents.99- *100- * @return {ElementCollection}101- * @api public102- */103- 104- parents: function() {105- return this.map(function(e){106- return e.parent()107- })108- },109- 110- /**111- * Return the first element's parent.112- *113- * @return {ElementCollection}114- * @api public115- */116- 117- parent: function() {118- return $([this.at(0).parent()])119- },120- 121- /**122- * Return the prev element.123- *124- * @return {ElementCollection}125- * @api public126- */127- 128- prev: function() {129- return $([this.at(0).prevSibling()])130- },131- 132- /**133- * Return the next element.134- *135- * @return {ElementCollection}136- * @api public137- */138- 139- next: function() {140- return $([this.at(0).nextSibling()])141- },142- 143- /**144- * Return the first element's text content.145- *146- * @return {string}147- * @api public148- */149- 150- text: function() {151- return this.at(0).text()152- },153- 154- /**155- * Convert collection to a string.156- *157- * @return {string}158- * @api public159- */160- 161- toString: function() {162- if (this.at(0) && this.at(0).doc)163- return '[Collection <elements>]'164- return this.__super__()165- }166-})167-168-/**169- * Add markup support to $().170- *171- * @param {object} arr172- * @return {Collection, ElementCollection}173- * @api public174- */175- 176-var $ = exports.$ = function(arr) {177- if (arr instanceof Collection) return arr178- return new ElementCollection(arr)179-}modified:lib/express/event.js-1 removed
1 2 // Express - Event - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3-3 exports.Event = Class({4 5 /**6 * Initialize with event _name_ and optional _data_.22 unmodified linesmodified:lib/express/http.js+2 added-2 removed
36 unmodified lines37 headers['content-length'] = data.length38 headers['content-type'] = 'application/x-www-form-urlencoded'39 }40 var request = client.request(method, path + search + hash, headers)41- if (data) request.sendBody(data)42- request.finish(function(response){41+ if (data) request.write(data)42+ request.close(function(response){43 if (response.statusCode < 200 || response.statusCode >= 400)44 promise.emitError(new Error('request failed with status ' + response.statusCode + ' "' + http.STATUS_CODES[response.statusCode] + '"'))45 else if (response.statusCode >= 300 && response.statusCode < 400)46 request(method, response.headers.location, headers, data, promise)33 unmodified linesmodified:lib/express/plugin.js+2 added-2 removed
1-1+var utils = require('express/utils');2 // Express - Plugin - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4 /**5 * Push _plugin_ with _options_ to the plugin stack.30 unmodified lines36 */37 38 init: function(options) {39 if (options)40- process.mixin(this, options)40+ utils.mixin(this, options)41 },42 43 /**44 * Trigger handler for the given _event_.11 unmodified linesmodified:lib/express/plugins.js+10 added-10 removed
1 2 // Express - Plugins - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3-4-process.mixin(require('express/plugins/hooks'))5-process.mixin(require('express/plugins/flash'))6-process.mixin(require('express/plugins/cache'))7-process.mixin(require('express/plugins/cookie'))8-process.mixin(require('express/plugins/session'))9-process.mixin(require('express/plugins/profiler'))10-process.mixin(require('express/plugins/common-logger'))11-process.mixin(require('express/plugins/content-length'))12-process.mixin(require('express/plugins/method-override'))3+var utils = require('express/utils');4+utils.mixin(require('express/plugins/hooks'))5+utils.mixin(require('express/plugins/flash'))6+utils.mixin(require('express/plugins/cache'))7+utils.mixin(require('express/plugins/cookie'))8+utils.mixin(require('express/plugins/session'))9+utils.mixin(require('express/plugins/profiler'))10+utils.mixin(require('express/plugins/common-logger'))11+utils.mixin(require('express/plugins/content-length'))12+utils.mixin(require('express/plugins/method-override'))modified:lib/express/request.js+5 added-4 removed
7 unmodified lines8 var StaticFile = require('express/static').File,9 statusBodies = require('http').STATUS_CODES,10 queryString = require('querystring'),11 mime = require('express/mime'),12+ utils= require('express/utils'),13 url = require('url')14 15 // --- InvalidStatusCode16 46 unmodified lines63 * @api private64 */65 66 init: function(request, response) {66- process.mixin(true, this, request)67+ utils.mixin(true, this, request)68 response.headers = {}69 this.response = response70 this.url = url.parse(this.url)71 this.url.pathname = exports.normalizePath(this.url.pathname)119 unmodified lines191 this.response.body = body192 this.trigger('response')193 if (typeof this.response.body != 'string') throw new InvalidResponseBody(this)194 if (typeof this.response.status != 'number') throw new InvalidStatusCode(this.response.status)194- this.response.sendHeader(this.response.status, this.response.headers)195- this.response.sendBody(this.response.body, encoding)196- this.response.finish()195+ this.response.writeHeader(this.response.status, this.response.headers)196+ this.response.write(this.response.body, encoding)197+ this.response.close()198 },199 200 /**201 * Set Content-Type header to the mime type74 unmodified linesmodified:lib/express/static.js+5 added-3 removed
1 2 // Express - Static - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3 4 var path = require('path'),5- posix = require('posix')5+ fs = require('fs')6 7 // --- InvalidPathError8 9 InvalidPathError = ExpressError.extend({38 unmodified lines48 return request.contentType(cache.type),49 request.halt(200, cache.content, 'binary')50 path.exists(file, function(exists){51 if (!exists) return request.halt()52- posix.stat(file).addCallback(function(stats){52+ fs.stat(file, function(e, stats){53+ if (e) throw e54 if (!stats.isFile()) return request.halt()54- posix.cat(file, 'binary').addCallback(function(content){55+ fs.readFile(file, 'binary', function(e, content){56+ if (e) throw e57 request.contentType(file)58 if (set('cache static files'))59 request.cache.set(file, { type: file, content: content })60 request.halt(200, content, 'binary')5 unmodified linesmodified:lib/express/utils.js+76 added-1 removed
129 unmodified lines130 params = params[key]131 return parts[key]132 })133 return orig134-}134+}135+136+/**137+ * Return a clone of _obj_.138+ *139+ * @param {mixed} obj140+ * @return {mixed}141+ * @api public142+ */143+144+function Clone() {}145+exports.clone = function(obj) {146+ Clone.prototype = obj147+ return new Clone148+}149+150+// From jQuery.extend in the jQuery JavaScript Library v1.3.2151+// Copyright (c) 2009 John Resig152+// Dual licensed under the MIT and GPL licenses.153+// http://docs.jquery.com/License154+// Modified for node.js (formely for copying properties correctly)155+exports.mixin = function() {156+ // copy reference to target object157+ var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, source;158+159+ // Handle a deep copy situation160+ if ( typeof target === "boolean" ) {161+ deep = target;162+ target = arguments[1] || {};163+ // skip the boolean and the target164+ i = 2;165+ }166+167+ // Handle case when target is a string or something (possible in deep copy)168+ if ( typeof target !== "object" && !(typeof target === 'function') )169+ target = {};170+171+ // mixin process itself if only one argument is passed172+ if ( length == i ) {173+ target = GLOBAL;174+ --i;175+ }176+177+ for ( ; i < length; i++ ) {178+ // Only deal with non-null/undefined values179+ if ( (source = arguments[i]) != null ) {180+ // Extend the base object181+ Object.getOwnPropertyNames(source).forEach(function(k){182+ var d = Object.getOwnPropertyDescriptor(source, k) || {value: source[k]};183+ if (d.get) {184+ target.__defineGetter__(k, d.get);185+ if (d.set) {186+ target.__defineSetter__(k, d.set);187+ }188+ }189+ else {190+ // Prevent never-ending loop191+ if (target !== d.value) {192+193+ if (deep && d.value && typeof d.value === "object") {194+ target[k] = exports.mixin(deep,195+ // Never move original objects, clone them196+ target[k] || (d.value.length != null ? [] : {})197+ , d.value);198+ }199+ else {200+ target[k] = d.value;201+ }202+ }203+ }204+ });205+ }206+ }207+ // Return the modified object208+ return target;209+};deleted:spec/support/libxmljsnot shown
Its text is not shown, deleted.
modified:spec/node.js+4 added-23 removed
1 2-require.paths.unshift('spec', 'lib', 'spec/lib', 'spec/support/libxmljs')2+require.paths.unshift('spec', 'lib', 'spec/lib')3 require("jspec")4 require("express")5 require("express/spec")6 7-quit = process.exit7 print = puts8+quit = process.exit9+readFile = require('fs').readFileSync10 10-readFile = function(path) {11- var result12- require('posix')13- .cat(path, "utf8")14- .addCallback(function(contents){ result = contents })15- .addErrback(function(){ throw new Error("failed to read file `" + path + "'") })16- .wait()17- return result18-}19-11 function run(specs) {12 specs.forEach(function(spec){13 JSpec.exec('spec/spec.' + spec + '.js')14 })19 unmodified lines34 'plugins.hooks',35 'plugins.cookie',36 'plugins.session',37 'plugins.flash',47- ],48- dependant: [49- 'element-collection'50- ]38+ ]39 }40 41 switch (process.ARGV[2]) {54- case 'independant':55- run(specs.independant)56- break57- case 'dependant':58- run(specs.dependant)59- break42 case 'all':43 run(specs.independant)62- run(specs.dependant)44 break45 default: 46 run([process.ARGV[2]])47 }3 unmodified linesmodified:spec/spec.collection.js+2 added
382 unmodified lines383 var a = $([1,2,3])384 var b = a.clone()385 a.should.not.equal b386 b.arr.should.eql [1,2,3]387+ b.arr.should.not.equal a.arr388 end389 390 it 'should clone an object collection'391 var a = $({ foo: 'bar' })392 var b = a.clone()393 a.should.not.equal b394 b.arr.should.eql { foo: 'bar' }395+ b.arr.should.not.equal a.arr396 end397 end398 399 describe '#sample()'75 unmodified linesdeleted:spec/spec.element-collection.js-83 removed
1-2-process.mixin(require('express/collection'))3-process.mixin(require('express/element-collection'))4-5-describe 'Express'6- describe 'ElementCollection'7- 8- describe '$("markup string")'9- it 'should return a ElementCollection'10- $('<p>foo</p>').should.be_an_instance_of Collection11- $('<p>foo</p>').should.be_an_instance_of ElementCollection12- end13- 14- it 'should wrap with <html><body>.. when not present'15- $('<p>foo</p>').at(0).name().should.eql 'html'16- end17- 18- it 'should not wrap with <html><body> when already present'19- $('<html><body></body></html>').at(0).name().should.eql 'html'20- end21- end22- 23- describe '#name()'24- it 'should return the first elements name'25- $('<html><body></body></html>').name().should.eql 'html'26- end27- end28- 29- describe '#xpath()'30- it 'should find children matching the given xpath'31- $('<li>1</li><li>2</li>').xpath('descendant-or-self::li').length().should.eql 232- $('<li>1</li><li>2</li>').xpath('descendant-or-self::li').at(0).name().should.eql 'li'33- var items = $('<li><p>Foo</p></li><li><p>Bar</p></li>').xpath('descendant-or-self::li')34- items.xpath('descendant-or-self::p').length().should.eql 235- end36- end37- 38- describe '#search()'39- it 'should find children matching the given css selector'40- $('<ul><li>foo</li><li>bar</li></ul>').search('ul > li:nth-child(2)').text().should.eql 'bar'41- end42- end43- 44- describe '#children()'45- it 'should return children'46- $('<p><em>foo</em><strong>bar</strong></p>').children().length().should.eql 147- $('<p><em>foo</em><strong>bar</strong></p>').xpath('descendant-or-self::p').children().length().should.eql 248- end49- end50- 51- describe '#parents()'52- it 'should return parents'53- $('<ul><li></li></ul><ul><li></li></ul>').xpath('descendant-or-self::li').parents().length().should.eql 254- $('<ul><li></li></ul><ul><li></li></ul>').xpath("descendant-or-self::*/*[name() = 'ul' and (position() = 1)]/descendant::li").parents().length().should.eql 155- end56- end57- 58- describe '#parent()'59- it 'should return the first parent'60- $('<ul><li></li></ul><ul><li></li></ul>').xpath('descendant-or-self::li').parent().length().should.eql 161- end62- end63- 64- describe '#text()'65- it 'should return an elements text'66- $('<p>foo bar</p>').text().should.eql 'foo bar'67- end68- end69- 70- describe '#next()'71- it 'should return the next element'72- $('<em>foo</em><p>bar</p>').xpath('descendant-or-self::em').next().text().should.eql 'bar'73- end74- end75- 76- describe '#prev()'77- it 'should return the previous element'78- $('<em>foo</em><p>bar</p>').xpath('descendant-or-self::p').prev().text().should.eql 'foo'79- end80- end81- 82- end83-endmodified:.gitmodules-3 removed
1-[submodule "spec/support/libxmljs"]2- path = spec/support/libxmljs3- url = git://github.com/sprsquish/libxmljs.git1 [submodule "lib/support/haml"]2 path = lib/support/haml3 url = git://github.com/creationix/haml-js.git4 [submodule "lib/support/js-oo"]5 unmodified linesmodified:Makefile+1 added-10 removed
4 unmodified lines5 6 init:7 @git submodule init && git submodule update8 9-test: init spec/support/libxmljs/libxmljs.node9+test: init10 @$(NODE) spec/node.js all11 12-test-independant: init13- @$(NODE) spec/node.js independant14- 15-test-dependant: init spec/support/libxmljs/libxmljs.node16- @$(NODE) spec/node.js dependant17- 12 app: app-chat13 14 app-chat:15 @$(NODE) examples/chat/app.js4 unmodified lines20 benchmark:21 @$(NODE) benchmarks/collection.js22 @$(NODE) benchmarks/views.js23 30-spec/support/libxmljs/libxmljs.node:31- @scons -C spec/support/libxmljs libxmljs.node32- 24 .PHONY: init test benchmark appmodified:Readme.md-1 removed
19 unmodified lines20 * Test helpers (mock requests etc)21 * Environment based configuration22 * Light-weight JavaScript class implementation via js-oo23 * Collections and chainable iterators24- * ElementCollections / markup parsing via libxmljs and css selector traversal support via css2xpath24 * View support (ejs, haml, sass, etc)25 26 ## Installation27 112 unmodified lines