Skip to content

Commit 022314a

Browse files
authored
Merge pull request #10 from tattersoftware/jquery
jQuery
2 parents de6635b + 61fb8b7 commit 022314a

8 files changed

Lines changed: 176 additions & 103 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: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
use CodeIgniter\Publisher\Publisher;
4+
use Tatter\Frontend\Bundles\FontAwesomeBundle;
5+
use Tatter\Frontend\Bundles\JQueryBundle;
6+
use Tatter\Frontend\FrontendBundle;
7+
use Tests\Support\TestCase;
8+
9+
/**
10+
* @internal
11+
*/
12+
final class BundlesTest extends TestCase
13+
{
14+
private $didPublish = false;
15+
16+
/**
17+
* Publishes all files once so they are
18+
* available for bundles.
19+
*/
20+
protected function setUp(): void
21+
{
22+
parent::setUp();
23+
24+
// Make sure everything is published
25+
if (! $this->didPublish) {
26+
foreach (Publisher::discover() as $publisher) {
27+
$publisher->publish();
28+
}
29+
30+
$this->didPublish = true;
31+
}
32+
}
33+
34+
/**
35+
* @dataProvider bundleProvider
36+
*
37+
* @param class-string<FrontendBundle> $class
38+
* @param string[] $expectedHeadFiles
39+
* @param string[] $expectedBodyFiles
40+
*/
41+
public function testBundlesFiles(string $class, array $expectedHeadFiles, array $expectedBodyFiles): void
42+
{
43+
$bundle = new $class();
44+
$head = $bundle->head();
45+
$body = $bundle->body();
46+
47+
foreach ($expectedHeadFiles as $file) {
48+
$this->assertStringContainsString($file, $head);
49+
}
50+
51+
foreach ($expectedBodyFiles as $file) {
52+
$this->assertStringContainsString($file, $body);
53+
}
54+
}
55+
56+
public function bundleProvider()
57+
{
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+
];
74+
}
75+
}

tests/FontAwesomeTest.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/PublishersTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
use Tatter\Frontend\FrontendPublisher;
4+
use Tatter\Frontend\Publishers\FontAwesomePublisher;
5+
use Tatter\Frontend\Publishers\JQueryPublisher;
6+
use Tests\Support\TestCase;
7+
8+
/**
9+
* @internal
10+
*/
11+
final class PublishersTest extends TestCase
12+
{
13+
/**
14+
* @dataProvider publisherProvider
15+
*
16+
* @param class-string<FrontendPublisher> $class
17+
* @param string[] $expected
18+
*/
19+
public function testPublishesFiles(string $class, array $expected): void
20+
{
21+
$publisher = new $class();
22+
$result = $publisher->publish();
23+
24+
// Verify that publication succeeded
25+
$this->assertTrue($result);
26+
$this->assertSame([], $publisher->getErrors());
27+
$this->assertNotSame([], $publisher->getPublished());
28+
29+
// Check for each of the expected files
30+
foreach ($expected as $path) {
31+
$file = $this->config->directory . $this->config->vendor . $path;
32+
$this->assertFileExists($file);
33+
}
34+
}
35+
36+
public function publisherProvider()
37+
{
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+
];
55+
}
56+
}

tests/_support/TestCase.php

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
namespace Tests\Support;
44

5-
use CodeIgniter\Publisher\Publisher;
65
use CodeIgniter\Test\CIUnitTestCase;
76
use org\bovigo\vfs\vfsStream;
87
use org\bovigo\vfs\vfsStreamDirectory;
98
use Tatter\Assets\Asset;
109
use Tatter\Assets\Config\Assets as AssetsConfig;
11-
use Tatter\Frontend\FrontendBundle;
12-
use Tatter\Frontend\FrontendPublisher;
1310

1411
abstract class TestCase extends CIUnitTestCase
1512
{
@@ -55,50 +52,4 @@ protected function tearDown(): void
5552
$this->root = null; // @phpstan-ignore-line
5653
$this->resetServices();
5754
}
58-
59-
/**
60-
* @param class-string<FrontendPublisher> $class
61-
* @param string[] $expected
62-
*/
63-
public function assertPublishesFiles(string $class, array $expected): void
64-
{
65-
$publisher = new $class();
66-
$result = $publisher->publish();
67-
68-
// Verify that publication succeeded
69-
$this->assertTrue($result);
70-
$this->assertSame([], $publisher->getErrors());
71-
$this->assertNotSame([], $publisher->getPublished());
72-
73-
// Check for each of the expected files
74-
foreach ($expected as $path) {
75-
$file = $this->config->directory . $this->config->vendor . $path;
76-
$this->assertFileExists($file);
77-
}
78-
}
79-
80-
/**
81-
* @param class-string<FrontendBundle> $class
82-
* @param string[] $expectedHeadFiles
83-
* @param string[] $expectedBodyFiles
84-
*/
85-
public function assertBundlesFiles(string $class, array $expectedHeadFiles, array $expectedBodyFiles): void
86-
{
87-
// Make sure everything is published
88-
foreach (Publisher::discover() as $publisher) {
89-
$publisher->publish();
90-
}
91-
92-
$bundle = new $class();
93-
$head = $bundle->head();
94-
$body = $bundle->body();
95-
96-
foreach ($expectedHeadFiles as $file) {
97-
$this->assertStringContainsString($file, $head);
98-
}
99-
100-
foreach ($expectedBodyFiles as $file) {
101-
$this->assertStringContainsString($file, $body);
102-
}
103-
}
10455
}

0 commit comments

Comments
 (0)