Created
December 26, 2013 11:50
-
-
Save berarma/8132793 to your computer and use it in GitHub Desktop.
CakePHP helper class that extends AssetCompress.AssetCompress to inline CSS and JS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('AssetCompress.AssetCompress', 'View/Helper'); | |
class AssetsHelper extends AssetCompressHelper { | |
public function inlineCss($file, $options = array()) { | |
if (Configure::read('debug') > 0) { | |
return $this->css($file, $options); | |
} | |
$file = $this->_addExt($file, '.css'); | |
$path = $this->config()->cachePath('css'); | |
$fullFilePath = $path . $this->_getBuildName($file); | |
$fileContents = file_get_contents($fullFilePath); | |
return $this->Html->tag('style', $fileContents, array('type' => 'text/css')); | |
} | |
public function inlineScript($file, $options = array()) { | |
if (Configure::read('debug') > 0) { | |
return $this->script($file, $options); | |
} | |
$file = $this->_addExt($file, '.js'); | |
$path = $this->config()->cachePath('js'); | |
$fullFilePath = $path . $this->_getBuildName($file); | |
$fileContents = file_get_contents($fullFilePath); | |
return $this->Html->scriptBlock($fileContents); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment