views:

161

answers:

2

I am attempting to use lesscss to build a templating system where each template has 3 or 4 alternative colour schemes.

So for example, I could have a red.less stylesheet that looks like this:

@main_colour: #ff0000;
@import 'main.less';

So, I only have one main.less stylesheet to maintain which contains all the main styles, and uses the variables set for colour codes. I can then create a seperate colour.less file for each colour scheme.

Only problem is when I try to do this I get a Less::VariableNameError which indicates that LESS is parsing the @imports BEFORE it parses the variables.

Is there a workaround to this or any other way to achieve the same end result?

+1  A: 

In reference to your tweet, yes, this would work as you expect in Sass. I'm actually kind of surprised that it doesn't work in Less.

nex3
Thanks for confirming that. It's not too late to switch to SASS, the only reason I didn't initially is due to the syntax.I've heard SASS is working on a more CSS-like syntax (like LESS). Do you know how close to reality this is?
aaronrussell
It's actually mostly usable today. The code is available on the scss branch of the repository (http://github.com/nex3/haml/commits/scss). It's not very well-documented at the moment, and it lacks a bit of polish, but it supports almost everything Sass does (the exception being script interpolation in selectors and properties, which is due in the next couple days). If you install that branch, you need merely name your files `.scss` and off you go.
nex3
Thanks. Managed to suss out the SCSS syntax by looking at your tests (although I look forward to the documentation). Seems to work as expected, so unless I get an answer from the LESS chaps pretty pronto I'll be swapping this project over to SASS. :)
aaronrussell
+1  A: 

I guess the Less guys wanted to keep the .Less file atomic and independent of external environmental settings. This was what I assumed, but I also didn't like it so our .NET port http://www.dotlesscss.com will allow you to do this by default.

Its not a big change to do in the original Less ruby version and if you fancy tinkering with the source I can point you in the right direction.

Out of interest, without been traitorous to the Less team I quite like the SASS syntax now and there are additional things such as conditional statements and loops that you cant (yet) do with Less.

@nex3 - you guys should stop competing and just work together.

Owen
Thanks. Last night I found a fork of LESS that seems to do what we all want: http://github.com/tablatom/less/commit/0c2c39dc0b3b606b7b8c927a4fd714bf14c1d3e6However, I'm now reluctant to continue with Less using a 'hacky' approach plus I just get the feeling the SASS team are on top of things a bit more.
aaronrussell