Skip to content

Commit 8a98eee

Browse files
committed
Merge branch 'pr121'
2 parents 0ef6b5b + df2c7af commit 8a98eee

9 files changed

+65
-5
lines changed

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 2.0.1
2+
3+
- 22 Feb 2015
4+
5+
* Fixed [#123](https://github.com/emberfeather/less.js-middleware/issues/123): imports are not objects for cache checking and did not have mtimes.
6+
* Added a `preprocess.importPaths` for modifying the import paths per request.
7+
18
# 2.0.0
29

310
– 21 Feb 2015

lib/middleware.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,13 @@ module.exports = less.middleware = function(source, options){
107107
},
108108
preprocess: {
109109
less: function(src, req) { return src; },
110-
path: function(pathname, req) { return pathname; }
110+
path: function(pathname, req) { return pathname; },
111+
importPaths: function(paths, req) { return paths; }
111112
},
112113
render: {
113114
compress: 'auto',
114-
yuicompress: false
115+
yuicompress: false,
116+
paths: []
115117
},
116118
storeCss: function(pathname, css, req, next) {
117119
mkdirp(path.dirname(pathname), 511 /* 0777 */, function(err){
@@ -188,9 +190,13 @@ module.exports = less.middleware = function(source, options){
188190
delete lessFiles[lessPath];
189191

190192
try {
193+
var renderOptions = extend(true, {}, options.render, {
194+
filename: lessPath,
195+
paths: options.preprocess.importPaths(options.render.paths, req)
196+
});
191197
lessSrc = options.preprocess.less(lessSrc, req);
192-
options.render.filename = lessPath;
193-
less.render(lessSrc, options.render, function(err, output){
198+
199+
less.render(lessSrc, renderOptions, function(err, output){
194200
if (err) {
195201
utilities.lessError(err);
196202
return next(err);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Randy Merrill <Zoramite+github@gmail.com> (http://forthedeveloper.com)",
33
"name": "less-middleware",
44
"description": "LESS.js middleware for connect.",
5-
"version": "2.0.0",
5+
"version": "2.0.1",
66
"repository": {
77
"type": "git",
88
"url": "git://github.com/emberfeather/less.js-middleware.git"

readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ The following options can be used to control the behavior of the middleware:
8787
<td>Function that modifies the less pathname before being loaded from the filesystem.</td>
8888
<td><code>function(pathname, req){...}</code></td>
8989
</tr>
90+
<tr>
91+
<th><code>preprocess.importPaths</code></th>
92+
<td>Function that modifies the import paths used by the less parser per request.</td>
93+
<td><code>function(paths, req){...}</code></td>
94+
</tr>
9095
<tr>
9196
<th><code>render</code></th>
9297
<td>Options for the less render. See the "<code>render</code> Options" section below.</td>
@@ -127,6 +132,10 @@ The following are the defaults used by the middleware:
127132
<th><code>yuicompress</code></th>
128133
<td><code>false</code></td>
129134
</tr>
135+
<tr>
136+
<th><code>paths</code></th>
137+
<td><code>[]</code></td>
138+
</tr>
130139
</tbody>
131140
</table>
132141

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@externalColor: #f03;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@paddingBox: 20px;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.widget{color:#f03;padding:20px}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import "externalvariables.less";
2+
@import "ui.less";
3+
.widget {
4+
color: @externalColor;
5+
padding: @paddingBox;
6+
}

test/test-middleware.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,35 @@ describe('middleware', function(){
167167
});
168168
});
169169

170+
describe('importPaths', function(){
171+
var app = setupExpress(__dirname + '/fixtures', {
172+
dest: tmpDest,
173+
preprocess: {
174+
path: function(pathname, req) {
175+
var returnPath = pathname.replace(/(\/[0-9\.0-9\.0-9].*\/)/, '/');
176+
return returnPath;
177+
},
178+
importPaths: function(paths, req) {
179+
var version = req.url.match(/\/([0-9\.0-9\.0-9]*)/);
180+
var reqPath = path.join(__dirname, 'fixtures', 'external', version[1] , '/');
181+
var paths = [
182+
reqPath,
183+
path.join(reqPath, 'ui')
184+
];
185+
return paths;
186+
}
187+
}
188+
});
189+
190+
it('should respond with newly mapped paths', function(done){
191+
var expected = fs.readFileSync(__dirname + '/fixtures/preprocessParserPaths-exp.css', 'utf8');
192+
request(app)
193+
.get('/2.43.3/preprocessParserPaths.css')
194+
.expect(200)
195+
.expect(expected, done);
196+
});
197+
});
198+
170199
describe('pathRoot', function(){
171200
var app = setupExpress('/fixtures', {
172201
dest: '/artifacts',

0 commit comments

Comments
 (0)