Skip to content

Commit

Permalink
Add cdn, popperjs. (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Nov 17, 2023
1 parent 9e05ff7 commit 4fced22
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 31 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,51 @@ BootstrapAsset::register($this);

declare(strict_types=1);

use Yii2\Asset\BootstrapCdnAsset;

BootstrapCdnAsset::register($this);
```

```php
<?php

declare(strict_types=1);

use Yii2\Asset\BootstrapPluginAsset;

BootstrapPluginAsset::register($this);
```

```php
<?php

declare(strict_types=1);

use Yii2\Asset\BootstrapPluginCdnAsset;

BootstrapPluginCdnAsset::register($this);
```

```php
<?php

declare(strict_types=1);

use Yii2\Asset\PopperAsset;

PopperAsset::register($this);
```

```php
<?php

declare(strict_types=1);

use Yii2\Asset\PopperCdnAsset;

PopperCdnAsset::register($this);
```

## Testing

[Check the documentation testing](/docs/testing.md) to learn about testing.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"require": {
"php": ">=8.1",
"npm-asset/bootstrap": "^5.3",
"npm-asset/popperjs--core": "^2.11",
"oomphinc/composer-installers-extender": "^2.0",
"yiisoft/yii2": "^2.2"
},
Expand Down
3 changes: 1 addition & 2 deletions src/BootstrapAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public function init(): void
parent::init();

$assetBootstrap = YII_ENV === 'prod'
? ['bootstrap.min.css', 'bootstrap.min.css.map']
: ['bootstrap.css', 'bootstrap.css.map'];
? ['bootstrap.min.css', 'bootstrap.min.css.map'] : ['bootstrap.css', 'bootstrap.css.map'];

$this->css = $assetBootstrap;
$this->publishOptions['only'] = $assetBootstrap;
Expand Down
29 changes: 29 additions & 0 deletions src/BootstrapCdnAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Yii2\Asset;

use yii\web\AssetBundle;

/**
* Twitter Bootstrap 5 CDN CSS bundle.
*/
final class BootstrapCdnAsset extends AssetBundle
{
/**
* @inheritDoc
*/
public $css = [
'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css',
];

/**
* @inheritDoc
*/
public $cssOptions = [
'crossorigin' => 'anonymous',
'integrity' => 'sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN',
'rel' => 'stylesheet',
];
}
3 changes: 1 addition & 2 deletions src/BootstrapPluginAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public function init(): void
parent::init();

$assetBootstrapPlugin = YII_ENV === 'prod'
? ['bootstrap.bundle.min.js', 'bootstrap.bundle.min.js.map']
: ['bootstrap.bundle.js', 'bootstrap.bundle.js.map'];
? ['bootstrap.bundle.min.js', 'bootstrap.bundle.min.js.map'] : ['bootstrap.bundle.js', 'bootstrap.bundle.js.map'];

$this->js = $assetBootstrapPlugin;
$this->publishOptions['only'] = $assetBootstrapPlugin;
Expand Down
35 changes: 35 additions & 0 deletions src/BootstrapPluginCdnAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Yii2\Asset;

use yii\web\AssetBundle;

/**
* Twitter Bootstrap 5 CDN JavaScript bundle.
*/
final class BootstrapPluginCdnAsset extends AssetBundle
{
/**
* @inheritDoc
*/
public $js = [
'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js',
];

/**
* @inheritDoc
*/
public $jsOptions = [
'crossorigin' => 'anonymous',
'integrity' => 'sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL',
];

/**
* @inheritDoc
*/
public $depends = [
BootstrapCdnAsset::class,
];
}
28 changes: 28 additions & 0 deletions src/PopperAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Yii2\Asset;

use yii\web\AssetBundle;

/**
* Popper JavaScript bundle.
*/
final class PopperAsset extends AssetBundle
{
/**
* @inheritDoc
*/
public $sourcePath = '@npm/popperjs--core/dist/umd';

public function init(): void
{
parent::init();

$assetPopper = YII_ENV === 'prod' ? ['popper.min.js', 'popper.min.js.map'] : ['popper.js', 'popper.js.map'];

$this->css = $assetPopper;
$this->publishOptions['only'] = $assetPopper;
}
}
28 changes: 28 additions & 0 deletions src/PopperCdnAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Yii2\Asset;

use yii\web\AssetBundle;

/**
* Popper CDN JavaScript bundle.
*/
final class PopperCdnAsset extends AssetBundle
{
/**
* @inheritDoc
*/
public $js = [
'https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js',
];

/**
* @inheritDoc
*/
public $jsOptions = [
'crossorigin' => 'anonymous',
'integrity' => 'sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r',
];
}
Loading

0 comments on commit 4fced22

Please sign in to comment.