Skip to content

Commit 61fb8b7

Browse files
committed
Add jQuery
1 parent 73d2d17 commit 61fb8b7

7 files changed

Lines changed: 97 additions & 57 deletions

File tree

README.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,12 @@ command to inject all assets into your front controller path:
3030
php spark publish
3131
```
3232

33-
### Bootstrap and Versioning
34-
35-
This dependency stack includes Bootstrap support for both versions 4 and 5. By default
36-
Composer will select the highest available version but it is a good idea to lock to one by
37-
requiring `twbs/bootstrap` with an explicit version:
38-
* Version 4: `composer require twbs/bootstrap:^4.0`
39-
* Version 5: `composer require twbs/bootstrap:^5.0`
40-
41-
AdminLTE and other Bootstrap-specific libraries will adjust accordingly. Using Bootstrap 4
42-
will also include jQuery (via [Tatter\JQuery](https://packagist.org/packages/tatter/jquery))
43-
as it is a dependency.
44-
4533
## Included Solutions
4634

4735
### Asset Libraries
4836

49-
* [AdminLTE](https://adminlte.io) (via [Tatter\AdminLTE](https://packagist.org/packages/tatter/adminlte)) - Admin Dashboard Template
50-
* [Bootstrap](https://getbootstrap.com) (via [Tatter\Bootstrap](https://packagist.org/packages/tatter/bootstrap)) - Mobile-first front-end CSS framework directed at responsive web development
51-
* [DataTables](https://datatables.net) - To enhance the accessibility of data in HTML tables
5237
* [FontAwesome](https://fontawesome.com) - Popular icon set and toolkit for vector icons and social logos
38+
* [jQuery](https://jquery.com) - A fast, small, and feature-rich JavaScript library
5339

5440
### Support Libraries
5541

@@ -89,8 +75,8 @@ want them to be applied. **app/Config/Assets.php**:
8975

9076
namespace Config;
9177

92-
use Tatter\AdminLTE\Bundles\AdminLTEBundle;
93-
use Tatter\Bootstrap\Bundles\BootstrapBundle;
78+
use Tatter\Frontend\Bundles\AdminLTEBundle;
79+
use Tatter\Frontend\Bundles\BootstrapBundle;
9480
use Tatter\Frontend\Bundles\FontAwesomeBundle;
9581

9682
class Assets extends \Tatter\Assets\Config\Assets
@@ -111,7 +97,18 @@ class Assets extends \Tatter\Assets\Config\Assets
11197
}
11298
```
11399

114-
Note that Bundles include their dependency (e.g. AdminLTE includes Bootstrap, Bootstrap 4
100+
Note that each Bundle includes its dependency (e.g. AdminLTE includes Bootstrap, Bootstrap
115101
includes jQuery), so while there is no harm in repeating assets it is also unnecessary.
116-
This does not extend to optional plugins, e.g. if we want to use FontAwesome in AdminLTE
102+
This does not extend to optional plugins, e.g. if you want to use FontAwesome in AdminLTE
117103
you will need to include both.
104+
105+
## Versioning
106+
107+
The intent is to maintain two major versions of this library for an indefinite amount of
108+
time until AdminLTE 4 is fully released and stable for production use. The core differences
109+
will be around the dependency stack for AdminLTE, Bootstrap, and jQuery.
110+
111+
| Library version | Bootstrap version | AdminLTE version | jQuery |
112+
| --------------: | -----------------: | ----------------: | :----: |
113+
| `1.x` | `4.x` | `3.x` | Yes |
114+
| `2.x` | `5.x` | `4.x` | No |

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"require": {
2525
"php": "^7.3 || ^8.0",
2626
"fortawesome/font-awesome": "^5.15",
27+
"components/jquery": "^3.3",
2728
"league/commonmark": "^1.5",
2829
"tatter/assets": "^3.0",
2930
"tatter/menus": "^1.0",

src/Bundles/JQueryBundle.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Tatter\Frontend\Bundles;
4+
5+
use Tatter\Assets\Asset;
6+
use Tatter\Frontend\FrontendBundle;
7+
8+
class JQueryBundle extends FrontendBundle
9+
{
10+
protected function define(): void
11+
{
12+
// JQuery needs to load early so we create the Asset then move it to the head tag
13+
$asset = Asset::createFromPath(Asset::config()->vendor . 'jquery/jquery.min.js');
14+
15+
$this->add(new Asset($asset, true));
16+
}
17+
}

src/Publishers/JQueryPublisher.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Tatter\Frontend\Publishers;
4+
5+
use Tatter\Frontend\FrontendPublisher;
6+
7+
class JQueryPublisher extends FrontendPublisher
8+
{
9+
protected $source = 'vendor/components/jquery';
10+
protected $path = 'jquery';
11+
}

tests/BundlesTest.php

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,44 @@
22

33
use CodeIgniter\Publisher\Publisher;
44
use Tatter\Frontend\Bundles\FontAwesomeBundle;
5+
use Tatter\Frontend\Bundles\JQueryBundle;
6+
use Tatter\Frontend\FrontendBundle;
57
use Tests\Support\TestCase;
68

79
/**
810
* @internal
911
*/
1012
final class BundlesTest extends TestCase
1113
{
12-
private $didPublish = false;
14+
private $didPublish = false;
1315

14-
/**
15-
* Publishes all files once so they are
16-
* available for bundles.
17-
*/
16+
/**
17+
* Publishes all files once so they are
18+
* available for bundles.
19+
*/
1820
protected function setUp(): void
1921
{
2022
parent::setUp();
2123

2224
// Make sure everything is published
2325
if (! $this->didPublish) {
24-
foreach (Publisher::discover() as $publisher) {
25-
$publisher->publish();
26-
}
26+
foreach (Publisher::discover() as $publisher) {
27+
$publisher->publish();
28+
}
2729

28-
$this->didPublish = true;
29-
}
30-
}
30+
$this->didPublish = true;
31+
}
32+
}
3133

3234
/**
33-
* @dataProvider bundleProvider
34-
*
35+
* @dataProvider bundleProvider
36+
*
3537
* @param class-string<FrontendBundle> $class
3638
* @param string[] $expectedHeadFiles
3739
* @param string[] $expectedBodyFiles
3840
*/
3941
public function testBundlesFiles(string $class, array $expectedHeadFiles, array $expectedBodyFiles): void
4042
{
41-
4243
$bundle = new $class();
4344
$head = $bundle->head();
4445
$body = $bundle->body();
@@ -54,14 +55,21 @@ public function testBundlesFiles(string $class, array $expectedHeadFiles, array
5455

5556
public function bundleProvider()
5657
{
57-
return [
58-
[
59-
FontAwesomeBundle::class,
60-
[
61-
'all.min.css',
62-
],
63-
[],
64-
],
65-
];
58+
return [
59+
[
60+
FontAwesomeBundle::class,
61+
[
62+
'all.min.css',
63+
],
64+
[],
65+
],
66+
[
67+
JQueryBundle::class,
68+
[
69+
'jquery.min.js', // Note that unlike most JS files this goes in <head>
70+
],
71+
[],
72+
],
73+
];
6674
}
6775
}

tests/PublishersTest.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3+
use Tatter\Frontend\FrontendPublisher;
34
use Tatter\Frontend\Publishers\FontAwesomePublisher;
5+
use Tatter\Frontend\Publishers\JQueryPublisher;
46
use Tests\Support\TestCase;
57

68
/**
@@ -9,8 +11,8 @@
911
final class PublishersTest extends TestCase
1012
{
1113
/**
12-
* @dataProvider publisherProvider
13-
*
14+
* @dataProvider publisherProvider
15+
*
1416
* @param class-string<FrontendPublisher> $class
1517
* @param string[] $expected
1618
*/
@@ -33,16 +35,22 @@ public function testPublishesFiles(string $class, array $expected): void
3335

3436
public function publisherProvider()
3537
{
36-
return [
37-
[
38-
FontAwesomePublisher::class,
39-
[
40-
'font-awesome/css/all.min.css',
41-
'font-awesome/css/svg-with-js.css',
42-
'font-awesome/webfonts/fa-brands-400.eot',
43-
'font-awesome/webfonts/fa-solid-900.woff2',
44-
],
45-
],
46-
];
38+
return [
39+
[
40+
FontAwesomePublisher::class,
41+
[
42+
'font-awesome/css/all.min.css',
43+
'font-awesome/css/svg-with-js.css',
44+
'font-awesome/webfonts/fa-brands-400.eot',
45+
'font-awesome/webfonts/fa-solid-900.woff2',
46+
],
47+
],
48+
[
49+
JQueryPublisher::class,
50+
[
51+
'jquery/jquery.min.js',
52+
],
53+
],
54+
];
4755
}
4856
}

tests/_support/TestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use org\bovigo\vfs\vfsStreamDirectory;
88
use Tatter\Assets\Asset;
99
use Tatter\Assets\Config\Assets as AssetsConfig;
10-
use Tatter\Frontend\FrontendBundle;
11-
use Tatter\Frontend\FrontendPublisher;
1210

1311
abstract class TestCase extends CIUnitTestCase
1412
{

0 commit comments

Comments
 (0)