Jump to content

RockLESS - PHP LESS parsing helper module.


bernhard
 Share

Recommended Posts

  • 1 year later...

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.

Link to comment
Share on other sites

  • 1 month later...

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 ?

Link to comment
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!

Link to comment
Share on other sites

  • 2 weeks later...

@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
Link to comment
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
Link to comment
Share on other sites

  • 4 weeks later...

It looks like this module could allow for the introduction of field content prior to compiling - is that accurate? Is there anything special that needs to be done to prioritize it at runtime before ProCache? I'm looking to be able to push field values from SettingsFactory into the LESS file preproc.

Link to comment
Share on other sites

Yes, RockLESS can send variables from PHP to LESS:

$less = $modules->get('RockLESS');
$less->vars = [
  'foo' => 'bar',
];
$css = $less->getCSS($config->paths->templates . 'less/theme.less')->cssUrl;
echo "<link rel='stylesheet' type='text/css' href='$css'>";

How you combine that with ProCache is up to you. You can either send the compiled CSS to procache or I think you could also generate a LESS file via plain PHP listing your variables and include that file via @include in your LESS and then parse that LESS via ProCache.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

This worked really nicely, but I have run into an interesting problem.

I'm trying to use this in coordination with Settings Factory, and the issue I guess is that there is no real way for RockLESS to detect that the variables going into the CSS call have changed - so I can change the options all day long but the css won't regenrate because RockLess hasn't detected any changes in the less file it is calling - right?

Would it make sense to hook the settings factory so that when the settings are saved the compiled file is deleted? Or would it be safer to just touch the less file the less file RockLess is trying to load?

I'm curious if any others are trying to do something similar.

Link to comment
Share on other sites

  • 2 months later...
  • 9 months later...

Does the new Less module added to core 179 replace this module? I currently use this to pull in settings factory variables as added values in LESS - if the same functionality exists in the new Less module then I'd like to refactor to just using one preprocessor.

Link to comment
Share on other sites

Not yet. Ryan asked me if we should use RockLess for the new admin theming feature but I voted against using RockLESS as it is more a proof of concept than a polished module. It lacks proper docs and some methods are redundant but slightly different.

Ryans Less module is a simple wrapper around the same less parser that RockLESS uses but it lacks the file/directory monitoring part. I'd like to add that to ryans Less module one day for the same reason you are talking about, but I have no idea when that will happen. I thought it would be a good idea to start simple and solid with the new Less module and add features there when we need them.

If you don't miss any features with Ryans module: Go with his module. If you miss features: Stay with RockLESS or even better make a PR so that we can shift to the new Less module 🙂 

  • Like 2
Link to comment
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
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...