Commit dded40f3 authored by webchick's avatar webchick

Issue #1784774 by mcjim, Rob Loach: Added Assetic component to core.

parent c556fa32
......@@ -11,7 +11,8 @@
"symfony/routing": "2.1.*",
"symfony/yaml": "2.1.*",
"twig/twig": "1.8.*",
"doctrine/common": "2.3.*"
"doctrine/common": "2.3.*",
"kriswallsmith/assetic": "1.1.*"
},
"minimum-stability": "beta"
"minimum-stability": "alpha"
}
......@@ -25,6 +25,10 @@
"package": "symfony/http-kernel",
"version": "v2.1.0-RC2"
},
{
"package": "symfony/process",
"version": "v2.1.0-RC2"
},
{
"package": "symfony/routing",
"version": "v2.1.0-RC2"
......@@ -36,13 +40,17 @@
{
"package": "twig/twig",
"version": "v1.8.3"
},
{
"package": "kriswallsmith/assetic",
"version": "v1.1.0-alpha1"
}
],
"packages-dev": null,
"aliases": [
],
"minimum-stability": "beta",
"minimum-stability": "alpha",
"stability-flags": [
]
......
......@@ -9,6 +9,7 @@
'Twig_' => $vendorDir . '/twig/twig/lib/',
'Symfony\\Component\\Yaml' => $vendorDir . '/symfony/yaml/',
'Symfony\\Component\\Routing' => $vendorDir . '/symfony/routing/',
'Symfony\\Component\\Process' => $vendorDir . '/symfony/process/',
'Symfony\\Component\\HttpKernel' => $vendorDir . '/symfony/http-kernel/',
'Symfony\\Component\\HttpFoundation' => $vendorDir . '/symfony/http-foundation/',
'Symfony\\Component\\EventDispatcher' => $vendorDir . '/symfony/event-dispatcher/',
......@@ -16,4 +17,5 @@
'Symfony\\Component\\ClassLoader' => $vendorDir . '/symfony/class-loader/',
'SessionHandlerInterface' => $vendorDir . '/symfony/http-foundation/Symfony/Component/HttpFoundation/Resources/stubs',
'Doctrine\\Common' => $vendorDir . '/doctrine/common/lib/',
'Assetic' => $vendorDir . '/kriswallsmith/assetic/src/',
);
......@@ -3,7 +3,7 @@
"name": "twig/twig",
"version": "v1.8.3",
"version_normalized": "1.8.3.0",
"time": "2012-06-18 19:48:16",
"time": "2012-06-18 18:48:16",
"source": {
"type": "git",
"url": "git://github.com/fabpot/Twig.git",
......@@ -58,7 +58,7 @@
"version": "v2.1.0-RC2",
"version_normalized": "2.1.0.0-RC2",
"target-dir": "Symfony/Component/ClassLoader",
"time": "2012-08-27 15:51:49",
"time": "2012-08-27 14:51:49",
"source": {
"type": "git",
"url": "https://github.com/symfony/ClassLoader",
......@@ -113,7 +113,7 @@
"version": "v2.1.0-RC2",
"version_normalized": "2.1.0.0-RC2",
"target-dir": "Symfony/Component/DependencyInjection",
"time": "2012-08-28 07:54:42",
"time": "2012-08-28 06:54:42",
"source": {
"type": "git",
"url": "https://github.com/symfony/DependencyInjection",
......@@ -172,7 +172,7 @@
"name": "doctrine/common",
"version": "2.3.0-RC2",
"version_normalized": "2.3.0.0-RC2",
"time": "2012-08-29 14:06:32",
"time": "2012-08-29 13:06:32",
"source": {
"type": "git",
"url": "https://github.com/doctrine/common",
......@@ -249,7 +249,7 @@
"version": "v2.1.0-RC2",
"version_normalized": "2.1.0.0-RC2",
"target-dir": "Symfony/Component/HttpFoundation",
"time": "2012-08-22 13:48:41",
"time": "2012-08-22 12:48:41",
"source": {
"type": "git",
"url": "https://github.com/symfony/HttpFoundation",
......@@ -302,7 +302,7 @@
"version": "v2.1.0-RC2",
"version_normalized": "2.1.0.0-RC2",
"target-dir": "Symfony/Component/EventDispatcher",
"time": "2012-08-22 13:48:41",
"time": "2012-08-22 12:48:41",
"source": {
"type": "git",
"url": "https://github.com/symfony/EventDispatcher",
......@@ -361,7 +361,7 @@
"version": "v2.1.0-RC2",
"version_normalized": "2.1.0.0-RC2",
"target-dir": "Symfony/Component/HttpKernel",
"time": "2012-08-28 08:00:18",
"time": "2012-08-28 07:00:18",
"source": {
"type": "git",
"url": "https://github.com/symfony/HttpKernel",
......@@ -433,7 +433,7 @@
"version": "v2.1.0-RC2",
"version_normalized": "2.1.0.0-RC2",
"target-dir": "Symfony/Component/Routing",
"time": "2012-08-28 07:54:42",
"time": "2012-08-28 06:54:42",
"source": {
"type": "git",
"url": "https://github.com/symfony/Routing",
......@@ -496,7 +496,7 @@
"version": "v2.1.0-RC2",
"version_normalized": "2.1.0.0-RC2",
"target-dir": "Symfony/Component/Yaml",
"time": "2012-08-22 13:48:41",
"time": "2012-08-22 12:48:41",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml",
......@@ -542,5 +542,115 @@
"Symfony\\Component\\Yaml": ""
}
}
},
{
"name": "symfony/process",
"version": "v2.1.0-RC2",
"version_normalized": "2.1.0.0-RC2",
"target-dir": "Symfony/Component/Process",
"time": "2012-08-26 06:13:51",
"source": {
"type": "git",
"url": "https://github.com/symfony/Process",
"reference": "v2.1.0-RC2"
},
"dist": {
"type": "zip",
"url": "https://github.com/symfony/Process/zipball/v2.1.0-RC2",
"reference": "v2.1.0-RC2",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
}
},
"installation-source": "dist",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "http://symfony.com/contributors"
}
],
"description": "Symfony Process Component",
"homepage": "http://symfony.com",
"autoload": {
"psr-0": {
"Symfony\\Component\\Process": ""
}
}
},
{
"name": "kriswallsmith/assetic",
"version": "v1.1.0-alpha1",
"version_normalized": "1.1.0.0-alpha1",
"time": "2012-08-28 05:33:44",
"source": {
"type": "git",
"url": "http://github.com/kriswallsmith/assetic.git",
"reference": "v1.1.0-alpha1"
},
"dist": {
"type": "zip",
"url": "https://github.com/kriswallsmith/assetic/zipball/v1.1.0-alpha1",
"reference": "v1.1.0-alpha1",
"shasum": ""
},
"require": {
"php": ">=5.3.1",
"symfony/process": "2.1.*"
},
"require-dev": {
"twig/twig": ">=1.6.0,<2.0",
"leafo/lessphp": "*",
"leafo/scssphp": "*",
"ptachoire/cssembed": "*"
},
"suggest": {
"twig/twig": "Assetic provides the integration with the Twig templating engine",
"leafo/lessphp": "Assetic provides the integration with the lessphp LESS compiler",
"leafo/scssphp": "Assetic provides the integration with the scssphp SCSS compiler",
"ptachoire/cssembed": "Assetic provides the integration with phpcssembed to embed data uris"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
},
"installation-source": "dist",
"license": [
"MIT"
],
"authors": [
{
"name": "Kris Wallsmith",
"email": "kris.wallsmith@gmail.com",
"homepage": "http://kriswallsmith.net/"
}
],
"description": "Asset Management for PHP",
"homepage": "https://github.com/kriswallsmith/assetic",
"keywords": [
"assets",
"compression",
"minification"
],
"autoload": {
"psr-0": {
"Assetic": "src/"
}
}
}
]
phpunit.xml
vendor/
composer.phar
composer.lock
language: php
php:
- 5.3
- 5.4
before_script:
- wget http://getcomposer.org/composer.phar
- php composer.phar install --dev
- git clone https://github.com/kamicane/packager.git vendor/packager --quiet --depth 1
- git clone https://github.com/leafo/lessphp.git vendor/lessphp --quiet --depth 1
- git clone https://github.com/mrclay/minify.git vendor/minify --quiet --depth 1
- svn checkout http://cssmin.googlecode.com/svn/trunk/ vendor/cssmin --quiet
- wget --quiet -O javascript-packer.zip "http://joliclic.free.fr/php/javascript-packer/telechargement.php?id=2&action=telecharger" && mkdir -p vendor/packer && unzip -qq javascript-packer.zip -d vendor/packer; rm javascript-packer.zip
script: phpunit --configuration phpunit.travis.xml
1.0.4 (August 28, 2012)
-----------------------
* Fixed the Twig tag to avoid a fatal error when left unclosed
* Added the HashableInterface for non-serialiable filters
* Fixed a bug for compass on windows
1.0.3 (March 2, 2012)
---------------------
* Added "boring" option to Compass filter
* Fixed accumulation of load paths in Compass filter
* Fixed issues in CssImport and CssRewrite filters
1.0.2 (August 26, 2011)
-----------------------
* Twig 1.2 compatibility
* Fixed filtering of large LessCSS assets
* Fixed escaping of commands on Windows
* Misc fixes to Compass filter
* Removed default CssEmbed charset
1.0.1 (July 15, 2011)
---------------------
* Fixed Twig error handling
* Removed use of STDIN
* Added inheritance of environment variables
* Fixed Compass on Windows
* Improved escaping of commands
1.0.0 (July 10, 2011)
---------------------
* Initial release
1.1.0-alpha1 (August 28, 2012)
------------------------------
* Added pure php css embed filter
* Added Scssphp support
* Added support for Google Closure language option
* Added a way to set a specific ruby path for CompassFilter and SassFilter
* Ensure uniqueness of temporary files created by the compressor filter. Fixed #61
* Added Compass option for generated_images_path (for generated Images/Sprites)
* Added PackerFilter
* Add the way to contact closure compiler API using curl, if available and allow_url_fopen is off
* Added filters for JSMin and JSMinPlus
* Added the UglifyJsFilter
* Improved the error message in getModifiedTime when a file asset uses an invalid file
* added support for asset variables:
Asset variables allow you to pre-compile your assets for a finite set of known
variable values, and then to simply deliver the correct asset version at runtime.
For example, this is helpful for assets with language, or browser-specific code.
* Removed the copy-paste of the Symfony2 Process component and use the original one
* Added ability to pass variables into lessphp filter
* Added google closure stylesheets jar filter
* Added the support of `--bare` for the CoffeeScriptFilter
Copyright (c) 2010-2012 OpenSky Project Inc
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# Assetic ![project status](http://stillmaintained.com/kriswallsmith/assetic.png) #
Assetic is an asset management framework for PHP.
``` php
<?php
use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Asset\GlobAsset;
$js = new AssetCollection(array(
new GlobAsset('/path/to/js/*'),
new FileAsset('/path/to/another.js'),
));
// the code is merged when the asset is dumped
echo $js->dump();
```
Assets
------
An Assetic asset is something with filterable content that can be loaded and
dumped. An asset also includes metadata, some of which can be manipulated and
some of which is immutable.
| **Property** | **Accessor** | **Mutator** |
|--------------|-----------------|---------------|
| content | getContent | setContent |
| mtime | getLastModified | n/a |
| source root | getSourceRoot | n/a |
| source path | getSourcePath | n/a |
| target path | getTargetPath | setTargetPath |
Filters
-------
Filters can be applied to manipulate assets.
``` php
<?php
use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Asset\GlobAsset;
use Assetic\Filter\LessFilter;
use Assetic\Filter\Yui;
$css = new AssetCollection(array(
new FileAsset('/path/to/src/styles.less', array(new LessFilter())),
new GlobAsset('/path/to/css/*'),
), array(
new Yui\CssCompressorFilter('/path/to/yuicompressor.jar'),
));
// this will echo CSS compiled by LESS and compressed by YUI
echo $css->dump();
```
The filters applied to the collection will cascade to each asset leaf if you
iterate over it.
``` php
<?php
foreach ($css as $leaf) {
// each leaf is compressed by YUI
echo $leaf->dump();
}
```
The core provides the following filters in the `Assetic\Filter` namespace:
* `CoffeeScriptFilter`: compiles CoffeeScript into Javascript
* `CssEmbedFilter`: embeds image data in your stylesheets
* `CssImportFilter`: inlines imported stylesheets
* `CssMinFilter`: minifies CSS
* `CssRewriteFilter`: fixes relative URLs in CSS assets when moving to a new URL
* `GoogleClosure\CompilerApiFilter`: compiles Javascript using the Google Closure Compiler API
* `GoogleClosure\CompilerJarFilter`: compiles Javascript using the Google Closure Compiler JAR
* `JpegoptimFilter`: optimize your JPEGs
* `JpegtranFilter`: optimize your JPEGs
* `LessFilter`: parses LESS into CSS (using less.js with node.js)
* `LessphpFilter`: parses LESS into CSS (using lessphp)
* `OptiPngFilter`: optimize your PNGs
* `PackerFilter`: compresses Javascript using Dean Edwards's Packer
* `PngoutFilter`: optimize your PNGs
* `CompassFilter`: Compass CSS authoring framework
* `Sass\SassFilter`: parses SASS into CSS
* `Sass\ScssFilter`: parses SCSS into CSS
* `SprocketsFilter`: Sprockets Javascript dependency management
* `StylusFilter`: parses STYL into CSS
* `Yui\CssCompressorFilter`: compresses CSS using the YUI compressor
* `Yui\JsCompressorFilter`: compresses Javascript using the YUI compressor
Asset Manager
-------------
An asset manager is provided for organizing assets.
``` php
<?php
use Assetic\AssetManager;
use Assetic\Asset\FileAsset;
use Assetic\Asset\GlobAsset;
$am = new AssetManager();
$am->set('jquery', new FileAsset('/path/to/jquery.js'));
$am->set('base_css', new GlobAsset('/path/to/css/*'));
```
The asset manager can also be used to reference assets to avoid duplication.
``` php
<?php
use Assetic\Asset\AssetCollection;
use Assetic\Asset\AssetReference;
use Assetic\Asset\FileAsset;
$am->set('my_plugin', new AssetCollection(array(
new AssetReference($am, 'jquery'),
new FileAsset('/path/to/jquery.plugin.js'),
)));
```
Filter Manager
--------------
A filter manager is also provided for organizing filters.
``` php
<?php
use Assetic\FilterManager;
use Assetic\Filter\Sass\SassFilter;
use Assetic\Filter\Yui;
$fm = new FilterManager();
$fm->set('sass', new SassFilter('/path/to/parser/sass'));
$fm->set('yui_css', new Yui\CssCompressorFilter('/path/to/yuicompressor.jar'));
```
Asset Factory
-------------
If you'd rather not create all these objects by hand, you can use the asset
factory, which will do most of the work for you.
``` php
<?php
use Assetic\Factory\AssetFactory;
$factory = new AssetFactory('/path/to/asset/directory/');
$factory->setAssetManager($am);
$factory->setFilterManager($fm);
$factory->setDebug(true);
$css = $factory->createAsset(array(
'@reset', // load the asset manager's "reset" asset
'css/src/*.scss', // load every scss files from "/path/to/asset/directory/css/src/"
), array(
'scss', // filter through the filter manager's "scss" filter
'?yui_css', // don't use this filter in debug mode
));
echo $css->dump();
```
Prefixing a filter name with a question mark, as `yui_css` is here, will cause
that filter to be omitted when the factory is in debug mode.
Caching
-------
A simple caching mechanism is provided to avoid unnecessary work.
``` php
<?php
use Assetic\Asset\AssetCache;
use Assetic\Asset\FileAsset;
use Assetic\Cache\FilesystemCache;
use Assetic\Filter\Yui;
$yui = new Yui\JsCompressorFilter('/path/to/yuicompressor.jar');
$js = new AssetCache(
new FileAsset('/path/to/some.js', array($yui)),
new FilesystemCache('/path/to/cache')
);
// the YUI compressor will only run on the first call
$js->dump();
$js->dump();
$js->dump();
```
Static Assets
-------------
Alternatively you can just write filtered assets to your web directory and be
done with it.
``` php
<?php
use Assetic\AssetWriter;
$writer = new AssetWriter('/path/to/web');
$writer->writeManagerAssets($am);
```
Twig
----
To use the Assetic [Twig][3] extension you must register it to your Twig
environment:
``` php
<?php
$twig->addExtension(new AsseticExtension($factory, $debug));
```
Once in place, the extension exposes a stylesheets and a javascripts tag with a syntax similar
to what the asset factory uses:
``` html+jinja
{% stylesheets '/path/to/sass/main.sass' filter='sass,?yui_css' output='css/all.css' %}
<link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
{% endstylesheets %}
```
This example will render one `link` element on the page that includes a URL
where the filtered asset can be found.
When the extension is in debug mode, this same tag will render multiple `link`
elements, one for each asset referenced by the `css/src/*.sass` glob. The
specified filters will still be applied, unless they are marked as optional
using the `?` prefix.
This behavior can also be triggered by setting a `debug` attribute on the tag:
``` html+jinja
{% stylesheets 'css/*' debug=true %} ... {% stylesheets %}
```
These assets need to be written to the web directory so these URLs don't
return 404 errors.
``` php
<?php
use Assetic\AssetWriter;
use Assetic\Extension\Twig\TwigFormulaLoader;
use Assetic\Extension\Twig\TwigResource;
use Assetic\Factory\LazyAssetManager;
$am = new LazyAssetManager($factory);
// enable loading assets from twig templates
$am->setLoader('twig', new TwigFormulaLoader($twig));