Comparing version 0.51.1 to 0.52.0-alpha
@@ -808,3 +808,3 @@ | ||
if (local && 'object' == local.nodeName) { | ||
return convert(json); | ||
return convert(json, local); | ||
} else { | ||
@@ -814,11 +814,15 @@ exports['-old-json'].call(this, json, local, namePrefix); | ||
function convert(obj){ | ||
var ret = new nodes.Object(); | ||
function convert(obj, options){ | ||
var ret = new nodes.Object() | ||
, leaveStrings = options.get('leave-strings').toBoolean(); | ||
for (var key in obj) { | ||
var val = obj[key]; | ||
if ('object' == typeof val) { | ||
ret.set(key, convert(val)); | ||
ret.set(key, convert(val, options)); | ||
} else { | ||
val = utils.coerce(val); | ||
if ('string' == val.nodeName) val = parseString(val.string); | ||
if ('string' == val.nodeName && leaveStrings.isFalse) { | ||
val = parseString(val.string); | ||
} | ||
ret.set(key, val); | ||
@@ -1678,63 +1682,26 @@ } | ||
/** | ||
* Attempt to parse unit `str`. | ||
* Attempt to parse string. | ||
* | ||
* @param {String} str | ||
* @return {Unit} | ||
* @return {Node} | ||
* @api private | ||
*/ | ||
function parseUnit(str){ | ||
var units = require('./../units.js').join('|') | ||
, m = str.match(new RegExp('^(-)?(\\d+\\.\\d+|\\d+|\\.\\d+)(' + units + ')?')) | ||
, n; | ||
if (!m) return; | ||
n = parseFloat(m[2]); | ||
if ('-' == m[1]) n = -n; | ||
return new nodes.Unit(n, m[3]); | ||
} | ||
function parseString(str){ | ||
var Parser = require('../parser') | ||
, parser | ||
, ret; | ||
/** | ||
* Attempt to parse color. | ||
* | ||
* @param {String} str | ||
* @return {RGBA} | ||
* @api private | ||
*/ | ||
function parseColor(str){ | ||
if (str.substr(0,1) === '#') { | ||
// Handle color shorthands (like #abc) | ||
var shorthand = str.length === 4, | ||
m = str.match(shorthand ? /\w/g : /\w{2}/g); | ||
if (!m) return; | ||
m = m.map(function(s) { return parseInt(shorthand ? s+s : s, 16) }); | ||
return new nodes.RGBA(m[0],m[1],m[2],1); | ||
try { | ||
parser = new Parser(str); | ||
parser.state.push('expression'); | ||
ret = new nodes.Expression(); | ||
ret.nodes = parser.parse().nodes; | ||
} catch (e) { | ||
ret = new nodes.Literal(str); | ||
} | ||
else if (str.substr(0,3) === 'rgb'){ | ||
var m = str.match(/([0-9]*\.?[0-9]+)/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); | ||
} | ||
return ret; | ||
} | ||
/** | ||
* 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); | ||
} | ||
/** | ||
* Attempt to parse object node to the javascript object. | ||
@@ -1741,0 +1708,0 @@ * |
@@ -9,14 +9,9 @@ /** | ||
, relative = require('path').relative | ||
, join = require('path').join | ||
, dirname = require('path').dirname | ||
, extname = require('path').extname | ||
, sep = require('path').sep | ||
, utils = require('../utils'); | ||
, extname = require('path').extname; | ||
/** | ||
* Return a url() function with the given `options`. | ||
* Return a url() function that resolves urls. | ||
* | ||
* Options: | ||
* | ||
* - `paths` resolution path(s), merged with general lookup paths | ||
* | ||
* Examples: | ||
@@ -26,6 +21,5 @@ * | ||
* .set('filename', __dirname + '/css/test.styl') | ||
* .define('url', stylus.resolver({ paths: [__dirname + '/public'] })) | ||
* .define('url', stylus.resolver()) | ||
* .render(function(err, css){ ... }) | ||
* | ||
* @param {Object} options | ||
* @return {Function} | ||
@@ -35,38 +29,27 @@ * @api public | ||
module.exports = function(options) { | ||
options = options || {}; | ||
var _paths = options.paths || []; | ||
module.exports = function() { | ||
function url(url) { | ||
// Compile the url | ||
var compiler = new Compiler(url); | ||
var compiler = new Compiler(url) | ||
, filename = url.filename; | ||
compiler.isURL = true; | ||
var url = url.nodes.map(function(node){ | ||
var url = parse(url.nodes.map(function(node){ | ||
return compiler.visit(node); | ||
}).join(''); | ||
}).join('')); | ||
// Parse literal | ||
var url = parse(url) | ||
, literal = new nodes.Literal('url("' + url.href + '")') | ||
, paths = _paths.concat(this.paths) | ||
var literal = new nodes.Literal('url("' + url.href + '")') | ||
, path = url.pathname | ||
, dest = this.options.dest | ||
, tail = '' | ||
, res | ||
, found; | ||
, res; | ||
// Absolute or hash | ||
if (url.protocol || !url.pathname) return literal; | ||
if (url.protocol || !path || '/' == path[0]) return literal; | ||
// Lookup | ||
found = utils.lookup(url.pathname, paths, '', true); | ||
// Failed to lookup | ||
if (!found) return literal; | ||
if (url.search) tail += url.search; | ||
if (url.hash) tail += url.hash; | ||
if (this.includeCSS && extname(found) == '.css') { | ||
return new nodes.Literal(found + tail); | ||
if (this.includeCSS && extname(path) == '.css') { | ||
return new nodes.Literal(path + tail); | ||
} else { | ||
@@ -77,4 +60,3 @@ if (dest && extname(dest) == '.css') { | ||
res = relative(dest || dirname(this.filename), found) + tail; | ||
if ('\\' == sep) res = res.replace(/\\/g, '/'); | ||
res = relative(dest || dirname(this.filename), join(dirname(filename), path)) + tail; | ||
return new nodes.Literal('url("' + res + '")'); | ||
@@ -81,0 +63,0 @@ } |
@@ -141,3 +141,3 @@ | ||
if ('object' == val.first.nodeName) { | ||
str += key + ' ' + this.toBlock.call(val.first); | ||
str += key + ' ' + val.first.toBlock(); | ||
} else { | ||
@@ -149,3 +149,3 @@ switch (key) { | ||
default: | ||
str += key + ':' + val.toString().replace(/ , /g, '\\,') + ';'; | ||
str += key + ':' + toString(val) + ';'; | ||
} | ||
@@ -156,2 +156,11 @@ } | ||
return str; | ||
function toString(node) { | ||
if (node.nodes) { | ||
return node.nodes.map(toString).join(node.isList ? ',' : ' '); | ||
} else if ('literal' == node.nodeName && ',' == node.val) { | ||
return '\\,'; | ||
} | ||
return node.toString(); | ||
} | ||
}; | ||
@@ -158,0 +167,0 @@ |
@@ -523,2 +523,7 @@ /*! | ||
// #a after an ident and newline | ||
if ('color' == this.lookahead(i).type | ||
&& 'newline' == this.lookahead(i - 1).type) | ||
return true; | ||
if (this.looksLikeAttributeSelector(i)) | ||
@@ -837,6 +842,7 @@ return true; | ||
if (this.accept('newline')) continue; | ||
// skip useless indents and comments | ||
next = this.lookahead(2).type; | ||
if ('indent' == this.peek().type | ||
&& ('outdent' == next || 'comment' == next)) { | ||
this.accept('indent'); | ||
&& ~['outdent', 'newline', 'comment'].indexOf(next)) { | ||
this.skip(['indent', 'outdent']); | ||
continue; | ||
@@ -1296,3 +1302,3 @@ } | ||
this.skipSpacesAndComments(); | ||
keyframes = new nodes.Keyframes(this.interpolate(), tok.val); | ||
keyframes = new nodes.Keyframes(this.selectorParts(), tok.val); | ||
this.skipSpacesAndComments(); | ||
@@ -1299,0 +1305,0 @@ |
@@ -58,2 +58,3 @@ /*! | ||
exports.Evaluator = require('./visitor/evaluator'); | ||
exports.Normalizer = require('./visitor/normalizer'); | ||
exports.Compiler = require('./visitor/compiler'); | ||
@@ -60,0 +61,0 @@ |
@@ -16,3 +16,2 @@ | ||
, join = require('path').join | ||
, resolve = require('path').resolve | ||
, glob = require('glob') | ||
@@ -41,3 +40,2 @@ , fs = require('fs'); | ||
* @param {String} ignore | ||
* @param {Boolean} resolveURL | ||
* @return {String} | ||
@@ -47,5 +45,4 @@ * @api private | ||
exports.lookup = function(path, paths, ignore, resolveURL){ | ||
exports.lookup = function(path, paths, ignore){ | ||
var lookup | ||
, method = resolveURL ? resolve : join | ||
, i = paths.length; | ||
@@ -69,3 +66,3 @@ | ||
try { | ||
lookup = method(paths[i], path); | ||
lookup = join(paths[i], path); | ||
if (ignore == lookup) continue; | ||
@@ -72,0 +69,0 @@ fs.statSync(lookup); |
@@ -182,3 +182,5 @@ /*! | ||
break; | ||
case 'charset': | ||
case 'literal': | ||
case 'namespace': | ||
this.buf += this.out(this.visit(node) + '\n', node); | ||
@@ -185,0 +187,0 @@ break; |
@@ -53,3 +53,4 @@ | ||
// Avoid overflows from importing the same file over again | ||
if (file === importStack[importStack.length - 1]) return nodes.null; | ||
if (~importStack.indexOf(file)) | ||
throw new Error('import loop has been found'); | ||
@@ -97,3 +98,3 @@ if (this.options._imports) this.options._imports.push(node.clone()); | ||
importStack.pop(); | ||
if (!this.resolveURL) this.paths.pop(); | ||
this.paths.pop(); | ||
@@ -353,3 +354,3 @@ return ret; | ||
if (keyframes.fabricated) return keyframes; | ||
keyframes.val = this.interpolate(keyframes); | ||
keyframes.val = this.interpolate(keyframes).trim(); | ||
if (val = this.lookup(keyframes.val)) { | ||
@@ -356,0 +357,0 @@ keyframes.val = val.first.string || val.first.name; |
@@ -78,3 +78,3 @@ /*! | ||
map = this.map.toString(); | ||
url = 'data:application/json;base64,' + new Buffer(map).toString('base64'); | ||
url = 'data:application/json;charset=utf-8;base64,' + new Buffer(map).toString('base64'); | ||
} | ||
@@ -81,0 +81,0 @@ if (this.inline || false !== this.comment) |
{ | ||
"name": "stylus", | ||
"description": "Robust, expressive, and feature-rich CSS superset", | ||
"version": "0.51.1", | ||
"version": "0.52.0-alpha", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
343849
13049