Commit 3905c419 by Qiang Xue

Merge pull request #5084 from yiisoft/asset-improvements

Asset improvements
parents d49957fe 4f0d10c6
...@@ -9,7 +9,7 @@ To add a new extension named `xyz` (must be in lower case), take the following s ...@@ -9,7 +9,7 @@ To add a new extension named `xyz` (must be in lower case), take the following s
* `CHANGELOG.md` * `CHANGELOG.md`
* `LICENSE.md` * `LICENSE.md`
3. ask Qiang to create a subsplit for `xyz` and a composer package named `yii2-xyz`; 3. ask Qiang to create a subsplit for `xyz` and a composer package named `yii2-xyz`;
4. modify `/composer.json` and add `xyz` to the `replace` section; 4. modify `/composer.json` and add `yiisoft/yii2-xyz` to the `replace` section;
5. If an extension contains js/css files or depends on external bower packages: 5. If an extension contains js/css files or depends on external bower packages:
* create `bower.json` * create `bower.json`
* ask Qiang to register a bower package with the name `yii2-xyz` * ask Qiang to register a bower package with the name `yii2-xyz`
...@@ -17,8 +17,8 @@ use yii\web\AssetBundle; ...@@ -17,8 +17,8 @@ use yii\web\AssetBundle;
*/ */
class BootstrapAsset extends AssetBundle class BootstrapAsset extends AssetBundle
{ {
public $sourcePath = '@bower/bootstrap'; public $sourcePath = '@bower/bootstrap/dist';
public $css = [ public $css = [
'dist/css/bootstrap.css', 'css/bootstrap.css',
]; ];
} }
...@@ -17,9 +17,9 @@ use yii\web\AssetBundle; ...@@ -17,9 +17,9 @@ use yii\web\AssetBundle;
*/ */
class BootstrapPluginAsset extends AssetBundle class BootstrapPluginAsset extends AssetBundle
{ {
public $sourcePath = '@bower/bootstrap'; public $sourcePath = '@bower/bootstrap/dist';
public $js = [ public $js = [
'dist/js/bootstrap.js', 'js/bootstrap.js',
]; ];
public $depends = [ public $depends = [
'yii\web\JqueryAsset', 'yii\web\JqueryAsset',
......
...@@ -17,9 +17,9 @@ use yii\web\AssetBundle; ...@@ -17,9 +17,9 @@ use yii\web\AssetBundle;
*/ */
class BootstrapThemeAsset extends AssetBundle class BootstrapThemeAsset extends AssetBundle
{ {
public $sourcePath = '@bower/bootstrap'; public $sourcePath = '@bower/bootstrap/dist';
public $css = [ public $css = [
'dist/css/bootstrap-theme.css', 'css/bootstrap-theme.css',
]; ];
public $depends = [ public $depends = [
'yii\bootstrap\BootstrapAsset', 'yii\bootstrap\BootstrapAsset',
......
...@@ -16,9 +16,9 @@ use yii\web\AssetBundle; ...@@ -16,9 +16,9 @@ use yii\web\AssetBundle;
*/ */
class TypeAheadAsset extends AssetBundle class TypeAheadAsset extends AssetBundle
{ {
public $sourcePath = '@bower/typeahead.js'; public $sourcePath = '@bower/typeahead.js/dist';
public $js = [ public $js = [
'dist/typeahead.bundle.js', 'typeahead.bundle.js',
]; ];
public $depends = [ public $depends = [
'yii\bootstrap\BootstrapAsset', 'yii\bootstrap\BootstrapAsset',
......
...@@ -268,9 +268,9 @@ class AssetManager extends Component ...@@ -268,9 +268,9 @@ class AssetManager extends Component
$asset = $bundle->sourcePath . '/' . $asset; $asset = $bundle->sourcePath . '/' . $asset;
} }
$n = strlen($asset); $n = mb_strlen($asset);
foreach ($this->assetMap as $from => $to) { foreach ($this->assetMap as $from => $to) {
$n2 = strlen($from); $n2 = mb_strlen($from);
if ($n2 <= $n && substr_compare($asset, $from, $n - $n2, $n2) === 0) { if ($n2 <= $n && substr_compare($asset, $from, $n - $n2, $n2) === 0) {
return $to; return $to;
} }
......
...@@ -19,9 +19,9 @@ use yii\web\AssetBundle; ...@@ -19,9 +19,9 @@ use yii\web\AssetBundle;
*/ */
class MaskedInputAsset extends AssetBundle class MaskedInputAsset extends AssetBundle
{ {
public $sourcePath = '@bower/jquery.inputmask'; public $sourcePath = '@bower/jquery.inputmask/dist';
public $js = [ public $js = [
'dist/jquery.inputmask.bundle.js' 'jquery.inputmask.bundle.js'
]; ];
public $depends = [ public $depends = [
'yii\web\YiiAsset' 'yii\web\YiiAsset'
......
...@@ -56,7 +56,7 @@ class ViewRendererTest extends TestCase ...@@ -56,7 +56,7 @@ class ViewRendererTest extends TestCase
$view = $this->mockView(); $view = $this->mockView();
$content = $view->renderFile('@yiiunit/extensions/smarty/views/layout.tpl'); $content = $view->renderFile('@yiiunit/extensions/smarty/views/layout.tpl');
$this->assertEquals(1, preg_match('#<script src="/assets/[0-9a-z]+/dist/jquery\\.js"></script>\s*</body>#', $content), 'Content does not contain the jquery js:' . $content); $this->assertEquals(1, preg_match('#<script src="/assets/[0-9a-z]+/jquery\\.js"></script>\s*</body>#', $content), 'Content does not contain the jquery js:' . $content);
} }
......
...@@ -39,7 +39,7 @@ class ViewRendererTest extends DatabaseTestCase ...@@ -39,7 +39,7 @@ class ViewRendererTest extends DatabaseTestCase
$view = $this->mockView(); $view = $this->mockView();
$content = $view->renderFile('@yiiunit/extensions/twig/views/layout.twig'); $content = $view->renderFile('@yiiunit/extensions/twig/views/layout.twig');
$this->assertEquals(1, preg_match('#<script src="/assets/[0-9a-z]+/dist/jquery\\.js"></script>\s*</body>#', $content), 'Content does not contain the jquery js:' . $content); $this->assertEquals(1, preg_match('#<script src="/assets/[0-9a-z]+/jquery\\.js"></script>\s*</body>#', $content), 'Content does not contain the jquery js:' . $content);
} }
public function testAppGlobal() public function testAppGlobal()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment