Skip to content

Commit 9b63cad

Browse files
authored
Add files via upload
1 parent c153db5 commit 9b63cad

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,68 @@
11
# codeigniter4-assets
22
Asset publishing and loading for CodeIgniter 4
3+
4+
## Quick Start
5+
6+
1. Install with Composer: `> composer require codenom/assets`
7+
2. Put CSS & JS files in: **public/assets**
8+
3. Add additional assets to config: **app/Config/Assets.php**
9+
3. Add in head tag: `<?= service('assets')->css() ?>`
10+
4. Add to footer: `<?= service('assets')->js() ?>`
11+
12+
## Features
13+
14+
Provides out-of-the-box asset loading for CSS and JavaScript files for CodeIgniter 4
15+
16+
## Installation
17+
18+
Install easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities
19+
and always be up-to-date:
20+
* `> composer require codenom/assets`
21+
22+
Or, install manually by downloading the source files and adding the directory to
23+
`app/Config/Autoload.php`.
24+
25+
## Configuration (optional)
26+
27+
The library's default behavior can be overridden or augment by its config file. Copy
28+
**examples/Assets.php** to **app/Config/Assets.php** and follow the instructions in the
29+
comments. If no config file is found the library will use its defaults.
30+
31+
## Usage
32+
33+
If installed correctly CodeIgniter 4 will detect and autoload the library, service, and
34+
config. Use the library methods `css()` and `js()` to display tags for the route-specific assets:
35+
`<?= service('assets')->css() ?>`
36+
37+
## Structure
38+
39+
The library searches the assets directory (default: **public/assets**) for files matching
40+
the current route, loading them in a cascading fashion for each route segment.
41+
42+
**Example:** https://example.com/users/view/30
43+
44+
The library will first load any root assets (`public/assets/*.css *.js`), then assets in
45+
the "users" subfolder (`public/assets/users/`), then "view" subfolder, then "12" subfolder.
46+
Any missing or invalid folders are ignored.
47+
48+
Additional assets may be specified from the config variable `$routes` - this is particularly
49+
helpful for including pre-bundled libraries. `$routes` maps each route to an asset file or
50+
a directory of assets to load for that route.
51+
52+
**Example:**
53+
54+
```
55+
public $routes = [
56+
'' => [
57+
'bootstrap/dist/css/bootstrap.min.css',
58+
'bootstrap/dist/js/bootstrap.bundle.min.js'
59+
],
60+
'files/upload' => [
61+
'vendor/dropzone'
62+
]
63+
];
64+
```
65+
66+
This tells the library to load the Bootstrap assets for every route (`''`) without having
67+
to move it from its pre-bundled subdirectory. It also will load any assets in the `dropzone`
68+
directory for the specified route.

composer.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"name": "codenom/assets",
3+
"description": "Asset publishing and loading for CodeIgniter 4",
4+
"keywords": [
5+
"codeigniter",
6+
"codeigniter4",
7+
"assets",
8+
"loader",
9+
"css",
10+
"javascript"
11+
],
12+
"homepage": "https://github.com/codenomdev/codeigniter4-assets",
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "Codenom Dev",
17+
"email": "dev@codenom.com",
18+
"homepage": "https://codenom.com",
19+
"role": "Developer"
20+
}
21+
],
22+
"repositories": [
23+
{
24+
"type": "vcs",
25+
"url": "https://github.com/codeigniter4/CodeIgniter4"
26+
}
27+
],
28+
"minimum-stability": "dev",
29+
"prefer-stable": true,
30+
"require": {
31+
"php": ">=7.2"
32+
},
33+
"require-dev": {
34+
"codeigniter4/codeigniter4": "dev-develop",
35+
"mikey179/vfsstream": "1.6.*",
36+
"phpunit/phpunit": "^8.5"
37+
},
38+
"autoload": {
39+
"psr-4": {
40+
"Tatter\\Assets\\": "src"
41+
}
42+
},
43+
"autoload-dev": {
44+
"psr-4": {
45+
"Tests\\Support\\": "tests/support"
46+
}
47+
},
48+
"scripts": {
49+
"test": "phpunit",
50+
"post-update-cmd": [
51+
"composer dump-autoload"
52+
]
53+
}
54+
}

phpunit.xml.dist

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
3+
backupGlobals="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
stopOnError="false"
9+
stopOnFailure="false"
10+
stopOnIncomplete="false"
11+
stopOnSkipped="false">
12+
<testsuites>
13+
<testsuite name="app">
14+
<directory>./tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
18+
<filter>
19+
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
20+
<directory suffix=".php">./src</directory>
21+
<exclude>
22+
<directory suffix=".php">./src/Views</directory>
23+
<file>./src/Config/Routes.php</file>
24+
</exclude>
25+
</whitelist>
26+
</filter>
27+
28+
<logging>
29+
<log type="coverage-html" target="build/logs/html"/>
30+
<log type="coverage-clover" target="build/logs/clover.xml"/>
31+
<log type="coverage-php" target="build/logs/coverage.serialized"/>
32+
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
33+
<log type="testdox-html" target="build/logs/testdox.html"/>
34+
<log type="testdox-text" target="build/logs/testdox.txt"/>
35+
<log type="junit" target="build/logs/logfile.xml"/>
36+
</logging>
37+
38+
<php>
39+
<server name="app.baseURL" value="http://example.com"/>
40+
41+
<!-- Directory containing phpunit.xml -->
42+
<const name="HOMEPATH" value="./"/>
43+
44+
<!-- Directory containing the Paths config file -->
45+
<const name="CONFIGPATH" value="./vendor/codeigniter4/codeigniter4/app/Config/"/>
46+
47+
<!-- Directory containing the front controller (index.php) -->
48+
<const name="PUBLICPATH" value="./vendor/codeigniter4/codeigniter4/public/"/>
49+
50+
<!-- https://getcomposer.org/xdebug -->
51+
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>
52+
53+
<!-- Database configuration -->
54+
<!-- <env name="database.tests.hostname" value="localhost"/> -->
55+
<!-- <env name="database.tests.database" value="tests"/> -->
56+
<!-- <env name="database.tests.username" value="tests_user"/> -->
57+
<!-- <env name="database.tests.password" value=""/> -->
58+
<!-- <env name="database.tests.DBDriver" value="MySQLi"/> -->
59+
<!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
60+
<env name="database.tests.database" value=":memory:"/>
61+
<env name="database.tests.DBDriver" value="SQLite3"/>
62+
</php>
63+
</phpunit>

0 commit comments

Comments
 (0)