Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,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'
}
}
},

Expand Down
15 changes: 13 additions & 2 deletions lib/less/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,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>';
Expand Down Expand Up @@ -575,7 +582,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);
}
});
}
Expand Down Expand Up @@ -645,7 +654,9 @@ less.refresh = function (reload, modifyVars) {
log("loading " + sheet.href + " from cache.", logLevel.info);
} else {
log("parsed " + sheet.href + " successfully.", logLevel.info);
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) {
Expand Down
4 changes: 4 additions & 0 deletions test/browser/css/postProcessor/postProcessor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hr {height:50px;}
.test {
color: #ffffff;
}
4 changes: 4 additions & 0 deletions test/browser/less/postProcessor/postProcessor.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@color: white;
.test {
color: @color;
}
4 changes: 4 additions & 0 deletions test/browser/runner-postProcessor-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var less = {};
less.postProcessor = function(styles) {
return 'hr {height:50px;}\n' + styles;
};
3 changes: 3 additions & 0 deletions test/browser/runner-postProcessor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe("less.js postProcessor", function() {
testLessEqualsInDocument();
});