Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft yiisoft/view assets, and view no merge. #50

Merged
merged 32 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
435ea33
Draft view assets, and view no merge.
terabytesoftw Aug 23, 2019
56b9204
Fix directory asset tests.
terabytesoftw Aug 23, 2019
5b253f8
Remove tests csrftoken will be added when it works.
terabytesoftw Aug 23, 2019
a809506
Add AssetConverterTest, minor corrections.
terabytesoftw Aug 24, 2019
d491af5
Fix styleci.
terabytesoftw Aug 24, 2019
d3cd8bc
Fix config common.
terabytesoftw Aug 24, 2019
1107987
Fix config .travis.yml, add logger to assetmanager, assetconverter.
terabytesoftw Aug 25, 2019
e7f0923
Fix travis config.
terabytesoftw Aug 25, 2019
7af2546
Minor corrections scrutinizer.
terabytesoftw Aug 25, 2019
10eb430
Minor corrections scrutinizer.
terabytesoftw Aug 25, 2019
6ddf241
Add documentation, minor corrections.
terabytesoftw Aug 26, 2019
d1af89f
Fix phpunit.xml.dist
terabytesoftw Aug 26, 2019
5bcec3a
Add info class.
terabytesoftw Aug 26, 2019
b492a5f
Update README.md.
terabytesoftw Aug 26, 2019
fb8ad9a
Update documentation - [ci skip].
terabytesoftw Aug 26, 2019
b71f103
Suggested corrections.
terabytesoftw Aug 26, 2019
e945835
Suggested corrections.
terabytesoftw Aug 26, 2019
30ce5e8
Fix config/common, add getBasePath() in view.
terabytesoftw Aug 26, 2019
8e765a8
Update documentation, minor corrections.
terabytesoftw Aug 27, 2019
9d61199
Adjust guide file names, fix minor issues
samdark Aug 28, 2019
a3072ce
Cleanup
samdark Aug 28, 2019
4fd180d
Fix test under Windows
samdark Aug 28, 2019
f662127
Formatting cleanup
samdark Aug 28, 2019
21761e2
Fix Locale reference
samdark Aug 28, 2019
20fec5f
Cleanup
samdark Aug 28, 2019
301ade7
Cleanup, add types
samdark Aug 28, 2019
136713e
Fix incorrect function call
samdark Aug 28, 2019
35d0d50
Remove comments that are not useful
samdark Aug 28, 2019
d3ee37c
Tests cleanup
samdark Aug 28, 2019
e5b1e95
More test cleanup
samdark Aug 28, 2019
91604dd
Removed VSCode generated comment
samdark Aug 28, 2019
82ccb90
Fix Theme array type-safety
samdark Aug 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 10 additions & 76 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,109 +1,43 @@
#
# Travis Setup
#

# use ubuntu trusty for newer version of nodejs, used for JS testing
dist: trusty

# faster builds on new travis setup not using sudo
# temporary disable, see https://github.com/travis-ci/travis-ci/issues/6842
#sudo: false
sudo: required
group: edge

# build only on master branches
# commented as this prevents people from running builds on their forks:
# https://github.com/yiisoft/yii2/commit/bd87be990fa238c6d5e326d0a171f38d02dc253a
#branches:
# only:
# - master
# - 3.0


#
# Test Matrix
#

language: php

env:
global:
- DEFAULT_COMPOSER_FLAGS="--prefer-dist --no-interaction --no-progress --optimize-autoloader"
- TASK_TESTS_PHP=1
- TASK_TESTS_COVERAGE=0

# cache vendor dirs
cache:
directories:
- vendor
terabytesoftw marked this conversation as resolved.
Show resolved Hide resolved
- $HOME/.composer/cache
- $HOME/.npm

# try running against postgres 9.6
addons:
code_climate:
repo_token: 2935307212620b0e2228ab67eadd92c9f5501ddb60549d0d86007a354d56915b

matrix:
fast_finish: true
include:
- php: 7.3
env: DEFAULT_COMPOSER_FLAGS="$DEFAULT_COMPOSER_FLAGS --ignore-platform-reqs" # php-cs
- php: 7.2
env: TASK_TESTS_COVERAGE=1
- php: "7.2"
- php: "7.3"
- php: "7.4snapshot"
- php: nightly

allow_failures:
- php: nightly

install:
- |
if [[ $TASK_TESTS_COVERAGE != 1 ]]; then
# disable xdebug for performance reasons when code coverage is not needed
phpenv config-rm xdebug.ini || echo "xdebug is not installed"
terabytesoftw marked this conversation as resolved.
Show resolved Hide resolved
fi
before_install:
- phpenv config-rm xdebug.ini || echo "xdebug is not installed"

# install composer dependencies
install:
- travis_retry composer self-update
- travis_retry composer global require hirak/prestissimo
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- travis_retry composer install $DEFAULT_COMPOSER_FLAGS

before_script:
# show some versions and env information
- php --version
- composer --version
- |
if [ $TASK_TESTS_PHP == 1 ]; then
php -r "echo INTL_ICU_VERSION . \"\n\";"
php -r "echo INTL_ICU_DATA_VERSION . \"\n\";"
fi

# enable code coverage
- |
if [ $TASK_TESTS_COVERAGE == 1 ]; then
PHPUNIT_FLAGS="--coverage-clover=coverage.clover"
fi

# Disable DEPRECATE messages during PHPUnit initialization on PHP 7.2. To fix them, PHPUnit should be updated to 6.*
# For Yii2 tests, messages will be enabled by tests/bootstrap.php
- |
if [[ $TRAVIS_PHP_VERSION == 7.2 || $TRAVIS_PHP_VERSION = nightly ]]; then
echo 'Disabled DEPRECATED notifications for PHP >= 7.2';
echo 'error_reporting = E_ALL & ~E_DEPRECATED' >> /tmp/php-config.ini;
phpenv config-add /tmp/php-config.ini;
fi


script:
# PHP tests
- |
if [ $TASK_TESTS_PHP == 1 ]; then
vendor/bin/phpunit --verbose $PHPUNIT_FLAGS --exclude-group wincache,xcache
fi
- phpdbg -qrr vendor/bin/phpunit --verbose --coverage-clover=coverage.clover

after_script:
- |
if [ $TASK_TESTS_COVERAGE == 1 ]; then
travis_retry wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
fi
- travis_retry wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
24 changes: 15 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,34 @@
"minimum-stability": "dev",
"require": {
"php": "^7.2",
"psr/container": "1.0.0",
"psr/container-implementation": "1.0.0",
"psr/event-dispatcher": "1.0.0",
"psr/event-dispatcher-implementation": "1.0.0",
"psr/log": "^1.1",
"psr/event-dispatcher": "^1.0",
"yiisoft/aliases": "^3.0@dev",
"yiisoft/arrays": "^3.0@dev",
"yiisoft/html": "^3.0@dev",
"yiisoft/json": "^3.0@dev",
"yiisoft/var-dumper": "^3.0@dev",
"yiisoft/files": "^3.0@dev"
"yiisoft/files": "^3.0@dev",
"yiisoft/i18n": "^3.0@dev"
},
"require-dev": {
"hiqdev/composer-config-plugin": "^1.0@dev",
"yiisoft/di": "^3.0@dev",
"yiisoft/log": "^3.0@dev",
"phpunit/phpunit": "^8.0",
"yiisoft/cache": "^3.0@dev",
terabytesoftw marked this conversation as resolved.
Show resolved Hide resolved
"yiisoft/yii-core": "^3.0@dev",
"yiisoft/strings": "^3.0@dev",
"yiisoft/di": "^3.0@dev",
"yiisoft/event-dispatcher": "^3.0@dev",
terabytesoftw marked this conversation as resolved.
Show resolved Hide resolved
"phpunit/phpunit": "^7.3",
"friendsofphp/php-cs-fixer": "^2.2"
"yiisoft/log": "^3.0@dev"
},
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
},
"config-plugin": {
"common": "config/common.php"
"common": "config/common.php",
"tests": "config/tests.php"
}
},
"autoload": {
Expand All @@ -52,6 +57,7 @@
},
"autoload-dev": {
"psr-4": {
"Yiisoft\\Tests\\": "tests",
"Yiisoft\\View\\Tests\\": "tests/View",
"Yiisoft\\Widget\\Tests\\": "tests/Widget",
"Yiisoft\\Asset\\Tests\\": "tests/Asset"
Expand Down
40 changes: 33 additions & 7 deletions config/common.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
<?php

use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Yiisoft\Aliases\Aliases;
use Yiisoft\Asset\AssetConverter;
use Yiisoft\Asset\AssetConverterInterface;
use Yiisoft\Asset\AssetManager;
use Yiisoft\Factory\Definitions\Reference;
use Yiisoft\View\Theme;
use Yiisoft\View\View;
use Yiisoft\Log\Logger;

return [
'view' => [
'__class' => View::class,
Aliases::class => [
],

Theme::class => Reference::to('theme'),
'theme' => [
'__class' => Theme::class,
AssetConverter::class => [
'__class' => AssetConverter::class,
'__construct()' => [
Reference::to(Aliases::class),
Reference::to(LoggerInterface::class)
]
],

AssetConverterInterface::class => AssetConverter::class,

AssetManager::class => function (ContainerInterface $container) {
$assetConverterInterface = $container->get(AssetConverterInterface::class);
$aliases = $container->get(Aliases::class);
$logger = $container->get(LoggerInterface::class);
$assetManager = new AssetManager($aliases, $logger);
$assetManager->setConverter($assetConverterInterface);

return $assetManager;
},

LoggerInterface::class => [
'__class' => Logger::class,
'__construct()' => [
'targets' => [],
],
],
];
79 changes: 77 additions & 2 deletions config/tests.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,82 @@
<?php

use Psr\Container\ContainerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\EventDispatcher\ListenerProviderInterface;
use Psr\Log\LoggerInterface;
use Yiisoft\Aliases\Aliases;
use Yiisoft\Asset\AssetConverter;
use Yiisoft\Asset\AssetManager;
use Yiisoft\EventDispatcher\Dispatcher;
use Yiisoft\EventDispatcher\Provider\Provider;
use Yiisoft\Factory\Definitions\Reference;
use Yiisoft\Log\Logger;
use Yiisoft\View\Theme;
use Yiisoft\View\View;
use Yiisoft\View\WebView;

$tempDir = sys_get_temp_dir();

return [
'request' => [
'cookieValidationKey' => 'test cookieValidationKey',
Aliases::class => [
'@root' => dirname(__DIR__, 1),
'@public' => '@root/tests/public',
'@basePath' => '@public/assets',
'@baseUrl' => '/baseUrl',
'@converter' => '@public/assetconverter',
'@npm' => '@root/node_modules',
'@view' => '@public/view',
'@web' => '@baseUrl',
'@testSourcePath' => '@public/assetsources'
],

AssetConverter::class => [
'__class' => AssetConverter::class,
'__construct()' => [
Reference::to(Aliases::class),
Reference::to(LoggerInterface::class)
]
],

AssetManager::class => [
'__class' => AssetManager::class,
'__construct()' => [
Reference::to(Aliases::class),
Reference::to(LoggerInterface::class)
],
'setBasePath' => ['@basePath'],
'setBaseUrl' => ['@baseUrl'],
],

ListenerProviderInterface::class => [
'__class' => Provider::class,
],

EventDispatcherInterface::class => [
'__class' => Dispatcher::class,
'__construct()' => [
'listenerProvider' => Reference::to(ListenerProviderInterface::class)
],
],

LoggerInterface::class => [
'__class' => Logger::class,
'__construct()' => [
'targets' => [],
],
],

Theme::class => [
'__class' => Theme::class,
],

View::class => [
'__class' => View::class,
'__construct()' => [
'basePath'=> $tempDir . DIRECTORY_SEPARATOR . 'views',
'theme'=> Reference::to(Theme::class),
'eventDispatcher' => Reference::to(EventDispatcherInterface::class),
'logger' => Reference::to(LoggerInterface::class)
],
],
];
12 changes: 12 additions & 0 deletions docs/guide/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Assets
======

An asset is a file that can be referenced on a Web page. It can be a CSS file, a JavaScript file, an image or video file, etc. These files are usually placed in non-public directory that is then becomes accessible from public directory either by copying or by symlinking. This preparation step is called publishing.

It is often preferable to manage assets programmatically. For example, when you use the [Yiisoft\Boostrap4\BoostrapAsset] widget in a page, it will automatically include the required CSS and JavaScript files, instead of asking you to manually find these files and include them. And when you upgrade the widget to a new version, it will automatically use the new version of the asset files. In this tutorial, we will describe the powerful asset management capability provided in Yii.

- [Configuration: composer.json](config-composer-json.md)
- [Configuration: asset manager](config-asset-manager.md)
- [Asset bundles](asset-bundles.md)


38 changes: 38 additions & 0 deletions docs/guide/asset-bundles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Asset Bundles <span id="asset-bundles"></span>

Yii manages assets in the unit of *asset bundle*. An asset bundle is a collection of files located in a directory and a configuration class. When you register the class, asset files such as CSS, JavaScript, images etc. are automatically made accessible from public directory and are referenced in a Web page HTML.


## Defining Asset Bundles <span id="defining-asset-bundles"></span>

Asset bundles are specified as PHP classes extending from [Yiisoft\Asset\AssetBundle]. The name of a bundle is simply its corresponding fully qualified PHP class name (without the leading backslash). An asset bundle class should be autoloadable. It usually specifies where the assets are located, what CSS and JavaScript files the bundle contains, and how the bundle depends on other bundles.

The following code defines the main asset bundle used:

```php
<?php

namespace App\Assets;

use Yiisoft\Asset\AssetBundle;

class AppAsset extends AssetBundle
{
public $basePath = '@webroot';

public $baseUrl = '@web';

public $css = [
'css/site.css',
['css/print.css', 'media' => 'print'],
];

public $js = [
];

public $depends = [
\Yiisoft\Yii\JQuery\YiiAsset::class,
\Yiisoft\Bootstrap4\BootstrapAsset::class,
];
}
```
Loading