Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require brackets to do maths #1151

Merged
merged 16 commits into from
Feb 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions bin/lessc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var options = {
color: true,
strictImports: false,
rootpath: '',
relativeUrls: false
relativeUrls: false,
strictMaths: true
};
var continueProcessing = true,
currentErrorcode;
Expand Down Expand Up @@ -103,6 +104,14 @@ args = args.filter(function (arg) {
case "relative-urls":
options.relativeUrls = true;
break;
case "sm":
case "strict-maths-off":
options.strictMaths = false;
break;
case "su":
case "strict-units-off":
options.strictUnits = false;
break;
}
});

Expand Down Expand Up @@ -161,7 +170,9 @@ var parseLessFile = function (e, data) {
try {
var css = tree.toCSS({
compress: options.compress,
yuicompress: options.yuicompress
yuicompress: options.yuicompress,
strictMaths: options.strictMaths,
strictUnits: options.strictUnits
});
if (output) {
ensureDirectory(output);
Expand Down
8 changes: 4 additions & 4 deletions lib/less/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function initRunningMode(){
if (less.watchMode) {
loadStyleSheets(function (e, root, _, sheet, env) {
if (root) {
createCSS(root.toCSS(), sheet, env.lastModified);
createCSS(root.toCSS(less), sheet, env.lastModified);
}
});
}
Expand Down Expand Up @@ -104,7 +104,7 @@ less.modifyVars = function(record) {
((record[name].slice(-1) === ';')? record[name] : record[name] +';');
}
new(less.Parser)(new less.tree.parseEnv(less)).parse(str, function (e, root) {
createCSS(root.toCSS(), less.sheets[less.sheets.length - 1]);
createCSS(root.toCSS(less), less.sheets[less.sheets.length - 1]);
});
};

Expand All @@ -117,7 +117,7 @@ less.refresh = function (reload) {
log("loading " + sheet.href + " from cache.");
} else {
log("parsed " + sheet.href + " successfully.");
createCSS(root.toCSS(), sheet, env.lastModified);
createCSS(root.toCSS(less), sheet, env.lastModified);
}
log("css for " + sheet.href + " generated in " + (new(Date) - endTime) + 'ms');
(env.remaining === 0) && log("css generated in " + (new(Date) - startTime) + 'ms');
Expand All @@ -138,7 +138,7 @@ function loadStyles() {
env.filename = document.location.href.replace(/#.*$/, '');

new(less.Parser)(env).parse(styles[i].innerHTML || '', function (e, cssAST) {
var css = cssAST.toCSS();
var css = cssAST.toCSS(less);
var style = styles[i];
style.type = 'text/css';
if (style.styleSheet) {
Expand Down
30 changes: 27 additions & 3 deletions lib/less/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,34 @@
return env;
};

//todo - do the same for the eval env and the toCSS env
//tree.evalEnv = function(options) {
//};
var evalCopyProperties = [
'compress', // whether to compress
'strictMaths', // whether maths has to be within parenthesis
'strictUnits' // whether units need to evaluate correctly
];

tree.evalEnv = function(options, frames) {
copyFromOriginal(options, this, evalCopyProperties);

this.frames = frames || [];
};

tree.evalEnv.prototype.inParenthesis = function () {
if (!this.parensStack) {
this.parensStack = [];
}
this.parensStack.push(true);
};

tree.evalEnv.prototype.outOfParenthesis = function () {
this.parensStack.pop();
};

tree.evalEnv.prototype.isMathsOn = function () {
return this.strictMaths === false ? true : (this.parensStack && this.parensStack.length);
};

//todo - do the same for the toCSS env
//tree.toCSSEnv = function (options) {
//};

Expand Down
2 changes: 1 addition & 1 deletion lib/less/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var less = {
'call', 'url', 'alpha', 'import',
'mixin', 'comment', 'anonymous', 'value',
'javascript', 'assignment', 'condition', 'paren',
'media', 'ratio', 'unicode-descriptor', 'extend'
'media', 'unicode-descriptor', 'negative', 'extend'
].forEach(function (n) {
require('./tree/' + n);
});
Expand Down
6 changes: 6 additions & 0 deletions lib/less/lessc_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ var lessc_helper = {
sys.puts(" -rp, --rootpath Set rootpath for url rewriting in relative imports and urls.");
sys.puts(" Works with or withour the relative-urls option.");
sys.puts(" -ru, --relative-urls re-write relative urls to the base less file.");
sys.puts(" -sm, --strict-maths-off Make maths not require brackets, which is similar behaviour");
sys.puts(" to before 1.4. This option is for compatability and may be");
sys.puts(" removed in the future.");
sys.puts(" -su, --strict-units-off Allow mixed units, e.g. 1px+1em or 1px*1px which have units");
sys.puts(" that cannot be represented. This option is for compatability");
sys.puts(" and may be removed in the future.");
sys.puts("");
sys.puts("Report bugs to: http://github.com/cloudhead/less.js/issues");
sys.puts("Home page: <http://lesscss.org/>");
Expand Down