Merge branch 'master' into 2_0_0

Conflicts:
	lib/less/browser.js
	lib/less/parser.js
This commit is contained in:
Luke Page
2014-02-23 17:38:39 +00:00
15 changed files with 73 additions and 9 deletions

View File

@@ -18,6 +18,11 @@ TODO
- Support property merging with +_ when spaces are needed and keep + for comma separated
- Do unit conversions with min and max functions. Don't pass through if not understood, throw an error
- Fix a bug when comparing a unit value to a non-unit value if the unit-value was the multiple of another unit (e.g. cm, mm, deg etc.)
- Fix mixins with media queries in import reference files not being put into the output (they now output, they used to incorrectly not)
- Fix lint mode - now reports all errors
- Fixed a small scope issue with & {} selector rulesets incorrectly making mixins visible - regression from 1.6.2
- Browser - added log level "debug" at 3 to get less logging, The default has changed so unless you set the value to the default you won't see a difference
- Browser - added postProcessor option, a function called to post-process the css before adding to the page
# 1.6.3

View File

@@ -215,6 +215,14 @@ module.exports = function(grunt) {
specs: 'test/browser/runner-global-vars-spec.js',
outfile: 'tmp/browser/test-runner-global-vars.html'
}
},
postProcessor: {
src: ['test/browser/less/postProcessor/*.less'],
options: {
helpers: 'test/browser/runner-postProcessor-options.js',
specs: 'test/browser/runner-postProcessor.js',
outfile: 'tmp/browser/test-postProcessor.html'
}
}
},

View File

@@ -21,11 +21,12 @@ var logLevel = {
};
// The amount of logging in the javascript console.
// 3 - Debug, information and errors
// 2 - Information and errors
// 1 - Errors
// 0 - None
// Defaults to 2
less.logLevel = typeof(less.logLevel) != 'undefined' ? less.logLevel : logLevel.debug;
less.logLevel = typeof(less.logLevel) != 'undefined' ? less.logLevel : (less.env === 'development' ? logLevel.debug : logLevel.errors);
// Load styles asynchronously (default: false)
//
@@ -57,7 +58,7 @@ var typePattern = /^text\/(x-)?less$/;
var cache = null;
function log(str, level) {
if (less.env == 'development' && typeof(console) !== 'undefined' && less.logLevel >= level) {
if (typeof(console) !== 'undefined' && less.logLevel >= level) {
console.log('less: ' + str);
}
}
@@ -159,6 +160,13 @@ function createCSS(styles, sheet, lastModified) {
}
}
function postProcessCSS(styles) {
if (less.postProcessor && typeof less.postProcessor === 'function') {
styles = less.postProcessor.call(styles, styles) || styles;
}
return styles;
}
function errorHTML(e, rootHref) {
var id = 'less-error-message:' + extractId(rootHref || "");
var template = '<li><label>{line}</label><pre class="{class}">{content}</pre></li>';
@@ -393,7 +401,9 @@ function initRunningMode(){
if (e) {
error(e, sheet.href);
} else if (root) {
createCSS(root.toCSS(less), sheet, env.lastModified);
var styles = root.toCSS(less);
styles = postProcessCSS(styles);
createCSS(styles, sheet, env.lastModified);
}
});
}
@@ -459,7 +469,9 @@ less.refresh = function (reload, modifyVars) {
log("loading " + sheet.href + " from cache.", logLevel.info);
} else {
log("parsed " + sheet.href + " successfully.", logLevel.debug);
createCSS(root.toCSS(less), sheet, env.lastModified);
var styles = root.toCSS(less);
styles = postProcessCSS(styles);
createCSS(styles, sheet, env.lastModified);
}
log("css for " + sheet.href + " generated in " + (new Date() - endTime) + 'ms', logLevel.info);
if (env.remaining === 0) {

View File

@@ -242,7 +242,16 @@ tree.functions = {
if(!(val instanceof tree.Dimension)) {
throw { type: "Argument", message: "the first argument to unit must be a number" + (val instanceof tree.Operation ? ". Have you forgotten parenthesis?" : "") };
}
return new(tree.Dimension)(val.value, unit ? unit.toCSS() : "");
if (unit) {
if (unit instanceof tree.Keyword) {
unit = unit.value;
} else {
unit = unit.toCSS();
}
} else {
unit = "";
}
return new(tree.Dimension)(val.value, unit);
},
convert: function (val, unit) {
return val.convertTo(unit.value);

View File

@@ -15,8 +15,13 @@ var less = {
if (callback) {
parser.parse(input, function (e, root) {
try { callback(e, root && root.toCSS && root.toCSS(options)); }
catch (err) { callback(err); }
if (e) { callback(e); return; }
var css;
try {
css = root && root.toCSS && root.toCSS(options);
}
catch (err) { callback(err); return; }
callback(null, css);
});
} else {
ee = new (require('events').EventEmitter)();
@@ -129,4 +134,4 @@ require('./join-selector-visitor.js');
require('./to-css-visitor.js');
require('./source-map-output.js');
module.exports = less;
module.exports = less;

View File

@@ -820,7 +820,7 @@ less.Parser = function Parser(env) {
// black border-collapse
//
keyword: function () {
var k = $re(/^[_A-Za-z-][_A-Za-z0-9-]*/);
var k = $re(/^%|^[_A-Za-z-][_A-Za-z0-9-]*/);
if (k) {
return tree.Color.fromKeyword(k) || new(tree.Keyword)(k);
}

View File

@@ -5,6 +5,7 @@ tree.Keyword.prototype = {
type: "Keyword",
eval: function () { return this; },
genCSS: function (env, output) {
if (this.value === '%') { throw { type: "Syntax", message: "Invalid % without number" }; }
output.add(this.value);
},
toCSS: tree.toCSS,

View File

@@ -0,0 +1,4 @@
hr {height:50px;}
.test {
color: #ffffff;
}

View File

@@ -0,0 +1,4 @@
@color: white;
.test {
color: @color;
}

View File

@@ -0,0 +1,4 @@
var less = {};
less.postProcessor = function(styles) {
return 'hr {height:50px;}\n' + styles;
};

View File

@@ -0,0 +1,3 @@
describe("less.js postProcessor", function() {
testLessEqualsInDocument();
});

View File

@@ -60,6 +60,7 @@
eformat: rgb(32, 128, 64);
unitless: 12;
unit: 14em;
unitpercentage: 100%;
get-unit: px;
get-unit-empty: ;
hue: 98;

View File

@@ -0,0 +1,3 @@
.a {
error: calc(1 %);
}

View File

@@ -0,0 +1,4 @@
SyntaxError: Invalid % without number in {path}percentage-missing-space.less on line 2, column 3:
1 .a {
2 error: calc(1 %);
3 }

View File

@@ -65,6 +65,7 @@
unitless: unit(12px);
unit: unit((13px + 1px), em);
unitpercentage: unit(100, %);
get-unit: get-unit(10px);
get-unit-empty: get-unit(10);