Skip to content

Commit

Permalink
Prepare for version 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yidas committed Oct 9, 2018
1 parent bbf9a03 commit 43fcf81
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ You could switch Asset to use CDN distribution by configuring `config` file:
'assetManager' => [
'bundles' => [
'yidas\yii\fontawesome\FontawesomeAsset' => [
'cdnVersion' => '4.7.0',
'cdn' => true,
// 'cdnVersion' => '4.7.0',
],
],
],
Expand All @@ -99,8 +100,8 @@ You could also specify CDN source you like:
'assetManager' => [
'bundles' => [
'yidas\yii\fontawesome\FontawesomeAsset' => [
'cdnVersion' => true,
'cdnUrl' => '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css',
'cdn' => true,
'cdnCSS' => ['//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'],
],
],
],
Expand Down
26 changes: 15 additions & 11 deletions src/FontawesomeAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,34 @@ class FontawesomeAsset extends \yii\web\AssetBundle
];

/**
* @var string|bool Enable by specifying a CDN version, eg. `'4.7.0'` or set `false` to disable CDN mode
* @var string CDN version for CDN mode, eg. `'4.7.0'`
*/
public $cdnVersion = false;
public $cdnVersion = '4.7.0';

/**
* @var string Sprintf format or fixed URL of Font-Awesome CDN URL, enabled while $cdnVersion is true or not empty
* @var bool Enable or disable CDN mode
*/
public $cdnUrl = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/%s/css/font-awesome.min.css';
public $cdn = false;

/**
* @var array Sprintf format or fixed URL of Font-Awesome CDN URL
*/
public $cdnCSS = ['https://cdnjs.cloudflare.com/ajax/libs/font-awesome/%s/css/font-awesome.min.css'];

/**
* Source handler
*/
public function init()
{
// CDN mode
if ($this->cdnVersion) {

if ($this->cdn) {
// Unset sourcePath
$this->sourcePath = NULL;

// Rewrite css
$this->css = [
sprintf($this->cdnUrl, $this->cdnVersion)
];
// Rewrite CSS
$this->css = [];
foreach ($this->cdnCSS as $key => $url) {
$this->css[] = sprintf($url, $this->cdnVersion);
}
}

parent::init();
Expand Down

0 comments on commit 43fcf81

Please sign in to comment.