General housecleaning, removing js

This commit is contained in:
Tom MacWright 2012-04-30 17:49:39 -04:00
parent 70d5240402
commit c7b7eca95d
5 changed files with 18 additions and 88 deletions

View File

@ -5,8 +5,8 @@ tree.functions = {
return this.rgba(r, g, b, 1.0);
},
rgba: function (r, g, b, a) {
var rgb = [r, g, b].map(function (c) { return number(c); }),
a = number(a);
var rgb = [r, g, b].map(function (c) { return number(c); });
a = number(a);
return new tree.Color(rgb, a);
},
hsl: function (h, s, l) {
@ -117,9 +117,6 @@ tree.functions = {
greyscale: function (color) {
return this.desaturate(color, new tree.Dimension(100));
},
e: function (str) {
return new tree.Anonymous(str instanceof tree.JavaScript ? str.evaluated : str);
},
'%': function (quoted /* arg, arg, ...*/) {
var args = Array.prototype.slice.call(arguments, 1),
str = quoted.value;

View File

@ -50,7 +50,7 @@ var carto = {
}
};
[ 'alpha', 'anonymous', 'call', 'color', 'comment', 'definition', 'dimension',
[ 'anonymous', 'call', 'color', 'comment', 'definition', 'dimension',
'directive', 'element', 'expression', 'filterset', 'filter',
'keyword', 'layer', 'mixin', 'operation', 'quoted',
'reference', 'rule', 'ruleset', 'selector', 'style', 'url', 'value',

View File

@ -196,7 +196,7 @@ carto.Parser = function Parser(env) {
for (var n = err.index; n >= 0 && einput.charAt(n) !== '\n'; n--) {
err.column++;
}
return new Error(_('<%=filename%>:<%=line%>:<%=column%> <%=message%>').template(err));
return new Error(_('<%=filename%>:<%=line%>:<%=column%> <%=message%>').template(err));
}
this.env = env = env || {};
@ -395,18 +395,18 @@ carto.Parser = function Parser(env) {
var node, root = [];
while ((node = $(this.mixin.definition) || $(this.rule) || $(this.ruleset) ||
$(this.mixin.call) || $(this.comment))
|| $(/^[\s\n]+/) || (node = $(this.invalid))) {
$(this.mixin.call) || $(this.comment)) ||
$(/^[\s\n]+/) || (node = $(this.invalid))) {
node && root.push(node);
}
return root;
},
invalid: function () {
var chunk;
var chunk = $(/^[^;\n]*[;\n]/);
// To fail gracefully, match everything until a semicolon or linebreak.
if (chunk = $(/^[^;\n]*[;\n]/)) {
if (chunk) {
return new(tree.Invalid)(chunk, memo);
}
},
@ -445,8 +445,8 @@ carto.Parser = function Parser(env) {
},
comparison: function() {
var str;
if (str = $(/^=|!=|<=|>=|<|>/)) {
var str = $(/^=|!=|<=|>=|<|>/);
if (str) {
return str;
}
},
@ -460,8 +460,8 @@ carto.Parser = function Parser(env) {
// and then contain numbers, underscores, and letters.
//
keyword: function() {
var k;
if (k = $(/^[A-Za-z-]+[A-Za-z-0-9_]*/)) { return new tree.Keyword(k) }
var k = $(/^[A-Za-z-]+[A-Za-z-0-9_]*/);
if (k) { return new tree.Keyword(k); }
},
//
@ -492,7 +492,7 @@ carto.Parser = function Parser(env) {
while (arg = $(this.expression)) {
args.push(arg);
if (! $(',')) { break }
if (! $(',')) { break; }
}
return args;
},
@ -571,21 +571,6 @@ carto.Parser = function Parser(env) {
if (value = $(/^(-?\d*\.?\d+)(px|%|em|pc|ex|in|deg|s|ms|pt|cm|mm|rad|grad|turn)?/)) {
return new tree.Dimension(value[1], value[2], memo);
}
},
//
// JavaScript code to be evaluated
//
// `window.location.href`
//
javascript: function() {
var str;
if (input.charAt(i) !== '`') { return }
if (str = $(/^`([^`]*)`/)) {
return new tree.JavaScript(str[1], i);
}
}
},
@ -597,7 +582,7 @@ carto.Parser = function Parser(env) {
variable: function() {
var name;
if (input.charAt(i) === '@' && (name = $(/^(@[\w-]+)\s*:/))) { return name[1] }
if (input.charAt(i) === '@' && (name = $(/^(@[\w-]+)\s*:/))) { return name[1]; }
},
//
@ -660,8 +645,8 @@ carto.Parser = function Parser(env) {
if (match = $(/^([#.](?:[\w-]|\\(?:[a-fA-F0-9]{1,6} ?|[^a-fA-F0-9]))+)[\s,]*\(/)) {
name = match[1];
while (param = $(this.entities.variable) || $(this.entities.literal)
|| $(this.entities.keyword)) {
while (param = $(this.entities.variable) || $(this.entities.literal) ||
$(this.entities.keyword)) {
// Variable
if (param instanceof tree.Variable) {
if ($(':')) {
@ -696,7 +681,7 @@ carto.Parser = function Parser(env) {
//
entity: function() {
return $(this.entities.literal) || $(this.entities.variable) || $(this.entities.url) ||
$(this.entities.call) || $(this.entities.keyword) || $(this.entities.javascript);
$(this.entities.call) || $(this.entities.keyword);
},
//
@ -778,7 +763,7 @@ carto.Parser = function Parser(env) {
}
var c = input.charAt(i);
if (c === '{' || c === '}' || c === ';' || c === ',') { break }
if (c === '{' || c === '}' || c === ';' || c === ',') { break; }
}
if (segments) {

View File

@ -1,14 +0,0 @@
(function(tree) {
tree.Alpha = function Alpha(val) {
this.value = val;
};
tree.Alpha.prototype = {
toString: function() {
return 'alpha(opacity=' +
(this.value.toString ? this.value.toString() : this.value) + ')';
},
eval: function() { return this; }
};
})(require('../tree'));

View File

@ -1,38 +0,0 @@
(function(tree) {
tree.JavaScript = function JavaScript(string, index) {
this.expression = string;
this.index = index;
};
tree.JavaScript.prototype = {
toString: function() {
return JSON.stringify(this.evaluated);
},
eval: function(env) {
var result,
expression = new Function('return (' + this.expression + ')'),
context = {};
for (var k in env.frames[0].variables()) {
context[k.slice(1)] = {
value: env.frames[0].variables()[k].value,
toJS: function() {
return this.value.eval(env).toString();
}
};
}
try {
this.evaluated = expression.call(context);
} catch (e) {
throw {
message: "JavaScript evaluation error: '" + e.name + ': ' + e.message + "'" ,
index: this.index
};
}
return this;
}
};
})(require('../tree'));