[fixed] Stylesheet Pre/Post Compile events never sent

Forum rules
Only administrators can post or move items here.
Post Reply
User avatar
airelibre
Dev Team Member
Dev Team Member
Posts: 98
Joined: Tue Dec 01, 2009 3:42 pm
Location: Alsace // France

[fixed] Stylesheet Pre/Post Compile events never sent

Post 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
User avatar
airelibre
Dev Team Member
Dev Team Member
Posts: 98
Joined: Tue Dec 01, 2009 3:42 pm
Location: Alsace // France

Re: [open] Stylesheet Pre/Post Compile events never sent

Post 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..
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: [open] Stylesheet Pre/Post Compile events never sent

Post by Rolf »

Thanks airelibre, we will look into it.

Rolf
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: [open] Stylesheet Pre/Post Compile events never sent

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
airelibre
Dev Team Member
Dev Team Member
Posts: 98
Joined: Tue Dec 01, 2009 3:42 pm
Location: Alsace // France

Re: [open] Stylesheet Pre/Post Compile events never sent

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: [open] Stylesheet Pre/Post Compile events never sent

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
airelibre
Dev Team Member
Dev Team Member
Posts: 98
Joined: Tue Dec 01, 2009 3:42 pm
Location: Alsace // France

Re: [open] Stylesheet Pre/Post Compile events never sent

Post 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?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: [open] Stylesheet Pre/Post Compile events never sent

Post by calguy1000 »

Fixed in svn.

Gotta test again with the different {cms_stylesheet} params but we should be good to go.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
airelibre
Dev Team Member
Dev Team Member
Posts: 98
Joined: Tue Dec 01, 2009 3:42 pm
Location: Alsace // France

Re: [fixed] Stylesheet Pre/Post Compile events never sent

Post 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

Code: Select all

{uploads_url}
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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: [fixed] Stylesheet Pre/Post Compile events never sent

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
airelibre
Dev Team Member
Dev Team Member
Posts: 98
Joined: Tue Dec 01, 2009 3:42 pm
Location: Alsace // France

Re: [fixed] Stylesheet Pre/Post Compile events never sent

Post 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
Post Reply

Return to “Closed Issues”