Comparing version 0.36.1 to 0.37.0
@@ -111,3 +111,3 @@ | ||
buf = new Buffer(this.length); | ||
fs.readSync(this.fd, buf, 0, this.length); | ||
fs.readSync(this.fd, buf, 0, this.length, 0); | ||
offset = 4; | ||
@@ -146,3 +146,3 @@ blockSize = buf[offset] << 8 | buf[offset + 1]; | ||
buf = new Buffer(offset); | ||
fs.readSync(this.fd, buf, 0, offset); | ||
fs.readSync(this.fd, buf, 0, offset, 0); | ||
buf = buf.toString('utf8'); | ||
@@ -149,0 +149,0 @@ parser = sax.parser(true); |
@@ -17,2 +17,3 @@ | ||
, units = require('../units') | ||
, colors = require('../colors') | ||
, path = require('path') | ||
@@ -406,8 +407,19 @@ , fs = require('fs'); | ||
* @param {String} path | ||
* @param {Boolean} [local] | ||
* @param {String} [namePrefix] | ||
* @api public | ||
*/ | ||
exports.json = function(path){ | ||
exports.json = function(path, local, namePrefix){ | ||
utils.assertString(path, 'path'); | ||
if (namePrefix) { | ||
utils.assertString(namePrefix, 'namePrefix'); | ||
namePrefix = namePrefix.val; | ||
} else { | ||
namePrefix = ''; | ||
} | ||
local = local ? local.toBoolean() : new nodes.Boolean(local); | ||
var scope = local.isTrue ? this.currentScope : this.global.scope; | ||
// lookup | ||
@@ -432,4 +444,4 @@ path = path.string; | ||
val = utils.coerce(val); | ||
if ('string' == val.nodeName) val = parseUnit(val.string) || new nodes.Literal(val.string); | ||
this.global.scope.add({ name: name, val: val }); | ||
if ('string' == val.nodeName) val = parseUnit(val.string) || parseColor(val.string) || new nodes.Literal(val.string); | ||
scope.add({ name: namePrefix + name, val: val }); | ||
} | ||
@@ -1028,1 +1040,28 @@ } | ||
} | ||
/** | ||
* Attempt to parse color | ||
* @param {String} str | ||
* @return {RGBA} | ||
* @api public | ||
*/ | ||
function parseColor(str){ | ||
if (str.substr(0,1) === '#'){ | ||
var m = str.match(/\w{2}/g); | ||
if (!m) return; | ||
m = m.map(function(s){ return parseInt(s, 16) }); | ||
return new nodes.RGBA(m[0],m[1],m[2],1); | ||
} | ||
else if (str.substr(0,3) === 'rgb'){ | ||
var m = str.match(/(\d\.*\d+)/g); | ||
if (!m) return; | ||
m = m.map(function(s){return parseFloat(s, 10)}); | ||
return new nodes.RGBA(m[0], m[1], m[2], m[3] || 1); | ||
} | ||
else { | ||
var rgb = colors[str]; | ||
if (!rgb) return; | ||
return new nodes.RGBA(rgb[0], rgb[1], rgb[2], 1); | ||
} | ||
} |
@@ -10,2 +10,3 @@ /** | ||
, dirname = require('path').dirname | ||
, extname = require('path').extname | ||
, utils = require('../utils'); | ||
@@ -60,3 +61,7 @@ | ||
return new nodes.Literal('url("' + relative(dirname(this.filename), found) +'")'); | ||
if (this.includeCSS && extname(found) == '.css') { | ||
return new nodes.Literal(found); | ||
} else { | ||
return new nodes.Literal('url("' + relative(dirname(this.filename), found) +'")'); | ||
} | ||
}; | ||
@@ -63,0 +68,0 @@ |
@@ -94,3 +94,3 @@ | ||
+ this.fn.toString() | ||
.match(/^function *\((.*?)\)/) | ||
.match(/^function *\w*\((.*?)\)/) | ||
.slice(1) | ||
@@ -97,0 +97,0 @@ .join(', ') |
@@ -118,2 +118,3 @@ | ||
var expr = new nodes.Expression; | ||
val = val.clone(); | ||
val.val = -val.val; | ||
@@ -120,0 +121,0 @@ expr.push(this); |
@@ -662,3 +662,4 @@ | ||
, found | ||
, literal; | ||
, literal | ||
, index; | ||
@@ -691,4 +692,10 @@ this.return--; | ||
found = utils.lookup(path, this.paths, this.filename); | ||
found = found || utils.lookup(join(name, 'index.styl'), this.paths, this.filename); | ||
if (!found) { | ||
found = utils.lookup(join(name, 'index.styl'), this.paths, this.filename); | ||
index = true; | ||
} | ||
// Throw if import failed | ||
if (!found) throw new Error('failed to locate @import file ' + path); | ||
// Expose imports | ||
@@ -706,5 +713,2 @@ imported.path = found; | ||
// Throw if import failed | ||
if (!found) throw new Error('failed to locate @import file ' + path); | ||
// Parse the file | ||
@@ -735,3 +739,3 @@ importStack.push(found); | ||
importStack.pop(); | ||
if (importStack.length) this.paths.pop(); | ||
if (importStack.length || index) this.paths.pop(); | ||
@@ -738,0 +742,0 @@ return ret; |
{ "name": "stylus" | ||
, "description": "Robust, expressive, and feature-rich CSS superset" | ||
, "version": "0.36.1" | ||
, "version": "0.37.0" | ||
, "author": "TJ Holowaychuk <tj@vision-media.ca>" | ||
@@ -5,0 +5,0 @@ , "keywords": ["css", "parser", "style", "stylesheets", "jade", "language"] |
Sorry, the diff of this file is not supported yet
242207
9166