Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

LESS: Difference between revisions

From MoodleDocs
No edit summary
m (Text replacement - "<code bash>" to "<syntaxhighlight lang="bash">")
(44 intermediate revisions by 16 users not shown)
Line 1: Line 1:
== Overview ==
== Overview ==


LESS 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.
LESS ([http://lesscss.org 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.
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.
Recess is one tool used to compile and compress LESS into CSS under *nix based systems.  There are [https://github.com/cloudhead/less.js/wiki/GUI-compilers-that-use-LESS.js many others tools for LESS].


For Windows users, WinLess is available to compile and compress LESS into CSS for you.
== The bootstrapbase theme ==


== The bootstrap theme ==
Moodle's bootstrapbase theme has rules written using LESS.


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.  


The main LESS file is '''theme/bootstrap/less/moodle.less''', with additional files in '''theme/bootstrap/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.


After compiling the LESS files, CSS ends up in '''theme/bootstrap/style/generated.css'''. This file should not be edited manually.
== Compiling LESS  ==
If you want to make changes to the .css generated from these .less files then you need to use a less compiler to build your changes. The supported way to achieve this
is using '''grunt'''. (See [[Grunt]] for details of how to install it).


== Installing Recess under Ubuntu ==
After editing the LESS files, compile (minified) your CSS using '''grunt''' as follows:
The following commands should be run to install Recess


<pre>
<syntaxhighlight lang="bash">
sudo apt-get install npm node
$ grunt css
npm install recess -g
</syntaxhighlight>
</pre>


== Installing Recess under Mac OS X using MacPorts ==
This will compile and compress the moodle.less & editor.less file (and all the LESS and CSS files it imports) into a single file, moodle.css & editor.css, and store it in the style folder of the bootstrapbase theme.
1. Install MacPorts on Mac OS X. If you use a different package manager some install commands will vary.


2. Install npm, the Node package manager
== See also ==
<pre>
* [[Grunt]]
    port install npm
</pre>
3. Install recess
<pre>
    npm install recess -g
</pre>


Depending on your shell, you may need to type rehash after installing for your shell to pick up the commands.
[[Category:Themes]]
 
== Using Recess ==
 
To compile to LESS for the boostrap theme use these commands, from the root of your Moodle code directory
<pre>
cd theme/boostrap/less/
recess --compile --compress moodle.less > ../style/generated.css
</pre>
 
This will compile and compress the moodle.less file (and all the LESS and CSS files it imports) into a single file, generated.css, and store it in the style folder of the bootstrap theme.
 
NOTE: if you are getting empty generated.css files, this is being caused by a parsing error in your LESS code. You will need to examine what you have altered or written to make sure it is complete and the syntax is correct.
 
== WinLess under Windows ==
Download [http://winless.org/ WinLess] and install it.
 
 
 
[[Category:Developer tools]]

Revision as of 19:18, 14 July 2021

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 bootstrapbase 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.

Compiling LESS

If you want to make changes to the .css generated from these .less files then you need to use a less compiler to build your changes. The supported way to achieve this is using grunt. (See Grunt for details of how to install it).

After editing the LESS files, compile (minified) your CSS using grunt as follows:

$ grunt css

This will compile and compress the moodle.less & editor.less file (and all the LESS and CSS files it imports) into a single file, moodle.css & editor.css, and store it in the style folder of the bootstrapbase theme.

See also