mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-24 04:42:14 +09:00
#18544647 Optimizer 사용시 CSS, Javascript에서 주석 제거, 줄 앞, 뒤 공백 제거
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7040 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
2416ab790c
commit
7fe42cfdbe
1 changed files with 20 additions and 5 deletions
|
|
@ -136,26 +136,30 @@
|
|||
* 실제 css나 js의 내용을 합친 것을 구함
|
||||
**/
|
||||
// 대상 파일의 내용을 구해오고 css 파일일 경우 url()내의 경로를 변경
|
||||
|
||||
$content_filename = substr($filename, 0, -4);
|
||||
$file_object = FileHandler::openFile($path."/".$content_filename, "w");
|
||||
|
||||
if($type == 'css') $file_object->write('@charset "UTF-8";'."\n");
|
||||
$str_to_write = '';
|
||||
if($type == 'css') $str_to_write .= '@charset "UTF-8";'."\n";
|
||||
|
||||
foreach($targets as $file) {
|
||||
$str = FileHandler::readFile($file['file']);
|
||||
|
||||
$str = Context::convertEncodingStr($str);
|
||||
$str = trim(Context::convertEncodingStr($str));
|
||||
|
||||
// css 일경우 background:url() 변경 / media 적용
|
||||
if($type == 'css') {
|
||||
$str = $this->replaceCssPath($file['file'], $str);
|
||||
if($file['media'] != 'all') $str = '@media '.$file['media'].' {'."\n".$str."\n".'}';
|
||||
}
|
||||
$file_object->write($str);
|
||||
$file_object->write("\n");
|
||||
$str_to_write .= $str;
|
||||
$str_to_write .= "\n";
|
||||
unset($str);
|
||||
}
|
||||
|
||||
$str_to_write = $this->doCompressCode($str_to_write);
|
||||
|
||||
$file_object->write($str_to_write);
|
||||
$file_object->close();
|
||||
|
||||
/**
|
||||
|
|
@ -247,5 +251,16 @@ if(!$cached) {
|
|||
return 'url("'.$target.'")';
|
||||
}
|
||||
|
||||
function doCompressCode($str_code) {
|
||||
$str_code = str_replace("\r", "\n", $str_code);
|
||||
$str_code = preg_replace("!^([ \t]+)!m", '', $str_code);
|
||||
$str_code = preg_replace("!([ \t]+)$!m", '', $str_code);
|
||||
$str_code = preg_replace("!^\/\*(\X*?)\*\/$!m", '', $str_code);
|
||||
$str_code = preg_replace('!^\/\/([^\n]*)!m', '', $str_code);
|
||||
$str_code = preg_replace("!(\n{2,})!m", "\n", $str_code);
|
||||
|
||||
return trim($str_code);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue