-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
844 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
.github export-ignore | ||
ncs.* export-ignore | ||
phpstan.neon export-ignore | ||
tests/ export-ignore | ||
|
||
*.sh eol=lf | ||
*.php* diff=php linguist-language=PHP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Coding Style | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
nette_cc: | ||
name: Nette Code Checker | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.1 | ||
coverage: none | ||
|
||
- run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress | ||
- run: php temp/code-checker/code-checker --strict-types --no-progress --ignore expected | ||
|
||
|
||
nette_cs: | ||
name: Nette Coding Standard | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.1 | ||
coverage: none | ||
|
||
- run: composer create-project nette/coding-standard temp/coding-standard ^3 --no-progress | ||
- run: php temp/coding-standard/ecs check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Static Analysis (only informative) | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
phpstan: | ||
name: PHPStan | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.1 | ||
coverage: none | ||
|
||
- run: composer install --no-progress --prefer-dist | ||
- run: composer phpstan -- --no-progress | ||
continue-on-error: true # is only informative |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php: ['8.1', '8.2', '8.3', '8.4'] | ||
|
||
fail-fast: false | ||
|
||
name: PHP ${{ matrix.php }} tests | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: none | ||
|
||
- run: composer install --no-progress --prefer-dist | ||
- run: vendor/bin/tester tests -s -C | ||
- if: failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: output | ||
path: tests/**/output | ||
|
||
|
||
lowest_dependencies: | ||
name: Lowest Dependencies | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.1 | ||
coverage: none | ||
|
||
- run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable | ||
- run: vendor/bin/tester tests -s -C | ||
- if: failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: output | ||
path: tests/**/output | ||
|
||
|
||
code_coverage: | ||
name: Code Coverage | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.3 | ||
coverage: none | ||
|
||
- run: composer install --no-progress --prefer-dist | ||
- run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src | ||
- run: wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar | ||
- env: | ||
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: php php-coveralls.phar --verbose --config tests/.coveralls.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "nette/assets", | ||
"description": "🎨 Nette Assets: elegant asset management for PHP with versioning, caching and providers for various storage backends.", | ||
"keywords": ["nette", "assets", "asset management", "versioning", "resources", "static files"], | ||
"homepage": "https://nette.org", | ||
"license": ["BSD-3-Clause", "GPL-2.0-only", "GPL-3.0-only"], | ||
"authors": [ | ||
{ | ||
"name": "David Grudl", | ||
"homepage": "https://davidgrudl.com" | ||
}, | ||
{ | ||
"name": "Nette Community", | ||
"homepage": "https://nette.org/contributors" | ||
} | ||
], | ||
"require": { | ||
"php": "8.1 - 8.4", | ||
"nette/utils": "^4.0" | ||
}, | ||
"suggest": { | ||
"latte/latte": "Allows using Assets in templates" | ||
}, | ||
"require-dev": { | ||
"nette/tester": "^2.5", | ||
"nette/di": "^3.2", | ||
"latte/latte": "^3.0.18", | ||
"tracy/tracy": "^2.9", | ||
"phpstan/phpstan-nette": "^1.0" | ||
}, | ||
"autoload": { | ||
"classmap": ["src/"] | ||
}, | ||
"minimum-stability": "dev", | ||
"scripts": { | ||
"phpstan": "phpstan analyse", | ||
"tester": "tester tests -s" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
Licenses | ||
======== | ||
|
||
Good news! You may use Nette Framework under the terms of either | ||
the New BSD License or the GNU General Public License (GPL) version 2 or 3. | ||
|
||
The BSD License is recommended for most projects. It is easy to understand and it | ||
places almost no restrictions on what you can do with the framework. If the GPL | ||
fits better to your project, you can use the framework under this license. | ||
|
||
You don't have to notify anyone which license you are using. You can freely | ||
use Nette Framework in commercial projects as long as the copyright header | ||
remains intact. | ||
|
||
Please be advised that the name "Nette Framework" is a protected trademark and its | ||
usage has some limitations. So please do not use word "Nette" in the name of your | ||
project or top-level domain, and choose a name that stands on its own merits. | ||
If your stuff is good, it will not take long to establish a reputation for yourselves. | ||
|
||
|
||
New BSD License | ||
--------------- | ||
|
||
Copyright (c) 2004, 2014 David Grudl (https://davidgrudl.com) | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of "Nette Framework" nor the names of its contributors | ||
may be used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
|
||
This software is provided by the copyright holders and contributors "as is" and | ||
any express or implied warranties, including, but not limited to, the implied | ||
warranties of merchantability and fitness for a particular purpose are | ||
disclaimed. In no event shall the copyright owner or contributors be liable for | ||
any direct, indirect, incidental, special, exemplary, or consequential damages | ||
(including, but not limited to, procurement of substitute goods or services; | ||
loss of use, data, or profits; or business interruption) however caused and on | ||
any theory of liability, whether in contract, strict liability, or tort | ||
(including negligence or otherwise) arising in any way out of the use of this | ||
software, even if advised of the possibility of such damage. | ||
|
||
|
||
GNU General Public License | ||
-------------------------- | ||
|
||
GPL licenses are very very long, so instead of including them here we offer | ||
you URLs with full text: | ||
|
||
- [GPL version 2](http://www.gnu.org/licenses/gpl-2.0.html) | ||
- [GPL version 3](http://www.gnu.org/licenses/gpl-3.0.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
parameters: | ||
level: 5 | ||
|
||
paths: | ||
- src | ||
|
||
includes: | ||
- vendor/phpstan/phpstan-nette/extension.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
Nette Assets | ||
============ | ||
|
||
[![Downloads this Month](https://img.shields.io/packagist/dm/nette/assets.svg)](https://packagist.org/packages/nette/assets) | ||
[![Tests](https://github.com/nette/assets/workflows/Tests/badge.svg?branch=master)](https://github.com/nette/assets/actions) | ||
[![Latest Stable Version](https://poser.pugx.org/nette/assets/v/stable)](https://github.com/nette/assets/releases) | ||
[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/nette/assets/blob/master/license.md) | ||
|
||
<!----> | ||
|
||
Introduction | ||
------------ | ||
|
||
Nette Assets is a powerful asset management library for PHP that helps you: | ||
|
||
✅ organize and serve your static assets (images, CSS, JavaScript, audio, etc.)<br> | ||
✅ handle asset versioning automatically<br> | ||
✅ get image dimensions without hassle<br> | ||
✅ verify asset existence in development mode<br> | ||
✅ support multiple storage backends | ||
|
||
The library provides a clean and intuitive API to manage static assets in your web applications with focus on developer experience and performance. | ||
|
||
<!----> | ||
|
||
Installation and Requirements | ||
----------------------------- | ||
|
||
The recommended way to install is via Composer: | ||
|
||
```shell | ||
composer require nette/assets | ||
``` | ||
|
||
Nette Assets requires PHP 8.1 or higher. | ||
|
||
<!----> | ||
|
||
Usage | ||
----- | ||
|
||
First, configure your assets in your application's configuration file: | ||
|
||
```neon | ||
assets: | ||
mapping: | ||
default: assets # maps 'default:' prefix to /assets directory | ||
audio: media/audio # maps 'audio:' prefix to /media/audio directory | ||
``` | ||
|
||
Then use assets in your Latte templates: | ||
|
||
```latte | ||
<script src={asset('app.js')} defer></script> | ||
``` | ||
|
||
You can also use provider-specific prefixes: | ||
|
||
```latte | ||
<audio src={asset('audio:podcast.mp3')} controls></audio> | ||
``` | ||
|
||
<!----> | ||
|
||
Asset Versioning | ||
---------------- | ||
|
||
The library automatically appends version query string to asset URLs based on file modification time: | ||
|
||
```latte | ||
{asset('app.js')} | ||
``` | ||
|
||
generates for example: | ||
|
||
```html | ||
/assets/app.js?v=1699944800 | ||
``` | ||
|
||
This ensures proper cache invalidation when assets change. | ||
|
||
<!----> | ||
|
||
Image Dimensions | ||
---------------- | ||
|
||
Get image dimensions easily in templates: | ||
|
||
```latte | ||
<img src={asset('logo.png')} width={assetWidth('logo.png')} height={assetHeight('logo.png')}> | ||
``` | ||
|
||
<!----> | ||
|
||
Multiple Storage Backends | ||
------------------------- | ||
|
||
The library supports multiple storage providers, which can be configured independently: | ||
|
||
```neon | ||
assets: | ||
mapping: | ||
product: App\UI\Accessory\ProductProvider(https://img.example.com, %rootDir%/www.img) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Nette\Assets; | ||
|
||
|
||
/** | ||
* Interface representing a static asset like image, script, stylesheet etc. | ||
* Provides basic properties and operations for working with the asset. | ||
*/ | ||
interface Asset | ||
{ | ||
/** | ||
* Returns the public URL of the asset. | ||
*/ | ||
public function getUrl(): string; | ||
|
||
/** | ||
* Returns the public URL of the asset. | ||
*/ | ||
public function __toString(): string; | ||
|
||
/** | ||
* Checks if the asset file exists in the filesystem. | ||
*/ | ||
public function exists(): bool; | ||
} |
Oops, something went wrong.