Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
michaljurecko committed Jan 20, 2017
0 parents commit c6041bc
Show file tree
Hide file tree
Showing 23 changed files with 842 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/contrib export-ignore
/tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/readme.md export-ignore
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/vendor/
/tests/tmp
/composer.lock
*.actual
*.expected
11 changes: 11 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
checks:
php:
code_rating: true

filter:
excluded_paths:
- 'tests/*'

tools:
external_code_coverage:
timeout: 1000
62 changes: 62 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
language: php
php:
- 5.6
- 7.0
- 7.1

matrix:
include:
- php: 5.6
env: dependencies="--prefer-lowest --prefer-stable"
- php: 7.0
env: dependencies="--prefer-lowest --prefer-stable"
- php: 7.0
env: coverage=on coding_standard=on

script:
# Tests
- vendor/bin/tester tests -s -c tests/php-unix.ini $coverageArgs
# Nette Code Checker
- >
if [ "$coding_standard" == "on" ]; then
php temp/code-checker/src/code-checker.php --short-arrays;
fi
# Nette Codding Standards
- >
if [ "$coding_standard" == "on" ]; then
vendor/bin/phpcs --standard=vendor/zenify/coding-standard/src/ZenifyCodingStandard/ruleset.xml --encoding=utf-8 -n -p src;
fi
after_failure:
# Print *.actual content
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done

before_script:
# Remove zenify/coding-standard (it not support PHP 5.6)
- >
if [ "$coding_standard" != "on" ]; then
travis_retry composer remove zenify/coding-standard --dev --no-interaction;
fi
# Install dependencies
- travis_retry composer update --no-interaction --prefer-dist $dependencies
# Install CodeChecker
- >
if [ "$coding_standard" == "on" ]; then
travis_retry composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction;
fi
# Code coverage arguments
- if [ "$coverage" == "on" ]; then coverageArgs="-p phpdbg --coverage ./coverage.xml --coverage-src ./src"; fi

after_script:
# Report Code Coverage
- >
if [ "$coverage" == "on" ]; then
wget https://scrutinizer-ci.com/ocular.phar;
php ocular.phar code-coverage:upload --format=php-clover coverage.xml;
fi
sudo: false

cache:
directories:
- $HOME/.composer/cache
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Webrouse/n-asset-macro

[![Build Status](https://img.shields.io/travis/webrouse/n-asset-macro.svg?style=flat-square)](https://travis-ci.org/webrouse/n-asset-macro)
[![Quality Score](https://img.shields.io/scrutinizer/g/webrouse/n-asset-macro.svg?style=flat-square)](https://scrutinizer-ci.com/g/webrouse/n-asset-macro/)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/webrouse/n-asset-macro.svg?style=flat-square)](https://scrutinizer-ci.com/g/webrouse/n-asset-macro/)
[![Latest stable](https://img.shields.io/packagist/v/webrouse/n-asset-macro.svg?style=flat-square)](https://packagist.org/packages/webrouse/n-asset-macro)

Asset macro for Latte and Nette Framework
useful for assets cache busting with gulp-buster and other similar tools.

Cache busting allows the assets to have a large expiry time in the browsers cache.

If the asset is changed then is also changed the hash in url and the browser is forced to retrieve the new version, otherwise is used local cached version.


## Installation

The best way to install **webrouse/n-asset-macro** is using [Composer](http://getcomposer.org/):

```sh
$ composer require webrouse/n-asset-macro
```

Register the extension:
```yaml
# app/config/config.neon
extensions:
assetMacro: Webrouse\AssetMacro\DI\Extension
```
## Usage
Use in any template:
```latte
{* app/presenters/templates/@layout.latte *}
<script src="{asset resources/compiled/vendor.js}"></script>
<script src="{asset resources/compiled/main.js}"></script>
```

Asset macro prepend path with ```$basePath``` and append version for cache busting
(eg. ```?v=32ecae4b82```).

### Asset version

Asset processors (such as gulp, bower, ...) can be usually set to generate JSON file
with assets versions based on their actual content.

Asset macro searches for the versions on several paths:
* asset path with appended `.json` extension (eg. `vendor.js.json`)
* `busters.json`, `versions.json` or `rev-manifest.json`
in asset directory or in any parent directory up to `%wwwDir%`

Specific path may be set in the configuration:
```yaml
# app/config/config.neon
assetMacro:
versions: %tempDir%/assets.json
```
Or you can set the array of versions:
```yaml
# app/config/config.neon
assetMacro:
versions:
'resources/compiled/vendor.js': 16016edc74d
'main.js': 4b82916016
```
If the file with versions can not be found an exception is thrown.
If the file exists, but it hasn't record for the asset the result path is `...?v=unknown`.


31 changes: 31 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "webrouse/n-asset-macro",
"license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"],
"description": "Asset macro for Latte and Nette Framework useful for assets cache busting (with gulp-buster, etc.)",
"type": "library",
"authors": [
{
"name": "Michal Jurečko",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.6",
"latte/latte": "^2.4",
"nette/di": "^2.3",
"nette/utils": "^2.3"
},
"require-dev": {
"nette/tester": "^2.0",
"nette/bootstrap": "^2.3",
"nette/application": "^2.3",
"nette/http": "^2.3",
"zenify/coding-standard": "^4.2"
},
"autoload": {
"psr-0": {
"Webrouse": "src"
}
},
"minimum-stability": "dev"
}
52 changes: 52 additions & 0 deletions contrib/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh

PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`

# Determine if a file list is passed
if [ "$#" -eq 1 ]
then
oIFS=$IFS
IFS='
'
SFILES="$1"
IFS=$oIFS
fi
SFILES=${SFILES:-$STAGED_FILES_CMD}

if [ "$FILES" != "" ]
then
echo "\n\nChecking PHP Lint..."
for FILE in $SFILES
do
php -l -d display_errors=0 $PROJECT/$FILE
if [ $? != 0 ]
then
echo "Fix the error before commit."
exit 1
fi
FILES="$FILES $PROJECT/$FILE"
done
fi

if [ "$FILES" != "" ]
then
echo "\n\nRunning Code Sniffer..."
vendor/bin/phpcs --standard=vendor/zenify/coding-standard/src/ZenifyCodingStandard/ruleset.xml --encoding=utf-8 --colors -n -p $FILES
if [ $? != 0 ]
then
echo "Fix the error before commit."
exit 1
fi
fi


echo "\n\nRunning tests..."
vendor/bin/tester tests -s -c tests/php-unix.ini
if [ $? != 0 ]
then
echo "Fix the error before commit."
exit 1
fi

exit $?
4 changes: 4 additions & 0 deletions contrib/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

cp contrib/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
Loading

0 comments on commit c6041bc

Please sign in to comment.