jaythakur / minify

Automatically exported from code.google.com/p/minify
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Integration with the Zend Framework #105

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice to see this library integrated into the Zend Framework. 
Right now I'm hacking around ZF and Minify to get them to work together.

It would be nice to have a more fluid integration.

Original issue reported on code.google.com by leeked on 21 Apr 2009 at 6:38

GoogleCodeExporter commented 9 years ago
Note: This is more of a task/enhancement, but for some reason I could only 
enter it as 
a 'defect'.

Original comment by leeked on 21 Apr 2009 at 6:39

GoogleCodeExporter commented 9 years ago
How do you imagine such an integration? What would the API/end user code look 
like? 
I've yet to do any serious work with ZF, but making Minify easier to work into 
existing frameworks is a goal I'm behind.

At the very least we could host some code in the repo/guide on the wiki.

Original comment by mrclay....@gmail.com on 21 Apr 2009 at 7:27

GoogleCodeExporter commented 9 years ago
I've done some integration with Zend Framework on projects I work on, and so 
far its
consisted of the following pieces:

-config file that is an array of js or css files
-section in the Initializer that uses Zend_Registry to register the array of 
js/css
to be used by other classes (view helper)
-view helper use Minify_Build and config array in Zend_Registry to render the 
script
include, or include the scripts un-minified if a disabled flag is set (useful 
for
development)
-last piece is a js.php or css.php file in the public that gets the same js/css
config array, and actually outputs the minified data using Minify::serve();

There may be a better way, but so far that's what I've come up with.  I'd be 
glad to
help out with sharing the View Helper, and other pieces of code as a tutorial 
of sorts.

Original comment by bmhar...@gmail.com on 9 Jun 2009 at 8:08

GoogleCodeExporter commented 9 years ago
It would be great if it tapped into the HeadSCript and HeadStyle plugins, so 
you 
wouldn't need a config array of files to maintain. By extending those plugins 
you could 
potentially create a unified minified file per page, and wirte the reference 
for that new 
file into the HTML page -- all without affecting anything either the developer 
or the end 
user comes into regular contact with.

Original comment by marcelko...@googlemail.com on 16 Feb 2010 at 11:22

GoogleCodeExporter commented 9 years ago
I already wrote Zend framework plugins for Minify, although some of the code is
slightly specific to my own project (and thus you couldn't just drop these two 
plugin
files in place and use them).  I did this via View Helpers (created one called
MinifyScript.php and one called MinStyleSheets.php) and then in my layout I 
call to

    <?= $this->minStyleSheets() ?>
    <?= $this->minifyScript() ?>

instead of $this->headScript() and $this->headLink() or whatever it was before. 
Downside is that if you had any other <link /> tags they wouldn't print, but in 
my
case I did not.  I imagine MinStyleSheets.php could probably be expanded to 
clear out
stylesheet link tags and leave all others in place, and $this->headLink() could 
still
be called, but I didn't fiddle much with it.  Same goes for $this->headScript() 
(as a
result of how I did this, I had to duplicate some code to handle inline scripts 
in
MinifyScript, but if the linked scripts were just cleared out, you could still 
call
headScript() instead which I think is cleaner, but again, I didn't fiddle much 
with it).

Note that this approach requires you to use the headLink()/headScript() view 
helpers
to add javascript and CSS files

$this->headLink()->appendStylesheet( $this->baseUrl . '/public/userbar.css' );
$this->headScript()->appendFile( $this->baseUrl . 
'/public/javascript/userbar.js' );

In both functions you'd need to fix getMinUrl() and getBaseUrl(), and replace 
any
references of FrameWork_Lib::getBaseURI() in the files.

Hopefully the attached files help.

Original comment by brandon....@gmail.com on 16 Feb 2010 at 1:51

Attachments:

GoogleCodeExporter commented 9 years ago
Oh, to add to my last comment, I had a basis for both classes (I didn't write 
them
from scratch).  Reference to the original code:

http://www.gsdesign.ro/blog/minify-css-in-zendframework/

Original comment by brandon....@gmail.com on 16 Feb 2010 at 1:53

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
You might want to glimpse at a similar component I have built for my library 
(which uses Zend Framework. It can minify and bundle in a master file css and 
js using common algorithms such as Yui or Crockford) and of course code from 
here (big thanks to the author for the Yui implementation) it uses the headLink 
and headScript view helpers, it can append inline scripting and it caches 
everything so that the file is not generated over and over. The library is 
still in early development but maybe that could help you a bit in what you 
would want to achieve. Code is written in PHP5.3. No documentation as of yet 
but who knows, it may still be of use for someone up to today! You can check it 
out here: 
http://github.com/majisti/Majisti/tree/master/library/Majisti/View/Helper/Head/

Original comment by Rat...@gmail.com on 21 Jun 2010 at 11:58

GoogleCodeExporter commented 9 years ago
Brandon made a great start. But I was looking for a drop in replacement for 
headLink(). I have made a version which needs Minify on the include path. It 
outputs the generated css file to a local file instead of calling the php 
version of minify. I guess the web server can just as well (with less memory 
usage!) send the static file and headers needed.

It is not thoroughly tested and should be considered a draft. The interface of 
Minify is not really that great to use for integration into other applications, 
as it has a lot of cross references. But it should do the job.

Usage:
1. Add the file to your library.
2. Set up the view to use the new helper.
3. Create a folder 'cached' in your document root.

Original comment by mkoons...@gmail.com on 30 Jun 2010 at 6:31

Attachments:

GoogleCodeExporter commented 9 years ago
Great Stuff mkoonstra this is much more along the lines I was looking for.

I've also implemented a similar solution for HeadScript which uses the google 
closure compiler:
http://github.com/balupton/balphp/blob/master/lib/Bal/View/Helper/HeadScriptBund
ler.php

Original comment by balup...@gmail.com on 16 Oct 2010 at 12:43

GoogleCodeExporter commented 9 years ago
Drop in Zend Script Helpers for Minify -> 
https://github.com/bubba-h57/zf-helpers

Original comment by r...@hines57.com on 10 Feb 2011 at 5:20

GoogleCodeExporter commented 9 years ago
thanks

Original comment by vinusem...@gmail.com on 11 Feb 2011 at 7:49

GoogleCodeExporter commented 9 years ago

Original comment by mrclay....@gmail.com on 3 Sep 2011 at 11:43