This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1af0e17
commit da058c1
Showing
6 changed files
with
202 additions
and
176 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
class ClientScript extends CClientScript | ||
{ | ||
public function render(&$output) | ||
{ | ||
if (Yii::app()->request->getIsAjaxRequest() && isset($_GET['callback'])) | ||
{ | ||
$scripts = ''; | ||
foreach ($this->scripts as $pos) | ||
{ | ||
foreach ($pos as $script) | ||
{ | ||
$scripts .= $script; | ||
} | ||
} | ||
$output = $scripts . "\n" . $_GET['callback'] . '({ content : "' . addslashes($output) . '" })'; | ||
} | ||
else | ||
{ | ||
parent::render($output); | ||
} | ||
} | ||
} |
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
348 changes: 174 additions & 174 deletions
348
protected/components/AssetManager.php → .../extensions/assetManager/AssetManager.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,174 +1,174 @@ | ||
<? | ||
/** | ||
* init version | ||
* PBMAssetManager class file. | ||
* @author Chris Yates <[email protected]> | ||
* @copyright Copyright © 2010 PBM Web Development | ||
* @license http://assetManager.googlecode.com/files/license.txt | ||
* @package PBM | ||
*/ | ||
|
||
/** | ||
* rewrite version | ||
*/ | ||
/** | ||
* PBMAssetManager class. | ||
* PBMAssetManager overrides CAssetManager::publish to provide parsing of assets | ||
* when required. | ||
* | ||
* Configuration | ||
* ------------- | ||
* Import the component. | ||
* Yii::import('path.to.component.PBMAssetManager'); | ||
* | ||
* Declare the use of this component as the asset manager component. This | ||
* example declares a Sass {@link } parser; multiple parsers may be declared. | ||
* <pre> | ||
* // application components | ||
* 'assetManager' => array( | ||
* 'class' => 'AssetManager', | ||
* 'parsers' => array( | ||
* 'sass' => array( // key == the type of file to parse | ||
* 'class' => 'ext.assetManager.Sass', // path alias to the parser | ||
* 'output' => 'css', // the file type it is parsed to | ||
* 'options' => array( | ||
* 'syntax' => 'sass' | ||
* ) | ||
* ), | ||
* 'scss' => array( // key == the type of file to parse | ||
* 'class' => 'ext.assetManager.Sass', // path alias to the parser | ||
* 'output' => 'css', // the file type it is parsed to | ||
* 'options' => array( | ||
* 'syntax' => 'scss', | ||
* 'style' => 'compressed' | ||
* ) | ||
* ), | ||
* 'less' => array( // key == the type of file to parse | ||
* 'class' => 'ext.assetManager.Less', // path alias to the parser | ||
* 'output' => 'css', // the file type it is parsed to | ||
* 'options' => array( | ||
* 'syntax' => 'scss', | ||
* 'style' => 'compressed' | ||
* ) | ||
* ), | ||
* ), | ||
* 'newDirMode' => 0755, | ||
* 'newFileMode' => 0644 | ||
* ), | ||
* </pre> | ||
* | ||
* You can also declare the "force" parameter to be true. This forces assets to | ||
* be published whether newer than the published asset or not; this is for | ||
* development so that changes to deep files get published without having to | ||
* flush the asset directory. Make sure this parameter is removed or declared | ||
* false in production. | ||
* | ||
* Usage | ||
* ----- | ||
* Usage is exactly the same as publishing an asset with CAssetManager, i.e. | ||
* | ||
* $publishedAsset = Yii::app()->getAssetMananger()->publish(Yii::getPathOfAlias('allias.to.asset.directory'). DIRECTORY_SEPARATOR . 'asset.sass'); | ||
* | ||
* The only difference is that parsing of files will take place during the | ||
* publish. Files that do not require parsing are handled exactly as before. | ||
* | ||
*/ | ||
class AssetManager extends CAssetManager { | ||
/** | ||
* @var array asset parsers | ||
*/ | ||
public $parsers; | ||
/** | ||
* @var boolean if true the asset will always be published | ||
*/ | ||
public $force = false; | ||
/** | ||
* @var string base web accessible path for storing private files | ||
*/ | ||
private $_basePath; | ||
/** | ||
* @var string base URL for accessing the publishing directory. | ||
*/ | ||
private $_baseUrl; | ||
/** | ||
* @var array published assets | ||
*/ | ||
private $_published=array(); | ||
|
||
|
||
public function publish($path,$hashByName=false,$level=-1,$forceCopy=false) | ||
{ | ||
$forceCopy = false; | ||
|
||
if($forceCopy===null) | ||
$forceCopy=$this->forceCopy; | ||
if(isset($this->_published[$path])) | ||
return $this->_published[$path]; | ||
else if(($src=realpath($path))!==false) | ||
{ | ||
if(is_file($src)) | ||
{ | ||
$dir=$this->hash($hashByName ? basename($src) : dirname($src)); | ||
$fileName=basename($src); | ||
//get extension for checking of exist format parsers | ||
$extension=pathinfo($fileName, PATHINFO_EXTENSION); | ||
$dstDir=$this->getBasePath().DIRECTORY_SEPARATOR.$dir; | ||
|
||
if (array_key_exists($extension, $this->parsers)) | ||
{ | ||
$fileName=basename($src, $extension).$this->parsers[$extension]['output']; | ||
} | ||
$dstFile=$dstDir.DIRECTORY_SEPARATOR.$fileName; | ||
|
||
if($this->force || @filemtime($dstFile)<@filemtime($src)) | ||
{ | ||
if(!is_dir($dstDir)) | ||
{ | ||
mkdir($dstDir); | ||
@chmod($dstDir,0777); | ||
} | ||
|
||
//if exist parser for this format than - parse it! | ||
if (array_key_exists($extension, $this->parsers)) | ||
{ | ||
$parserClass = Yii::import($this->parsers[$extension]['class']); | ||
$parser = new $parserClass($this->parsers[$extension]['options']); | ||
file_put_contents($dstFile, $parser->parse($src)); | ||
} | ||
else | ||
{ | ||
copy($src,$dstFile); | ||
} | ||
@chmod($dstFile, $this->newFileMode); | ||
} | ||
|
||
return $this->_published[$path]=$this->getBaseUrl()."/$dir/$fileName"; | ||
} | ||
else if(is_dir($src)) | ||
{ | ||
$dir=$this->hash($hashByName ? basename($src) : $src.filemtime($src)); | ||
$dstDir=$this->getBasePath().DIRECTORY_SEPARATOR.$dir; | ||
|
||
if($this->linkAssets) | ||
{ | ||
if(!is_dir($dstDir)) | ||
symlink($src,$dstDir); | ||
} | ||
else if(!is_dir($dstDir) || $forceCopy) | ||
{ | ||
CFileHelper::copyDirectory($src,$dstDir,array( | ||
'exclude'=>$this->excludeFiles, | ||
'level'=>$level, | ||
'newDirMode'=>$this->newDirMode, | ||
'newFileMode'=>$this->newFileMode, | ||
)); | ||
} | ||
|
||
return $this->_published[$path]=$this->getBaseUrl().'/'.$dir; | ||
} | ||
} | ||
throw new CException(Yii::t('yii','The asset "{asset}" to be published does not exist.', | ||
array('{asset}'=>$path))); | ||
} | ||
|
||
} | ||
<? | ||
/** | ||
* init version | ||
* PBMAssetManager class file. | ||
* @author Chris Yates <[email protected]> | ||
* @copyright Copyright © 2010 PBM Web Development | ||
* @license http://assetManager.googlecode.com/files/license.txt | ||
* @package PBM | ||
*/ | ||
|
||
/** | ||
* rewrite version | ||
*/ | ||
/** | ||
* PBMAssetManager class. | ||
* PBMAssetManager overrides CAssetManager::publish to provide parsing of assets | ||
* when required. | ||
* | ||
* Configuration | ||
* ------------- | ||
* Import the component. | ||
* Yii::import('path.to.component.PBMAssetManager'); | ||
* | ||
* Declare the use of this component as the asset manager component. This | ||
* example declares a Sass {@link } parser; multiple parsers may be declared. | ||
* <pre> | ||
* // application components | ||
* 'assetManager' => array( | ||
* 'class' => 'AssetManager', | ||
* 'parsers' => array( | ||
* 'sass' => array( // key == the type of file to parse | ||
* 'class' => 'ext.assetManager.Sass', // path alias to the parser | ||
* 'output' => 'css', // the file type it is parsed to | ||
* 'options' => array( | ||
* 'syntax' => 'sass' | ||
* ) | ||
* ), | ||
* 'scss' => array( // key == the type of file to parse | ||
* 'class' => 'ext.assetManager.Sass', // path alias to the parser | ||
* 'output' => 'css', // the file type it is parsed to | ||
* 'options' => array( | ||
* 'syntax' => 'scss', | ||
* 'style' => 'compressed' | ||
* ) | ||
* ), | ||
* 'less' => array( // key == the type of file to parse | ||
* 'class' => 'ext.assetManager.Less', // path alias to the parser | ||
* 'output' => 'css', // the file type it is parsed to | ||
* 'options' => array( | ||
* 'syntax' => 'scss', | ||
* 'style' => 'compressed' | ||
* ) | ||
* ), | ||
* ), | ||
* 'newDirMode' => 0755, | ||
* 'newFileMode' => 0644 | ||
* ), | ||
* </pre> | ||
* | ||
* You can also declare the "force" parameter to be true. This forces assets to | ||
* be published whether newer than the published asset or not; this is for | ||
* development so that changes to deep files get published without having to | ||
* flush the asset directory. Make sure this parameter is removed or declared | ||
* false in production. | ||
* | ||
* Usage | ||
* ----- | ||
* Usage is exactly the same as publishing an asset with CAssetManager, i.e. | ||
* | ||
* $publishedAsset = Yii::app()->getAssetMananger()->publish(Yii::getPathOfAlias('allias.to.asset.directory'). DIRECTORY_SEPARATOR . 'asset.sass'); | ||
* | ||
* The only difference is that parsing of files will take place during the | ||
* publish. Files that do not require parsing are handled exactly as before. | ||
* | ||
*/ | ||
class AssetManager extends CAssetManager { | ||
/** | ||
* @var array asset parsers | ||
*/ | ||
public $parsers; | ||
/** | ||
* @var boolean if true the asset will always be published | ||
*/ | ||
public $force = false; | ||
/** | ||
* @var string base web accessible path for storing private files | ||
*/ | ||
private $_basePath; | ||
/** | ||
* @var string base URL for accessing the publishing directory. | ||
*/ | ||
private $_baseUrl; | ||
/** | ||
* @var array published assets | ||
*/ | ||
private $_published=array(); | ||
|
||
|
||
public function publish($path,$hashByName=false,$level=-1,$forceCopy=false) | ||
{ | ||
$forceCopy = false; | ||
|
||
if($forceCopy===null) | ||
$forceCopy=$this->forceCopy; | ||
if(isset($this->_published[$path])) | ||
return $this->_published[$path]; | ||
else if(($src=realpath($path))!==false) | ||
{ | ||
if(is_file($src)) | ||
{ | ||
$dir=$this->hash($hashByName ? basename($src) : dirname($src)); | ||
$fileName=basename($src); | ||
//get extension for checking of exist format parsers | ||
$extension=pathinfo($fileName, PATHINFO_EXTENSION); | ||
$dstDir=$this->getBasePath().DIRECTORY_SEPARATOR.$dir; | ||
|
||
if (array_key_exists($extension, $this->parsers)) | ||
{ | ||
$fileName=basename($src, $extension).$this->parsers[$extension]['output']; | ||
} | ||
$dstFile=$dstDir.DIRECTORY_SEPARATOR.$fileName; | ||
|
||
if($this->force || @filemtime($dstFile)<@filemtime($src)) | ||
{ | ||
if(!is_dir($dstDir)) | ||
{ | ||
mkdir($dstDir); | ||
@chmod($dstDir,0777); | ||
} | ||
|
||
//if exist parser for this format than - parse it! | ||
if (array_key_exists($extension, $this->parsers)) | ||
{ | ||
$parserClass = Yii::import($this->parsers[$extension]['class']); | ||
$parser = new $parserClass($this->parsers[$extension]['options']); | ||
file_put_contents($dstFile, $parser->parse($src)); | ||
} | ||
else | ||
{ | ||
copy($src,$dstFile); | ||
} | ||
@chmod($dstFile, $this->newFileMode); | ||
} | ||
|
||
return $this->_published[$path]=$this->getBaseUrl()."/$dir/$fileName"; | ||
} | ||
else if(is_dir($src)) | ||
{ | ||
$dir=$this->hash($hashByName ? basename($src) : $src.filemtime($src)); | ||
$dstDir=$this->getBasePath().DIRECTORY_SEPARATOR.$dir; | ||
|
||
if($this->linkAssets) | ||
{ | ||
if(!is_dir($dstDir)) | ||
symlink($src,$dstDir); | ||
} | ||
else if(!is_dir($dstDir) || $forceCopy) | ||
{ | ||
CFileHelper::copyDirectory($src,$dstDir,array( | ||
'exclude'=>$this->excludeFiles, | ||
'level'=>$level, | ||
'newDirMode'=>$this->newDirMode, | ||
'newFileMode'=>$this->newFileMode, | ||
)); | ||
} | ||
|
||
return $this->_published[$path]=$this->getBaseUrl().'/'.$dir; | ||
} | ||
} | ||
throw new CException(Yii::t('yii','The asset "{asset}" to be published does not exist.', | ||
array('{asset}'=>$path))); | ||
} | ||
|
||
} |
Oops, something went wrong.