LESS: Difference between revisions
No edit summary |
|||
Line 15: | Line 15: | ||
After compiling the LESS files, CSS ends up in '''theme/bootstrapbase/style/moodle.css'''. This file should not be edited manually. | After compiling the LESS files, CSS ends up in '''theme/bootstrapbase/style/moodle.css'''. This file should not be edited manually. | ||
== | == Installing Recess == | ||
=== | === Ubuntu === | ||
The following commands should be run to install Recess | The following commands should be run to install Recess | ||
< | <code bash> | ||
sudo apt-get install npm node | |||
# If the above fails due to the error "The following packages have unmet dependencies", | |||
# run the commands separately, ie. | |||
</ | # sudo apt-get install npm | ||
# and then | |||
# sudo apt-get install node | |||
npm install recess -g | |||
</code> | |||
<code>npm</code> stands for Node Package Manager, and is the equivalent of apt-get for node.js packages. | <code>npm</code> stands for Node Package Manager, and is the equivalent of apt-get for node.js packages. | ||
=== | === Mac OS X === | ||
1. Install the basic node packages from the web site: [http://nodejs.org http://nodejs.org] (or use your favourite package manager to install <code>node</code> and <code>npm</code>). | 1. Install the basic node packages from the web site: [http://nodejs.org http://nodejs.org] (or use your favourite package manager to install <code>node</code> and <code>npm</code>). | ||
2. On the command line, install recess like this: | 2. On the command line, install recess like this: | ||
< | <code bash> | ||
npm install recess -g | |||
</ | </code> | ||
=== | === Windows 7 === | ||
In order to install Recess you need to have Node.js installed first, which is relatively simple to do. | In order to install Recess you need to have Node.js installed first, which is relatively simple to do. | ||
Go to nodejs.org click install. | Go to nodejs.org click install. | ||
Line 50: | Line 50: | ||
When installed go to -> Start -> All Programs -> type Node.js into the Search box, then select Node.js Command prompt (black icon) from the list. Now you are ready to install Recess. So at the command line prompt type the following: | When installed go to -> Start -> All Programs -> type Node.js into the Search box, then select Node.js Command prompt (black icon) from the list. Now you are ready to install Recess. So at the command line prompt type the following: | ||
< | <code bash> | ||
npm install recess -g | |||
</ | </code> | ||
<code>npm</code> stands for Node Package Manager, and is the equivalent of apt-get for node.js packages. | <code>npm</code> stands for Node Package Manager, and is the equivalent of apt-get for node.js packages. | ||
== Using Recess == | |||
After editing the LESS files, compile (minified) your CSS as follows: | After editing the LESS files, compile (minified) your CSS as follows: | ||
< | <code bash> | ||
cd theme/bootstrapbase/less/ | cd theme/bootstrapbase/less/ | ||
recess --compile --compress moodle.less > ../style/moodle.css | recess --compile --compress moodle.less > ../style/moodle.css | ||
</ | </code> | ||
or if you prefer to run it from the top-level: | or if you prefer to run it from the top-level: |
Revision as of 14:14, 8 August 2013
Overview
LESS (lesscss.org) extends CSS with dynamic behavior such as variables, mixins, operations and functions. It's an advanced way of writing CSS that we use in some themes within Moodle.
Browsers don't interpret it themselves, however, so LESS files need to be converted into normal CSS before use.
Recess is one tool used to compile and compress LESS into CSS under *nix based systems. There are many others tools for LESS.
The bootstrapbase theme
Moodle's Bootstrap base theme has rules written using LESS.
The main LESS file is theme/bootstrapbase/less/moodle.less, with additional files in theme/bootstrapbase/less/moodle/ imported by the main file.
After compiling the LESS files, CSS ends up in theme/bootstrapbase/style/moodle.css. This file should not be edited manually.
Installing Recess
Ubuntu
The following commands should be run to install Recess
sudo apt-get install npm node
- If the above fails due to the error "The following packages have unmet dependencies",
- run the commands separately, ie.
- sudo apt-get install npm
- and then
- sudo apt-get install node
npm install recess -g
npm
stands for Node Package Manager, and is the equivalent of apt-get for node.js packages.
Mac OS X
1. Install the basic node packages from the web site: http://nodejs.org (or use your favourite package manager to install node
and npm
).
2. On the command line, install recess like this:
npm install recess -g
Windows 7
In order to install Recess you need to have Node.js installed first, which is relatively simple to do.
Go to nodejs.org click install.
When installed go to -> Start -> All Programs -> type Node.js into the Search box, then select Node.js Command prompt (black icon) from the list. Now you are ready to install Recess. So at the command line prompt type the following:
npm install recess -g
npm
stands for Node Package Manager, and is the equivalent of apt-get for node.js packages.
Using Recess
After editing the LESS files, compile (minified) your CSS as follows:
cd theme/bootstrapbase/less/
recess --compile --compress moodle.less > ../style/moodle.css
or if you prefer to run it from the top-level:
recess --compile --compress theme/bootstrapbase/less/moodle.less > theme/bootstrapbase/style/moodle.css
This will compile and compress the moodle.less file (and all the LESS and CSS files it imports) into a single file, moodle.css, and store it in the style folder of the bootstrapbase theme.
Alternatively if you want to view the normal (un-minified) CSS then use the following method.
recess --compile moodle.less > ../style/moodle.css
NOTE: if you are getting an empty moodle.css file, this is being caused by a parsing error in your LESS code. A bug in recess
currently prevents it giving you helpful error messages in many cases. You will need to examine what you have altered or written to make sure it is complete and the syntax is correct. The lessc
compiler is what is used by recess
to do the actual compiling and will have been installed automatically along with it. If you call it directly as lessc moodle.less
it should give you a helpful error message that points you to where the problem is.