Skip to content

Commit 89ec8d0

Browse files
committed
Add DataTables
1 parent 06f4cc8 commit 89ec8d0

7 files changed

Lines changed: 119 additions & 1 deletion

File tree

README.md

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

33+
<<<<<<< HEAD
34+
=======
35+
### Bootstrap and Versioning
36+
37+
This dependency stack includes Bootstrap support for both versions 4 and 5. By default
38+
Composer will select the highest available version but it is a good idea to lock to one by
39+
requiring `twbs/bootstrap` with an explicit version:
40+
* Version 4: `composer require twbs/bootstrap:^4.0`
41+
* Version 5: `composer require twbs/bootstrap:^5.0`
42+
43+
AdminLTE and other Bootstrap-specific libraries will adjust accordingly.
44+
3345
## Included Solutions
3446

3547
### Asset Libraries
3648

3749
* [Bootstrap](https://getbootstrap.com) - Mobile-first front-end CSS framework directed at responsive web development
50+
* [DataTables](https://datatables.net) - To enhance the accessibility of data in HTML tables
3851
* [FontAwesome](https://fontawesome.com) - Popular icon set and toolkit for vector icons and social logos
3952
* [jQuery](https://jquery.com) - A fast, small, and feature-rich JavaScript library
4053

@@ -45,6 +58,9 @@ php spark publish
4558
* [Tatter\Menus](https://packagist.org/packages/tatter/menus)
4659
* [Tatter\Themes](https://packagist.org/packages/tatter/themes)
4760

61+
> *Note: jQuery is included because some other libraries depend on it; should those libraries
62+
> remove it as a dependency or be removed themselve then jQuery will no longer be included.
63+
4864
## Configuration
4965

5066
*For full configuration details see the [Assets docs](https://github.com/tattersoftware/codeigniter4-assets).*

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
],
2424
"require": {
2525
"php": "^7.3 || ^8.0",
26+
"datatables.net/datatables.net-bs4": "dev-master",
2627
"fortawesome/font-awesome": "^5.15",
2728
"components/jquery": "^3.3",
2829
"league/commonmark": "^1.5",
@@ -51,7 +52,11 @@
5152
"repositories": [
5253
{
5354
"type": "vcs",
54-
"url": "https://github.com/codeigniter4/CodeIgniter4"
55+
"url": "https://github.com/codeigniter4/CodeIgniter4.git"
56+
},
57+
{
58+
"type": "vcs",
59+
"url": "https://github.com/DataTables/Dist-DataTables-Bootstrap4.git"
5560
},
5661
{
5762
"type": "composer",

src/Bundles/DataTablesBundle.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Tatter\Frontend\Bundles;
4+
5+
use Tatter\Frontend\FrontendBundle;
6+
7+
class DataTablesBundle extends FrontendBundle
8+
{
9+
/**
10+
* Applies any initial inputs after the constructor.
11+
*/
12+
protected function define(): void
13+
{
14+
$this
15+
->addPath('datatables/js/jquery.dataTables.min.js')
16+
->addPath('datatables/js/dataTables.bootstrap4.min.js')
17+
->addPath('datatables/css/dataTables.bootstrap4.min.css')
18+
->merge(new BootstrapBundle());
19+
}
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Tatter\Frontend\Publishers;
4+
5+
use Tatter\Frontend\FrontendPublisher;
6+
7+
class DataTablesPublisher extends FrontendPublisher
8+
{
9+
protected $source = 'vendor/datatables.net/datatables.net';
10+
protected $path = 'datatables';
11+
12+
/**
13+
* Reads files from the sources and copies them out to their destinations.
14+
* This method should be reimplemented by child classes intended for
15+
* discovery.
16+
*/
17+
public function publish(): bool
18+
{
19+
return $this
20+
->addPath('js')
21+
->addPath('types')
22+
->merge(true);
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Tatter\Frontend\Publishers;
4+
5+
use Tatter\Frontend\FrontendPublisher;
6+
7+
class DataTablesStylePublisher extends FrontendPublisher
8+
{
9+
protected $source = 'vendor/datatables.net/datatables.net-bs4';
10+
protected $path = 'datatables';
11+
12+
/**
13+
* Reads files from the sources and copies them out to their destinations.
14+
* This method should be reimplemented by child classes intended for
15+
* discovery.
16+
*/
17+
public function publish(): bool
18+
{
19+
return $this
20+
->addPath('css')
21+
->addPath('images')
22+
->addPath('js')
23+
->addPath('types')
24+
->merge(true);
25+
}
26+
}

tests/BundlesTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ public function bundleProvider()
6666
'bootstrap.bundle.min.js',
6767
],
6868
],
69+
[
70+
DataTablesBundle::class,
71+
[
72+
'bootstrap.min.css',
73+
'jquery.min.js',
74+
],
75+
[
76+
'bootstrap.bundle.min.js',
77+
'dataTables.bootstrap4.min.js',
78+
'jquery.dataTables.min.js',
79+
],
80+
],
6981
[
7082
FontAwesomeBundle::class,
7183
[

tests/PublishersTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ public function publisherProvider()
4545
'bootstrap/js/bootstrap.min.js.map',
4646
],
4747
],
48+
[
49+
DataTablesPublisher::class,
50+
[
51+
'datatables/js/jquery.dataTables.js',
52+
'datatables/types/types.d.ts',
53+
],
54+
],
55+
[
56+
DataTablesStylePublisher::class,
57+
[
58+
'datatables/css/dataTables.bootstrap4.min.css',
59+
'datatables/images/sort_asc_disabled.png',
60+
'datatables/js/dataTables.bootstrap4.js',
61+
],
62+
],
4863
[
4964
FontAwesomePublisher::class,
5065
[

0 commit comments

Comments
 (0)