From 43fcf81ede5862fd45f764fd1992b1c243848b02 Mon Sep 17 00:00:00 2001 From: Nick Tsai Date: Tue, 9 Oct 2018 11:10:01 +0800 Subject: [PATCH] Prepare for version 4.0.0 --- README.md | 7 ++++--- src/FontawesomeAsset.php | 26 +++++++++++++++----------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 2383aae..cda7b31 100644 --- a/README.md +++ b/README.md @@ -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', ], ], ], @@ -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'], ], ], ], diff --git a/src/FontawesomeAsset.php b/src/FontawesomeAsset.php index 0bd7dad..073801a 100644 --- a/src/FontawesomeAsset.php +++ b/src/FontawesomeAsset.php @@ -21,14 +21,19 @@ 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 @@ -36,15 +41,14 @@ class FontawesomeAsset extends \yii\web\AssetBundle 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();