Skip to content

Commit

Permalink
Up
Browse files Browse the repository at this point in the history
  • Loading branch information
rmrevin committed May 16, 2014
1 parent 6fe41e6 commit 9ee0b44
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions View.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class View extends \yii\web\View
*/
public $expand_imports = true;

/**
* @var int
*/
public $css_linebreak_pos = 2048;

/**
* @var int chmod of minified file
*/
Expand Down Expand Up @@ -129,7 +134,7 @@ private function minifyCSS()
$fonts = '';

foreach ($css_files as $file) {
$content = file_get_contents(\Yii::getAlias($this->base_path) . $file) . PHP_EOL;
$content = file_get_contents(\Yii::getAlias($this->base_path) . $file);

preg_match_all('|url\(([^)]+)\)|is', $content, $m);
if (!empty($m[0])) {
Expand All @@ -150,10 +155,10 @@ private function minifyCSS()
}

if (true === $this->expand_imports) {
preg_match_all('|(\@import\s([^;]+))|is', $css, $m);
preg_match_all('|\@import\s([^;]+);|is', $css, $m);
if (!empty($m[0])) {
foreach ($m[0] as $k => $v) {
$import_url = $m[2][$k];
$import_url = $m[1][$k];
if (!empty($import_url)) {
$import_content = $this->getImportContent($import_url);
if (!empty($import_content)) {
Expand All @@ -164,7 +169,7 @@ private function minifyCSS()
}
}

$css = (new \CSSmin())->run($css);
$css = (new \CSSmin())->run($css, $this->css_linebreak_pos);

if (false !== $this->force_charset) {
$charsets = '@charset "' . (string)$this->force_charset . '";' . PHP_EOL;
Expand Down Expand Up @@ -238,15 +243,15 @@ private function minifyJS()

$js_minify_file = $this->minify_path . DIRECTORY_SEPARATOR . sha1($long_hash) . '.js';
if (!file_exists($js_minify_file)) {
$data = '';
$js = '';
foreach ($files as $file => $html) {
$file = \Yii::getAlias($this->base_path) . $file;
$data .= file_get_contents($file) . ';' . PHP_EOL;
$js .= file_get_contents($file) . ';' . PHP_EOL;
}

$data = \JSMin::minify($data);
$js = (new \JSMin($js))->min();

file_put_contents($js_minify_file, $data);
file_put_contents($js_minify_file, $js);
chmod($js_minify_file, $this->file_mode);
}

Expand Down

0 comments on commit 9ee0b44

Please sign in to comment.