Skip to content

Commit

Permalink
Cleaned up a few vars to match CI coding standards.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericlbarnes committed Apr 23, 2011
1 parent 422fe99 commit 84f19af
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
45 changes: 23 additions & 22 deletions libraries/Minify/Minify.php
Expand Up @@ -53,19 +53,19 @@ public function __construct($params = array())
* @author Eric Barnes, F.S.Encinas
* @param array $files
* @param string $type
* @param string $cssCharset
* @param bool $compact
* @return void
* @param string $css_charset
* @return mixed
*/
public function combine_files($files = array(), $type = '', $compact = TRUE, $cssCharset = 'utf-8')
public function combine_files($files = array(), $type = '', $compact = TRUE, $css_charset = 'utf-8')
{
if ( !is_array($files) OR count($files) < 1)
if ( ! is_array($files) OR count($files) < 1)
{
log_message('error', 'Minify->combine_files missing files array');
return FALSE;
}

return $this->_do_combine($files, $type, $compact, $cssCharset);
return $this->_do_combine($files, $type, $compact, $css_charset);
}

// ------------------------------------------------------------------------
Expand All @@ -78,11 +78,11 @@ public function combine_files($files = array(), $type = '', $compact = TRUE, $cs
* @param string $directory
* @param array $ignore
* @param string $type
* @param string $cssCharset
* @param bool $compact
* @param string $css_charset
* @return string
*/
public function combine_directory($directory = '', $ignore = array(), $type = '', $compact = TRUE, $cssCharset = 'utf-8')
public function combine_directory($directory = '', $ignore = array(), $type = '', $compact = TRUE, $css_charset = 'utf-8')
{
$available = array();

Expand Down Expand Up @@ -113,7 +113,7 @@ public function combine_directory($directory = '', $ignore = array(), $type = ''
}
}

return $this->_do_combine($available, $type, $compact, $cssCharset);
return $this->_do_combine($available, $type, $compact, $css_charset);
}

// ------------------------------------------------------------------------
Expand All @@ -126,47 +126,48 @@ public function combine_directory($directory = '', $ignore = array(), $type = ''
* @author Eric Barnes, F.S.Encinas
* @param array $files
* @param string $type
* @param string $cssCharset
* @param bool $compact
* @param string $css_charset
* @return string
*/
private function _do_combine($files, $type, $compact = TRUE, $cssCharset = 'utf-8')
private function _do_combine($files, $type, $compact = TRUE, $css_charset = 'utf-8')
{
$contents = '';
$fileCount = 0;
$file_count = 0;

foreach ($files AS $file)
{
if ( !file_exists($file))
if ( ! file_exists($file))
{
log_message('error', 'Minify->_do_combine missing file ' . $file);
log_message('error', 'Minify->_do_combine missing file '.$file);
continue;
}

$fileCount++;
$file_count++;

if ($type == '')
{
$type = $this->_get_type($file);
}

$pathInf = pathinfo($file, PATHINFO_BASENAME); // Referal File and path
$path_info = pathinfo($file, PATHINFO_BASENAME); // Referal File and path

if ($type == 'css')
{
// only one charset placed at the beginning of the document is allowed
// in order to keep standars compliance and fixing Webkit problems
// Note: Minify_css driver yet remove all charsets previously
if ($fileCount == 1) {
$contents .= '@charset "'. $cssCharset .'";' . "\n";
if ($file_count == 1)
{
$contents .= '@charset "'.$css_charset.'";'."\n";
}
$contents .= "\n" . '/* @fileRef ' . $pathInf . ' */' . "\n";
$contents .= $this->css->min($file, $compact, $isaggregated = TRUE);
$contents .= "\n".'/* @fileRef '.$path_info.' */'."\n";
$contents .= $this->css->min($file, $compact, $is_aggregated = TRUE);
}
elseif ($type == 'js')
{
unset($cssCharset);
$contents .= "\n" . '// @fileRef ' . $pathInf . ' ' . "\n";
unset($css_charset);
$contents .= "\n".'// @fileRef '.$path_info.' '."\n";
$contents .= $this->js->min($file, $compact);
}
else
Expand All @@ -193,7 +194,7 @@ public function save_file($contents = '', $full_path = '')
{
$this->_ci->load->helper('file');

if ( !write_file($full_path, $contents))
if ( ! write_file($full_path, $contents))
{
log_message('error', 'Minify->save_file could not write file');
return FALSE;
Expand Down
31 changes: 15 additions & 16 deletions libraries/Minify/drivers/Minify_css.php
Expand Up @@ -36,30 +36,30 @@ public function __construct()
* @param bool $compact
* @return string
*/
public function min($file = '', $compact = TRUE, $isaggregated = NULL)
public function min($file = '', $compact = TRUE, $is_aggregated = NULL)
{
if ($file == '' OR !file_exists($file))
if ($file == '' OR ! file_exists($file))
{
log_message('error', 'Minify_css->min missing file ' . $file);
log_message('error', 'Minify_css->min missing file '.$file);
return FALSE;
}

if (!isset($isaggregated))
if ( ! isset($is_aggregated))
{
$contents = file_get_contents($file);
}
else
{
$contents = $this->removeCharsets(file_get_contents($file));
$contents = $this->remove_charsets(file_get_contents($file));
}

if ( $compact != FALSE )
if ($compact != FALSE)
{
return trim($this->_optimize($contents)) . "\n";
return trim($this->_optimize($contents))."\n";
}
else
{
return "\n" . trim($contents) . "\n\n";
return "\n".trim($contents)."\n\n";
}
}

Expand All @@ -70,14 +70,14 @@ public function min($file = '', $compact = TRUE, $isaggregated = NULL)
* charset declarations removal to support do combine function
* in order to set a new one user defined charset at the beggining of the document
* to keep standars compliance (and fix Webkit buggy behaviours)
*
* @author F.S.Encinas
* @param string $contents
* @return string
*/
private function removeCharsets($contents) {

private function remove_charsets($contents)
{
return preg_replace('/^@charset\s+[\'"](\S*)\b[\'"];/i', '', $contents);

}

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -121,7 +121,7 @@ private function _optimize($contents)
# - Colon: Retain :pseudo-selectors.
'| ([\(:])\s+' .
'>xS',
array(get_class($this), '_optimizeCB'),
array(get_class($this), '_optimize_call_back'),
$contents
);

Expand All @@ -132,19 +132,18 @@ private function _optimize($contents)
* Optimize CB
* Optimize Callback Helper companion for optimize fn
* based on Drupal 7 CSS Core aggregator
*
*
* @author F.S.Encinas
* @param string $matches
* @return array
*/
private function _optimizeCB($matches) {

private function _optimize_call_back($matches)
{
// Discard the full match.
unset($matches[0]);

// Use the non-empty match.
return current(array_filter($matches));

}
}

Expand Down
6 changes: 3 additions & 3 deletions libraries/Minify/drivers/Minify_js.php
Expand Up @@ -47,13 +47,13 @@ public function min($file = '', $compact = TRUE)

$contents = file_get_contents($file);

if ( $compact != FALSE )
if ($compact != FALSE)
{
return trim(JSMin::minify($contents)) . "\n";
return trim(JSMin::minify($contents))."\n";
}
else
{
return "\n" . trim($contents) . "\n\n";
return "\n".trim($contents)."\n\n";
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Expand Up @@ -49,14 +49,14 @@ echo $this->minify->combine_directory('test/css/, array('all.css'), [optionalPar

Optional Params
<pre>
combine_files($files, [type], [compact], [cssCharset]);
combine_directory($directory, [ignore], [type], [compact], [cssCharset]);
combine_files($files, [type], [compact], [css_charset]);
combine_directory($directory, [ignore], [type], [compact], [css_charset]);
</pre>
Common:
<pre>
[type]: string ('css' or 'js')
[compact] : bool (TRUE, FALSE). TRUE Compact/compress output, FALSE doesn't compress output (only aggregation)
[cssCharset] : string (default 'utf-8'). If CSS you can force a starting single charset declaration (when aggregate files)
[css_charset] : string (default 'utf-8'). If CSS you can force a starting single charset declaration (when aggregate files)
due to the charset pre-removal (for stantdars compliance and Webkit bugfix prevention)
set to null or leave empty if JS.
</pre>
Expand All @@ -66,5 +66,5 @@ Combine dir:
</pre>

## Credits

fsencinas - (https://github.com/fsencinas)
JS-Min - (https://github.com/rgrove/jsmin-php)

0 comments on commit 84f19af

Please sign in to comment.