Comparing version 0.39.4 to 0.40.0
@@ -383,3 +383,3 @@ | ||
/** | ||
* Convert a .json file into stylus variables | ||
* Convert a .json file into stylus variables or object. | ||
* Nested variable object keys are joined with a dash (-) | ||
@@ -399,3 +399,3 @@ * | ||
* json('media-queries.json') | ||
* | ||
* | ||
* @media small | ||
@@ -406,3 +406,7 @@ * // => @media screen and (max-width:400px) | ||
* // => @media screen and (min-width:600px) and (orientation:landscape) | ||
* | ||
* | ||
* vars = json('vars.json', { hash: true }) | ||
* body | ||
* width: vars.width | ||
* | ||
* @param {String} path | ||
@@ -417,2 +421,39 @@ * @param {Boolean} [local] | ||
// lookup | ||
path = path.string; | ||
var found = utils.lookup(path, this.options.paths, this.options.filename); | ||
if (!found) throw new Error('failed to locate .json file ' + path); | ||
// read | ||
var json = JSON.parse(fs.readFileSync(found, 'utf8')); | ||
if (local && 'object' == local.nodeName) { | ||
return convert(json); | ||
} else { | ||
exports['-old-json'].call(this, json, local, namePrefix); | ||
} | ||
function convert(obj){ | ||
var ret = new nodes.Object(); | ||
for (var key in obj) { | ||
var val = obj[key]; | ||
if ('object' == typeof val) { | ||
ret.set(key, convert(val)); | ||
} else { | ||
val = utils.coerce(val); | ||
if ('string' == val.nodeName) val = parseString(val.string); | ||
ret.set(key, val); | ||
} | ||
} | ||
return ret; | ||
} | ||
}; | ||
/** | ||
* Old `json` BIF. | ||
* | ||
* @api private | ||
*/ | ||
exports['-old-json'] = function(json, local, namePrefix){ | ||
if (namePrefix) { | ||
@@ -427,10 +468,3 @@ utils.assertString(namePrefix, 'namePrefix'); | ||
// lookup | ||
path = path.string; | ||
var found = utils.lookup(path, this.options.paths, this.options.filename); | ||
if (!found) throw new Error('failed to locate .json file ' + path); | ||
// read | ||
var str = fs.readFileSync(found, 'utf8'); | ||
convert.call(this, JSON.parse(str)); | ||
convert(json); | ||
return; | ||
@@ -444,6 +478,6 @@ | ||
if ('object' == typeof val) { | ||
convert.call(this, val, name); | ||
convert(val, name); | ||
} else { | ||
val = utils.coerce(val); | ||
if ('string' == val.nodeName) val = parseUnit(val.string) || parseColor(val.string) || new nodes.Literal(val.string); | ||
if ('string' == val.nodeName) val = parseString(val.string); | ||
scope.add({ name: namePrefix + name, val: val }); | ||
@@ -1059,3 +1093,3 @@ } | ||
* @return {Unit} | ||
* @api public | ||
* @api private | ||
*/ | ||
@@ -1072,7 +1106,7 @@ | ||
/** | ||
* Attempt to parse color | ||
* Attempt to parse color. | ||
* | ||
* @param {String} str | ||
* @return {RGBA} | ||
* @api public | ||
* @api private | ||
*/ | ||
@@ -1102,1 +1136,13 @@ | ||
} | ||
/** | ||
* Attempt to parse string. | ||
* | ||
* @param {String} str | ||
* @return {Unit|RGBA|Literal} | ||
* @api private | ||
*/ | ||
function parseString(str){ | ||
return parseUnit(str) || parseColor(str) || new nodes.Literal(str); | ||
} |
@@ -151,3 +151,3 @@ | ||
/** | ||
* Check if the current token is a part of class selector. | ||
* Check if the current token is a part of selector. | ||
* | ||
@@ -159,3 +159,12 @@ * @return {Boolean} | ||
isPartOfSelector: function() { | ||
return !!(this.prev && '.' == this.prev.type); | ||
switch (this.prev && this.prev.type) { | ||
// .or | ||
case '.': | ||
// #for | ||
case 'color': | ||
// [is] | ||
case '[': | ||
return true; | ||
} | ||
return false; | ||
}, | ||
@@ -162,0 +171,0 @@ |
@@ -395,3 +395,4 @@ | ||
if ('=' == this.lookahead(i).type && '{' == this.lookahead(i + 1).type) | ||
if (('=' == this.lookahead(i).type || 'function' == this.lookahead(i).type) | ||
&& '{' == this.lookahead(i + 1).type) | ||
return false; | ||
@@ -979,3 +980,4 @@ | ||
while (']' != this.lookahead(i++).type | ||
&& 'selector' != this.lookahead(i).type) ; | ||
&& 'selector' != this.lookahead(i).type | ||
&& 'eos' != this.lookahead(i).type) ; | ||
isSelector = this.looksLikeSelector() && this.stateAllowsSelector(); | ||
@@ -982,0 +984,0 @@ if ('=' == this.lookahead(i).type || ('[' == this.lookahead(i).type && !isSelector)) { |
@@ -90,13 +90,9 @@ | ||
if (!fn) { | ||
this.emit('end', css); | ||
return css; | ||
} else { | ||
if (!this.listeners('end').length) { | ||
return fn(null, css); | ||
} | ||
this.emit('end', css, function(err, css) { | ||
fn(err, css); | ||
}); | ||
var listeners = this.listeners('end'); | ||
if (fn) listeners.push(fn); | ||
for (var i = 0, len = listeners.length; i < len; i++) { | ||
var ret = listeners[i](null, css); | ||
if (ret) css = ret; | ||
} | ||
if (!fn) return css; | ||
} catch (err) { | ||
@@ -103,0 +99,0 @@ var options = {}; |
@@ -480,3 +480,2 @@ | ||
, right = this.visit(binop.right); | ||
this.return--; | ||
@@ -487,2 +486,3 @@ // HACK: ternary | ||
: null; | ||
this.return--; | ||
@@ -489,0 +489,0 @@ // Operate |
{ | ||
"name": "stylus", | ||
"description": "Robust, expressive, and feature-rich CSS superset", | ||
"version": "0.39.4", | ||
"version": "0.40.0", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
253248
9621