Difference between revisions of "LESS"
(→Installing Recess) |
(→Installing Recess) |
||
Line 17: | Line 17: | ||
== Installing Recess == | == Installing Recess == | ||
− | As of August-2015, "recess - no longer maintained, does not work with newer less versions" : https://github.com/twitter/recess . | + | As of August-2015, "recess - no longer maintained, does not work with newer less versions" : https://github.com/twitter/recess . |
− | Better use lessc or other alternatives. | + | Better use [http://lesscss.org/#using-less-installation lessc] or other alternatives. |
=== Ubuntu === | === Ubuntu === |
Revision as of 13:43, 28 September 2015
Contents
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
As of August-2015, "recess - no longer maintained, does not work with newer less versions" : https://github.com/twitter/recess .
Better use lessc or other alternatives.
Ubuntu
The following commands should be run to install Recess
sudo apt-get install npm nodejs # 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 nodejs npm install recess -g # If the above fails with a "..permission denied.." error, # run npm install with sudo: # sudo npm install recess -g
If you find problem installing nodejs with npm, you can use node.js binaries
- Download Linux Binaries node.js binaries
- untar it to your local directory and add it to the PATH.
You can also use following script to get latest version.
CURRENT=$(node -v) VERSION=$(curl -L -s http://nodejs.org/dist/latest/ \ | egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \ | tail -n1) PLATFORM=linux ARCH=x64 PREFIX="$HOME/node-v$VERSION-$PLATFORM-$ARCH" if test "v$VERSION" != "$CURRENT"; then echo "Installing node v$VERSION ..." mkdir -p "$PREFIX" && \ curl -# -L http://nodejs.org/dist/v$VERSION/node-v$VERSION-$PLATFORM-$ARCH.tar.gz \ | tar xzvf - --strip-components=1 -C "$PREFIX" echo 'export PATH=$PATH:'"$PREFIX" >> $HOME/.bashrc echo "Latest stable version installed at $PREFIX" else echo "Latest stable version of node already installed." fi
npmstands 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 installnodeand
npm).
2. On the command line, install recess like this:
npm install recess -g
FreeBSD
1. Install npm (will also install nodes ie nodejs as a dependency)
Using packages on:pkg install npmBuild port in /usr/port/www:
cd /usr/port/www/npm; make install cleanUsing portmaster:
portmaster npm2. On the command line, install recess like this:
npm install recess -g
Windows 7, 8, & 10
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
npmstands 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.cssNOTE: if you are getting an empty moodle.css file, this is being caused by a parsing error in your LESS code. A bug in
recesscurrently 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
lessccompiler is what is used by
recessto do the actual compiling and will have been installed automatically along with it. If you call it directly as
lessc moodle.lessit should give you a helpful error message that points you to where the problem is.