From 8531d110b19f2ecb38c40ab7e8e0f614e5aa59ea Mon Sep 17 00:00:00 2001 From: jamie-pate Date: Tue, 12 Jul 2011 17:12:25 -0700 Subject: [PATCH 1/4] Modified to allow precompiling of *.less.css files as well as *.less files (server won't serve up .less files) --- lib/less/tree/import.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/less/tree/import.js b/lib/less/tree/import.js index 2a9512091..6b3d89d57 100644 --- a/lib/less/tree/import.js +++ b/lib/less/tree/import.js @@ -23,7 +23,7 @@ tree.Import = function (path, imports) { this.path = path.value.value || path.value; } - this.css = /css$/.test(this.path); + this.css = /css$/.test(this.path)&&/less\.css$/.test(this.path);//precompile less.css and .less files! // Only pre-compile .less files if (! this.css) { From c37bf800fc894a55173b3b22622473af55f06488 Mon Sep 17 00:00:00 2001 From: jamie-pate Date: Tue, 12 Jul 2011 17:43:44 -0700 Subject: [PATCH 2/4] forgot to negate the test for /less\.css$/ --- lib/less/tree/import.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/less/tree/import.js b/lib/less/tree/import.js index 6b3d89d57..aa7064046 100644 --- a/lib/less/tree/import.js +++ b/lib/less/tree/import.js @@ -23,7 +23,7 @@ tree.Import = function (path, imports) { this.path = path.value.value || path.value; } - this.css = /css$/.test(this.path)&&/less\.css$/.test(this.path);//precompile less.css and .less files! + this.css = /css$/.test(this.path) && !/less\.css$/.test(this.path);//precompile less.css and .less files! // Only pre-compile .less files if (! this.css) { From 4172369b8b7f5934640f00961c652c583d0048b8 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 13 Jul 2011 00:04:22 -0700 Subject: [PATCH 3/4] Added || (boolean or) operator allows conditional overriding of variable values @somevariable:red; @include "otherfile" =================contents of "otherfile"========= @somevariable:@somevariable||green; --- lib/less/parser.js | 12 +++++++++++- lib/less/tree/operation.js | 1 + lib/less/tree/ruleset.js | 1 + lib/less/tree/value.js | 4 ++++ lib/less/tree/variable.js | 16 ++++++++++++++-- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/less/parser.js b/lib/less/parser.js index e828c23cb..09b9170f6 100644 --- a/lib/less/parser.js +++ b/lib/less/parser.js @@ -1049,6 +1049,16 @@ less.Parser = function Parser(env) { return operation || m; } }, + bor: function() { + + var m, a, op, operation; + if (m = $(this.addition)) { + while ((op = $(/^\|\|\s+/)) && (a = $(this.addition))) { + operation = new(tree.Operation)(op, [operation || m, a]); + } + return operation || m; + } + }, // // An operand is anything that can be part of an operation, @@ -1075,7 +1085,7 @@ less.Parser = function Parser(env) { expression: function () { var e, delim, entities = [], d; - while (e = $(this.addition) || $(this.entity)) { + while (e = $(this.bor) || $(this.entity)) { entities.push(e); } if (entities.length > 0) { diff --git a/lib/less/tree/operation.js b/lib/less/tree/operation.js index d2e4d5780..047eb2c25 100644 --- a/lib/less/tree/operation.js +++ b/lib/less/tree/operation.js @@ -26,6 +26,7 @@ tree.operate = function (op, a, b) { case '-': return a - b; case '*': return a * b; case '/': return a / b; + case '||': return a || b; } }; diff --git a/lib/less/tree/ruleset.js b/lib/less/tree/ruleset.js index 246200fa4..60625a7ce 100644 --- a/lib/less/tree/ruleset.js +++ b/lib/less/tree/ruleset.js @@ -62,6 +62,7 @@ tree.Ruleset.prototype = { else { return this._variables = this.rules.reduce(function (hash, r) { if (r instanceof tree.Rule && r.variable === true) { + r.prevValue = hash[r.name]; hash[r.name] = r; } return hash; diff --git a/lib/less/tree/value.js b/lib/less/tree/value.js index 922096cdc..149c1df71 100644 --- a/lib/less/tree/value.js +++ b/lib/less/tree/value.js @@ -3,7 +3,11 @@ tree.Value = function (value) { this.value = value; this.is = 'value'; + if (value ===undefined) { + this.operate = function(op,other){return op=='||'?other:undefined;}; + } }; + tree.Value.prototype = { eval: function (env) { if (this.value.length === 1) { diff --git a/lib/less/tree/variable.js b/lib/less/tree/variable.js index 10f7c0847..ba5fb8032 100644 --- a/lib/less/tree/variable.js +++ b/lib/less/tree/variable.js @@ -11,9 +11,20 @@ tree.Variable.prototype = { if (variable = tree.find(env.frames, function (frame) { if (v = frame.variable(name)) { - return v.value.eval(env); + if (!v.isEvaluating) { //stop recursive evaluation by returning a special value + v.isEvaluating = true; + try { + return v.value.eval(env); + } finally { + v.isEvaluating = undefined; + } + } else if (v.prevValue) { + return v.prevValue.value.eval(env); + } else { + return new tree.Value(undefined); + } } - })) { return variable } + })) { return variable; } else { throw { message: "variable " + name + " is undefined", index: this.index }; @@ -21,4 +32,5 @@ tree.Variable.prototype = { } }; + })(require('less/tree')); From c5af8a84931459d6df96dbc1951ac96cacc85b3a Mon Sep 17 00:00:00 2001 From: Jamie Pate Date: Wed, 13 Jul 2011 01:16:54 -0700 Subject: [PATCH 4/4] Fixed color || operator --- lib/less/tree/color.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/less/tree/color.js b/lib/less/tree/color.js index 38d34f85a..b59e11e55 100644 --- a/lib/less/tree/color.js +++ b/lib/less/tree/color.js @@ -58,11 +58,12 @@ tree.Color.prototype = { // operate: function (op, other) { var result = []; - + if (op == '||') { + return this||other; + } if (! (other instanceof tree.Color)) { other = other.toColor(); } - for (var c = 0; c < 3; c++) { result[c] = tree.operate(op, this.rgb[c], other.rgb[c]); }