emberfeather / less.js-middleware

Connect Middleware for LESS.js compiling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature: pass variables to .less files via POST/GET

kelexel opened this issue · comments

What about the ability to set in the middleware options a list of variables to look for, and replacing said variables by their passed values in the requested .less/.css file ?

Also, as a bonus the ability to pass a file name via said POST/GET ?

Idea is to have several .less/.css files that can be dynamically created based on a set of predefined colors, font-sizes, etc.

Typically, you would be running your app on localhost:1234, and make a POST or GET to generate a customized stylesheet..

So, you could make a POST request to /less/visitors.less, passing: {"filename": "client1.css", "variables": {"color1": "#FF0000"}};
Which would result in the file "client1.css" where @color1 would equal #FF0000 ...

What do you think ?

I would veto the filename options immediately over security concerns 😦 There are just too many things that could go wrong with arbitrary filenames for such a small feature. Instead you could do it yourself by using the pre/post hooks to write the files where you want them. Besides the filename that you request doesn't normally exist until it is created by the middleware, so it acts in a similar manner already. You can just use one of the hooks to change the less file it is looking for.

I'll think over the idea of custom variables.

Variables ARE passed, through express params or query params, and accessible in the preprocess function. I don't see a need to provide another proprietary way of passing them.

That is true. To be fair, the storeCss just got the req as part of the 2.0.0 version. The request object should have the information that is needed for providing per request variable. And other static variables could be done as part of the pre/post process options.