Skip to content

Commit

Permalink
Merge pull request #1 from liuggio/master
Browse files Browse the repository at this point in the history
YUI Compression as variable
  • Loading branch information
athoune committed Dec 15, 2011
2 parents 79d31f1 + 3d23a36 commit df0511f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
5 changes: 0 additions & 5 deletions README

This file was deleted.

40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
YUI-compressor meets Drupal


Installation
---------------------------------------


1. go to your sites/all/modules/

2. __clone repository__

git clone https://github.com/athoune/Drupal-Compressor compressor

3. __download the latest YUI compressor__

get yuicompressor-X.Y.Z.jar from its website and put into sites/all/modules/compressor

http://developer.yahoo.com/yui/compressor/

4. into admin/settings/file-system

__enable radio button Public and sites/default/files must be writable__

5. __enable 'compressor' in admin/build/modules/list__

6. __enable the CSS and JS compression into admin/settings/performance__

and be sure that your version of yuicompressor-X.Y.Z.jar is on the same the path


Contribution
---------------------------------------

1- athoune

2- liuggio




18 changes: 17 additions & 1 deletion compressor.module
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@ function compressor_help($path, $arg) {
}
}


function getYuiCompressorPath()
{
$path = dirname(__FILE__) . '/yuicompressor-2.4.7.jar';
return variable_get('yuicompressorpath', $path);
}
/**
* Implementation of hook_form_alter().
*/
function compressor_form_alter(&$form, $form_state, $form_id) {

if ($form_id == 'system_performance_settings') {
$form['bandwidth_optimizations']['preprocess_js']['#title'] = t('Optimize and YUI Compress JavaScript files');
$form['bandwidth_optimizations']['preprocess_css']['#title'] = t('Optimize and YUI Compress CSS files');
$form['bandwidth_optimizations']['yuicompressorpath'] = array(
'#type' => 'textfield',
'#title' => t('Path to the yiu-compressor. <br>Download it into ' . $path . ''),
'#default_value' => getYuiCompressorPath(),
'#size' => 120,
);
$form['bandwidth_optimizations']['minify_js']['#description'] .= t(' Once the JavaScript files have been aggregated, they will be minified.');
}
}
Expand All @@ -29,10 +42,12 @@ function compressor_form_alter(&$form, $form_state, $form_id) {
* Minify the aggregated JavaScript file if JavaScript Optimization is turned on.
*/
function compressor_preprocess_page(&$variables) {
$compressor = dirname(__FILE__) . '/yuicompressor-2.4.2.jar';
$compressor = getYuiCompressorPath();
global $user;

// Only do this for pages that have CSS on them.
if (!empty($variables['styles'])) {

// Only process it is CSS Optimization is enabled.
if (variable_get('preprocess_css', 0)) {
// Strip out the aggregated JavaScript file.
Expand All @@ -44,6 +59,7 @@ function compressor_preprocess_page(&$variables) {
if(substr($dir_file,0,1) != '/') {
$dir_file = getcwd() .'/'. $dir_file;
}

foreach($matches[1] as $aggregated_file) {
$css_file_path = file_directory_path() . $aggregated_file;
$cssmin_file_path = str_replace('.css', '.min.css', $css_file_path);
Expand Down

0 comments on commit df0511f

Please sign in to comment.