Author: gimler Date: 2010-03-10 12:51:08 +0100 (Wed, 10 Mar 2010) New Revision: 28454
Added: plugins/sfMinifyPlugin/trunk/lib/helper/MinifyHelper.php Removed: plugins/sfMinifyPlugin/trunk/lib/filter/ plugins/sfMinifyPlugin/trunk/lib/helper/SfMinifyHelper.php Modified: plugins/sfMinifyPlugin/trunk/ plugins/sfMinifyPlugin/trunk/README Log: sfMinifyPlugin: update google minify; update for symfony 1.3 and 1.4; add enabled config param for js and css Property changes on: plugins/sfMinifyPlugin/trunk ___________________________________________________________________ Modified: svn:externals - minify http://minify.googlecode.com/svn/tags/release_2.0.1/ + minify http://minify.googlecode.com/svn/tags/release_2.1.3/ Modified: plugins/sfMinifyPlugin/trunk/README =================================================================== --- plugins/sfMinifyPlugin/trunk/README 2010-03-10 07:41:24 UTC (rev 28453) +++ plugins/sfMinifyPlugin/trunk/README 2010-03-10 11:51:08 UTC (rev 28454) @@ -6,46 +6,74 @@ Combines, minifies, and caches JavaScript and CSS files on demand to speed up page loads. -## Usage +## Installation ## - * add this to your ``.htaccess`` file + * Install the plugin (via a package) + symfony plugin:install sfMinifyPlugin + + * Install the plugin (via a Subversion checkout) + + svn co http//svn.symfony-project.com/plugins/sfMinifyPlugin/trunk plugins/sfMinifyPlugin + + * Activate the plugin in the `config/ProjectConfiguration.class.php` + + [php] + class ProjectConfiguration extends sfProjectConfiguration + { + public function setup() + { + $this->enablePlugins(array( + 'sfMinifyPlugin', + '...' + )); + } + } + + * Copy ``plugins/sfMinifyPlugin/web/sfMinifyPlugin.php`` to your ``web`` directory + + * Add this to your ``.htaccess`` file + [plain] # Combine and minify JavaScript and CSS with Minify. - RewriteRule ^(.*\.(css|js))$ ../plugins/sfMinifyPlugin/sfMinifyPlugin.php?f=/$1 [L,NC] + RewriteRule ^minify/(.*\.(css|js))$ sfMinifyPlugin.php?f=/$1 [L,NC] if you have run symfony on a subdirectory change it to [plain] # Combine and minify JavaScript and CSS with Minify. - RewriteRule ^(.*\.(css|js))$ ../plugins/sfMinifyPlugin/sfMinifyPlugin.php?f=/subdirectory/$1 [L,NC] + RewriteRule ^minify/(.*\.(css|js))$ sfMinifyPlugin.php?f=/subdirectory/$1 [L,NC] - * copy ``plugins/sfMinifyPlugin/web/sfMinifyPlugin.php`` to your ``web`` directory and edit the project configuration +### Helper -### Filter or Helper +you can activate minify over with the helpers simple add/change the helper in your layout file (default ``layout.php``) to -you can activate minify over the filter or with the helpers - - * change the common filter in your ``filters.yml`` to - - [plain] - common: - class: sfMinifyFilter # Filter class - param: - javascripts: true - stylesheets: true - - * or add/change the helper in your layout file (default ``layout.php``) to - [php] - use_helper('SfMinify'); + use_helper('Minify'); minify_include_javascript(); minify_include_stylesheets(); ### Configuration -you can enable and disable javascript or stylesheet minify by setting the params in ``filter.yml`` by default both types will be minified +Enable the plugin features through app.yml. You should enable the plugin only in the production and staging environments. This is because the plugin overhead is noticeable in the development environment, and because the plugin strips comments and whitespaces from your script and CSS files, making editions harder. So keep the plugin disabled in the development environment. A typical plugin setup would look like this: + [yaml] + # in apps/frontend/config/app.yml + dev: + sfMinifyPlugin: + js: + enabled: false # disable minify for js files in development + css: + enabled: false # disable minify for css files in development + + all: + sfMinifyPlugin: + asset_version: 1 # key to the asset version (see below) + js: + enabled: true # activate minify for js files + css: + enabled: true # activate minify for css files + #### Compression to compress the files simple set the ``compressed`` option to on in ``settings.yml`` Copied: plugins/sfMinifyPlugin/trunk/lib/helper/MinifyHelper.php (from rev 28453, plugins/sfMinifyPlugin/trunk/lib/helper/SfMinifyHelper.php) =================================================================== --- plugins/sfMinifyPlugin/trunk/lib/helper/MinifyHelper.php (rev 0) +++ plugins/sfMinifyPlugin/trunk/lib/helper/MinifyHelper.php 2010-03-10 11:51:08 UTC (rev 28454) @@ -0,0 +1,157 @@ +<?php +/** + * Return one <script> tag for all javascripts configured in view.yml or added to the response object. + * + * You can use this helper to decide the location of javascripts in pages. + * By default, if you don't call this helper, symfony will automatically include javascripts before </head>. + * Calling this helper disables this behavior. + * + * @return string <script> tag + */ +function minify_get_javascripts() +{ + $jsSettings = sfConfig::get('app_sfMinifyPlugin_js'); + if(!$jsSettings['enabled']) return get_javascripts(); + + $response = sfContext::getInstance()->getResponse(); + sfConfig::set('symfony.asset.javascripts_included', true); + + $already_seen = array(); + $minify_files = array(); + foreach ($response->getPositions() as $position) + { + foreach ($response->getJavascripts($position) as $files => $options) + { + if (!is_array($files)) + { + $files = array($files); + } + + $options = array_merge(array('type' => 'text/javascript')); + foreach ($files as $file) + { + if (isset($already_seen[$file])) continue; + + $already_seen[$file] = 1; + + $file = javascript_path($file); + $type = serialize($options); + + if(isset($minify_files[$type])) + { + array_push($minify_files[$type], $file); + } + else + { + $minify_files[$type] = array($file); + } + } + } + } + + $html = ''; + foreach($minify_files as $options => $files) + { + $options = unserialize($options); + $options['src'] = '/minify'.join($files, ','); + $html .= content_tag('script', '', $options)."\n"; + } + + return $html; +} + +/** + * Print <script> tag for all javascripts configured in view.yml or added to the response object. + * + * @see minify_get_javascripts() + */ +function minify_include_javascripts() +{ + echo minify_get_javascripts(); +} + +/** + * Return one <link> tag for all stylesheets configured in view.yml or added to the response object. + * + * You can use this helper to decide the location of stylesheets in pages. + * By default, if you don't call this helper, symfony will automatically include stylesheets before </head>. + * Calling this helper disables this behavior. + * + * @return string <link> tags + */ +function minify_get_stylesheets() +{ + $cssSettings = sfConfig::get('app_sfMinifyPlugin_css'); + if(!$cssSettings['enabled']) return get_stylesheets(); + + $response = sfContext::getInstance()->getResponse(); + sfConfig::set('symfony.asset.stylesheets_included', true); + + $already_seen = array(); + $minify_files = array(); + foreach ($response->getPositions() as $position) + { + foreach ($response->getStylesheets($position) as $files => $options) + { + if (!is_array($files)) + { + $files = array($files); + } + + $options = array_merge(array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen'), $options); + foreach ($files as $file) + { + if (isset($already_seen[$file])) continue; + + $already_seen[$file] = 1; + + $absolute = false; + if (isset($options['absolute'])) + { + unset($options['absolute']); + $absolute = true; + } + + if(!isset($options['raw_name'])) + { + $file = stylesheet_path($file, $absolute); + } + else + { + unset($options['raw_name']); + } + + $type = serialize($options); + + if(isset($minify_files[$type])) + { + array_push($minify_files[$type], $file); + } + else + { + $minify_files[$type] = array($file); + } + } + } + } + + $html = ''; + foreach($minify_files as $options => $files) + { + $options = unserialize($options); + $options['href'] = '/minify'.join($files, ','); + $html .= tag('link', $options)."\n"; + } + + return $html; +} + +/** + * Print <link> tag for all stylesheets configured in view.yml or added to the response object. + * + * @see minify_get_stylesheets() + */ +function minify_include_stylesheets() +{ + echo minify_get_stylesheets(); +} Deleted: plugins/sfMinifyPlugin/trunk/lib/helper/SfMinifyHelper.php =================================================================== --- plugins/sfMinifyPlugin/trunk/lib/helper/SfMinifyHelper.php 2010-03-10 07:41:24 UTC (rev 28453) +++ plugins/sfMinifyPlugin/trunk/lib/helper/SfMinifyHelper.php 2010-03-10 11:51:08 UTC (rev 28454) @@ -1,153 +0,0 @@ -<?php -/** - * Return one <script> tag for all javascripts configured in view.yml or added to the response object. - * - * You can use this helper to decide the location of javascripts in pages. - * By default, if you don't call this helper, symfony will automatically include javascripts before </head>. - * Calling this helper disables this behavior. - * - * @return string <script> tag - */ -function minify_get_javascripts($response, $minify) -{ - if(!$minify) return get_javascripts(); - - sfConfig::set('symfony.asset.javascripts_included', true); - - $already_seen = array(); - $minify_files = array(); - foreach ($response->getPositions() as $position) - { - foreach ($response->getJavascripts($position) as $files => $options) - { - if (!is_array($files)) - { - $files = array($files); - } - - $options = array_merge(array('type' => 'text/javascript')); - foreach ($files as $file) - { - if (isset($already_seen[$file])) continue; - - $already_seen[$file] = 1; - - $file = javascript_path($file); - $type = serialize($options); - - if(isset($minify_files[$type])) - { - array_push($minify_files[$type], $file); - } - else - { - $minify_files[$type] = array($file); - } - } - } - } - - $html = ''; - foreach($minify_files as $options => $files) - { - $options = unserialize($options); - $options['src'] = join($files, ','); - $html .= content_tag('script', '', $options)."\n"; - } - - return $html; -} - -/** - * Print <script> tag for all javascripts configured in view.yml or added to the response object. - * - * @see minify_get_javascripts() - */ -function minify_include_javascripts() -{ - echo minify_get_javascripts(); -} - -/** - * Return one <link> tag for all stylesheets configured in view.yml or added to the response object. - * - * You can use this helper to decide the location of stylesheets in pages. - * By default, if you don't call this helper, symfony will automatically include stylesheets before </head>. - * Calling this helper disables this behavior. - * - * @return string <link> tags - */ -function minify_get_stylesheets($response, $minify) -{ - if(!$minify) return get_stylesheets(); - - sfConfig::set('symfony.asset.stylesheets_included', true); - - $already_seen = array(); - $minify_files = array(); - foreach ($response->getPositions() as $position) - { - foreach ($response->getStylesheets($position) as $files => $options) - { - if (!is_array($files)) - { - $files = array($files); - } - - $options = array_merge(array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'screen'), $options); - foreach ($files as $file) - { - if (isset($already_seen[$file])) continue; - - $already_seen[$file] = 1; - - $absolute = false; - if (isset($options['absolute'])) - { - unset($options['absolute']); - $absolute = true; - } - - if(!isset($options['raw_name'])) - { - $file = stylesheet_path($file, $absolute); - } - else - { - unset($options['raw_name']); - } - - $type = serialize($options); - - if(isset($minify_files[$type])) - { - array_push($minify_files[$type], $file); - } - else - { - $minify_files[$type] = array($file); - } - } - } - } - - $html = ''; - foreach($minify_files as $options => $files) - { - $options = unserialize($options); - $options['href'] = join($files, ','); - $html .= tag('link', $options)."\n"; - } - - return $html; -} - -/** - * Print <link> tag for all stylesheets configured in view.yml or added to the response object. - * - * @see minify_get_stylesheets() - */ -function minify_include_stylesheets() -{ - echo minify_get_stylesheets(); -} -- You received this message because you are subscribed to the Google Groups "symfony SVN" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/symfony-svn?hl=en.
