Page 1 of 1
[fixed] Stylesheet Pre/Post Compile events never sent
Posted: Mon Aug 18, 2014 7:36 pm
by airelibre
I'm working on a module that should take the "smartyfied" css and give it to a css preprocessor such as iLess or Lessphp before writing the cache css file.
For that, I thought that the StylesheetPostCompile event was my friend, but I cannot make it work.
The problem is in the file plugins/postfilter.postcompilefunc.php / Line 28 the "switch" is waiting for a "stylesheet" string, but when I use :
debug_to_log($smarty->_current_file);
.. I have strings like "f1b38ab6e8e4130dcdcf13c16217e1138f11a830"
And the line 29 is never executed.
Seems to be buggy in 1.11 too
Hope this could help you - Thanks
Re: [open] Stylesheet Pre/Post Compile events never sent
Posted: Tue Aug 26, 2014 7:43 am
by airelibre
In order to make the StylesheetPostCompile event work, I suggest removing
Code: Select all
case 'stylesheet' Events::SendEvent('Core','StylesheetPostCompile',array('stylesheet'=>&$tpl_output));
break;
From plugins/function.cms_stylesheet.php
And add something like
Code: Select all
Events::SendEvent('Core','StylesheetPostCompile',array('stylesheet'=>&$_contents));
On line 324 in file plugins/function.cms_stylesheet.php
Same stuff for the PreCompile
Hope this could help..
Re: [open] Stylesheet Pre/Post Compile events never sent
Posted: Tue Aug 26, 2014 7:59 am
by Rolf
Thanks airelibre, we will look into it.
Rolf
Re: [open] Stylesheet Pre/Post Compile events never sent
Posted: Sat Aug 30, 2014 5:12 pm
by calguy1000
it's actually not that simple. the compile events are sent every time a template is 'compiled'. which for string resources is only once.... which is technically what we want.
This will involve a significant rework to cms_stylesheet and probably creating a new smarty resource type.
Re: [open] Stylesheet Pre/Post Compile events never sent
Posted: Mon Sep 01, 2014 5:49 am
by airelibre
Ok, but we only need to send the event once too, not everytime, no?
For the moment, I found a trick with placing a little "tag" in the stylesheet to identify it, but do you think this will be fixed in cmsms 2.0?
If I can help testing, let me know
Re: [open] Stylesheet Pre/Post Compile events never sent
Posted: Thu Sep 04, 2014 12:16 am
by calguy1000
Yeah, I'll figure out something to do. I think I'll have to create a separate smarty resource for stylesheets.
FYI.... The other way to do this would be to just replace the {cms_stylesheet} tag with one of your own (from your module). i.e: {MyModule action=stylesheet} or something like that.
Re: [open] Stylesheet Pre/Post Compile events never sent
Posted: Thu Sep 04, 2014 5:09 am
by airelibre
Yes I did think about that, but this would not be a proper solution I think just for 1 or 2 lines, right?
And the StylesheetPreCompile / StylesheetPostCompile remains unused.
To give you more informations, for the moment, for the module CSSPreprocessor, I use the SmartyPreCompile event, and use my own
Code: Select all
$smarty->fetch('string:'$content);
line to process the template.
It works, but I had to do conditionnal check to test if I'm in a stylesheet or not (a specific comment string in the stylesheet), and I had to ensure my code only runs once in order to not generate an infinite loop.
Maybe another solution would be to create a new event, something called "StylesheetPreWriteToFile" which would send the stylesheet just before creating the cache file?
Re: [open] Stylesheet Pre/Post Compile events never sent
Posted: Sat Sep 06, 2014 8:46 pm
by calguy1000
Fixed in svn.
Gotta test again with the different {cms_stylesheet} params but we should be good to go.
Re: [fixed] Stylesheet Pre/Post Compile events never sent
Posted: Mon Sep 08, 2014 7:28 am
by airelibre
Thank you, seems to work with my first tests.
Maybe you can help me with a "problem": with the PostCompile, Smarty gives us something like :
Code: Select all
<?php echo smarty_function_uploads_url(array(),$_smarty_tpl);?>
For
in the source code
What is the proper way to get the "final" source code with smarty ?
The aim is to plug modules after all the stylesheet with smarty has been processed
Thanks
Re: [fixed] Stylesheet Pre/Post Compile events never sent
Posted: Mon Sep 08, 2014 2:00 pm
by calguy1000
Apparently you are still confused about how smarty functions.
A: A template is compiled to php code
- the precompile filter is called just before the compilation
- the postcompile filter is called just after the compilation
- compilation is only done when the template has changed (for performance reasons)
B: The php code from step A is 'rendered' by smarty into HTML (or in this case CSS).
C: (optionally) the output is 'cached' (smarty caching)
- the cache is refreshed every hour.
- In the case of CSS we do the caching ourselves.
So what you wanted is a 'post render' callback for CSS Which I don't think we ever had available.
Re: [fixed] Stylesheet Pre/Post Compile events never sent
Posted: Mon Sep 08, 2014 2:10 pm
by airelibre
Thanks for your explanation - You're right, I'm don't know Smarty compilation/caching system very well.
Yes, there is no event/callback after the CSS 'render', that's why I use the PreCompile/PostCompile event - As far as I know, it's the only way to get the CSS without having to create (and maintain) my own {cms_stylesheet} plugin. Is that right?
For the moment I use the PreCompile event, and do my own "fetch" but maybe there's a way to use the PostCompile event and get the rendered CSS code instead of the PHP source?
I know this is not directly related to v2, so thanks for your help