Improvements on LESS Module
- XWiki
- Feature
- Completed
- [xwiki-devs] Future of Flamingo, Bootstrap and Less in XWiki https://markmail.org/thread/7sbviier23wzfadf (Sep 17, 2015)
- [xwiki-devs] [Proposal] Using Less4j by default in XWiki https://markmail.org/thread/xda5bkyhlxhz3ov5 (Dec 17, 2014)
- [xwiki-devs] [Proposal] A new mechanism to overwrite a skin file https://markmail.org/thread/ikavgfonfftjyebm (Feb 25, 2015)
- [xwiki-devs] [Proposal] Introduce LESS in Skin Extensions (SSX) https://markmail.org/thread/drziuv4nax3gfnm4 (Dec 11, 2014)
- [xwiki-devs] UI Standards for now and the future https://markmail.org/thread/odi5mvyk6odnhmm3 (Jul 2, 2014)
- [xwiki-devs] [Proposal] Color Theme Application for Flamingo https://markmail.org/thread/aiocakrfmrr256pt (Jun 3, 2014)
- [xwiki-devs] [Proposal] Retro-compatibility between Color Theme Application ad Flamingo https://markmail.org/thread/2sxvthwbxhptkuau (May 26, 2014)
- [xwiki-devs] VOTE: Integrate LESS in XWiki https://markmail.org/thread/i6hyotva4tmtikvz (May 15, 2014)
- [xwiki-devs] About Bootstrap and Color Themes https://xwiki.markmail.org/thread/cvfvbrldneg67lmf (May 13, 2014)
- [xwiki-devs] [Proposal] Integrate LESS css in XWiki https://xwiki.markmail.org/thread/hw45txkv2vk5dnqw (Apr 23, 2014)
- [xwiki-devs] How to use UI components in different skins? https://markmail.org/message/vwl2m4dt5ykeypmr (Mar 18, 2014)
- [Discussion][Skin] Less vs. Sass vs. Velocity https://markmail.org/message/nhtlf5aauxxsfzov (Feb 19, 2014)
- [xwiki-devs] [VOTE] Integrate Bootstrap framework inside platform https://markmail.org/thread/wmfmmhdhpsxuth5y (Feb 25, 2014)
Description
Use Cases
- UC1: Having the LESS features inside an SSX object
- UC2: Be able to use all the skin's features (mix-ins, variables) in SSX for a good integration with the current skin.
- UC3: Being able to overwrite a LESS file within a skin object
Implementation Ideas
How to deal with the skin
For UC2, we need to include the LESS file of the current skin in any SSX object. So we could add, before the content of the SSX, the following line before using the LESS compiler:
But we do not want to have all the CSS classes of the skin written in every SSX! Fortunatly, we can use the "reference" option of the LESS Compiler to include it, but without adding the imported styles to the compiled output (see: http://lesscss.org/features/#import-options-reference).
So, the code becomes:
But we have an other problem. style.less.vm needs to be executed with velocity to initialize some variables (mainly about color themes) but right now, velocity is NOT executed on imported files. It is intended, because some collisions could happen between the LESS and the Velocity Syntax. So, to be able to integrate any LESS library, we do not execute Velocity on imported files and I don't think we should change that behaviour.
What can we do is creating a new temporary directory, in which we write the velocity output of the imported file, and then execute the LESS compiler on the SSX with that new temporary directory as an include path. It should work.
For UC3, the same solution could be applied. If the skin document overwrites a file, we can put this file in that temporary directory and when LESS will look for an "example.less" file, it will look in that temporary directory BEFORE looking at the regular directory (it was first explained there).
About the SSX object
We have 3 options:
Sol1 - Create a new class: LSSX
Instead of modifying the SSX implementation, we can create a LESS Stylesheet Skin extension (LSSX) that would have the same behaviour except that it will use the LESS compiler.
Sol 2 - Add a new property in the SSX object
This new property would be called "CSS pre-processor" and the user would be allow to select between: "none", "less", "sass", or any new language that we want to support in the future.
Problem: if a skin does not have LESS variables, the compilation will fail. This means that an extension using this new system will no more be compatible with Colibri.
A solution for that would be to have 2 SSX objects in the extension. One with old CSS code for Colibri (prefixed by .skin-colibri), and one with the LESS code.
For colibri, the first SSX will work, but the other will fail.
Sol 3 - The first line of the SSX is used to set the preprocessor
The first line of the SSX could be:
The values could be "none" (default), "less", "sass" or anything else in the future. It has the benefit that this syntax could be used in files and not only on SSX object.
Decision
Personally, I prefer the second solution. It looks easier for a web-developer.
Cache
Of course, any SSX object that contains LESS code must be cached.