Jump to content
bernhard

RockLESS - PHP LESS parsing helper module.

Recommended Posts

RockLESS

This is a helper module for parsing LESS and returning the resulting CSS file or content. It checks the LESS file for changes and recreates the CSS file only when needed. See the comments in the module file for options.

This is an exemplary return of the getCSS() method:

example object

And this is how you can use a less file as theme in your HTML markup:

<link rel="stylesheet" type="text/css" href="<?= $modules->get('RockLESS')->getCSS($config->paths->templates . 'less/theme.less')->cssUrl; ?>">

 

Download:

https://modules.processwire.com/modules/rock-less/

https://github.com/BernhardBaumrock/RockLESS

  • Like 8

Share this post


Link to post
Share on other sites

Where did you get the Less compiler part from? I noticed some warnings from php regarding the use of "continue" rather than "break" in some switch statements (functionally identical but continue generates a warning). I saw they were from the less.php/Less.php file and was about to patch them, however I was curious as to whether this was imported from an external library or you rolled your own. If external then I would imagine it more useful to fix it upstream first. I did a brief search for "less.php" but didn't find anything that seemed to match your project file's structure.

Share this post


Link to post
Share on other sites

Hi @porl sorry for the delay!

It's this one: https://github.com/oyejorge/less.php I see that the repository is archived/read-only. Maybe you want to fork it and I can include the fixed version?

Or we can take one of the 186 available forks 🙈 https://github.com/oyejorge/less.php/network/members; maybe https://github.com/wikimedia/less.php ?

Share this post


Link to post
Share on other sites

@bernhard I definitely think a more active fork makes sense. If one of use were to fork it for this one-off I think a similar problem would just happen again in future.

Share this post


Link to post
Share on other sites

@porl could you please try if the fork linked above resolves your problem? It has a very active commit log and 72 contributors so that should be a solid choice.

Share this post


Link to post
Share on other sites

@bernhard I'll be happy to when I get a chance. Unfortunately I'm in the middle of a project I have severely underestimated time-wise so I'm not sure when I'll get to it sorry. If you don't get anything useful from me in the near future make sure to ping me again and I'll try to get back to it!

Share this post


Link to post
Share on other sites

@bernhard I have started a quick test and so far so good.

The wikimedia fork is structured differently but I copied the "lib/Less" directory into the RockLESS one (so there is /RockLESS/Less) and modified the RockLESS.module.php file as follows:

diff --git a/site/modules/RockLESS/RockLESS.module.php b/site/modules/RockLESS/RockLESS.module.php
index a711627..fd455da 100644
--- a/site/modules/RockLESS/RockLESS.module.php
+++ b/site/modules/RockLESS/RockLESS.module.php
@@ -23,7 +23,10 @@ class RockLESS extends WireData implements Module {
   public function init() {
     // load less.php if it is not already loaded
     // a simple require_once does not work properly
-    if(!class_exists('Less_Parser')) require_once(__DIR__ . "/less.php/Less.php");
+    if(!class_exists('Less_Parser')) {
+      require_once(__DIR__ . "/Less/Autoloader.php");
+      \Less_Autoloader::register();
+    }
   }
 
   /**

A quick check and the RockSkinUIKit module loads and executes with no more errors.

I'm not using the RockLESS module beyond that in this project but I assume that is a sign that it should work as expected.

  • Thanks 1

Share this post


Link to post
Share on other sites

v0.0.3 fixes a bug where cssUrl returned the path and not the relative url due to windows directory separator. Not sure why this was no issue until now... And another reason why I hope that we get $files->url() and $files->path() soon 😐 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...