PK =\GM7T T Gemfilenu W+A source "https://rubygems.org"
gem "sprockets", "~> 1.0.0"
gem "sass"
gem "compass"
PK =\GMk. CHANGELOG-1.1.mdnu W+A 1.1.2 (July 18, 2013)
-------------------
* Fixed deep mtime on asset collections
* `CallablesFilter` now implements `DependencyExtractorInterface`
* Fixed detection of "partial" children in subfolders in `SassFilter`
* Restored `PathUtils` for BC
1.1.1 (June 1, 2013)
--------------------
* Fixed cloning of asset collections
* Fixed environment var inheritance
* Replaced `AssetWriter::getCombinations()` for BC, even though we don't use it
* Added support for `@import-once` to Less filters
1.1.0 (May 15, 2013)
--------------------
* Added LazyAssetManager::getLastModified() for determining "deep" mtime
* Added DartFilter
* Added EmberPrecompile
* Added GssFilter
* Added PhpCssEmbedFilter
* Added RooleFilter
* Added TypeScriptFilter
* Added the possibility to configure additional load paths for less and lessphp
* Added the UglifyCssFilter
* Fixed the handling of directories in the GlobAsset. #256
* Added Handlebars support
* Added Scssphp-compass support
* Added the CacheBustingWorker
* Added the UglifyJs2Filter
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
PK =\GM: CHANGELOG-1.0.mdnu W+A 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
PK =\GMv$ v$ README.mdnu W+A # Assetic [![Build Status](https://travis-ci.org/kriswallsmith/assetic.png?branch=master)](https://travis-ci.org/kriswallsmith/assetic) ![project status](http://stillmaintained.com/kriswallsmith/assetic.png) #
Assetic is an asset management framework for PHP.
``` php
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
dump();
```
The filters applied to the collection will cascade to each asset leaf if you
iterate over it.
``` php
dump();
}
```
The core provides the following filters in the `Assetic\Filter` namespace:
* `CoffeeScriptFilter`: compiles CoffeeScript into Javascript
* `CompassFilter`: Compass CSS authoring framework
* `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
* `DartFilter`: compiles Javascript using dart2js
* `EmberPrecompileFilter`: precompiles Handlebars templates into Javascript for use in the Ember.js framework
* `GoogleClosure\CompilerApiFilter`: compiles Javascript using the Google Closure Compiler API
* `GoogleClosure\CompilerJarFilter`: compiles Javascript using the Google Closure Compiler JAR
* `GssFilter`: compliles CSS using the Google Closure Stylesheets Compiler
* `HandlebarsFilter`: compiles Handlebars templates into Javascript
* `JpegoptimFilter`: optimize your JPEGs
* `JpegtranFilter`: optimize your JPEGs
* `JSMinFilter`: minifies Javascript
* `JSMinPlusFilter`: minifies Javascript
* `LessFilter`: parses LESS into CSS (using less.js with node.js)
* `LessphpFilter`: parses LESS into CSS (using lessphp)
* `OptiPngFilter`: optimize your PNGs
* `PackagerFilter`: parses Javascript for packager tags
* `PackerFilter`: compresses Javascript using Dean Edwards's Packer
* `PhpCssEmbedFilter`: embeds image data in your stylesheet
* `PngoutFilter`: optimize your PNGs
* `Sass\SassFilter`: parses SASS into CSS
* `Sass\ScssFilter`: parses SCSS into CSS
* `ScssphpFilter`: parses SCSS using scssphp
* `SprocketsFilter`: Sprockets Javascript dependency management
* `StylusFilter`: parses STYL into CSS
* `TypeScriptFilter`: parses TypeScript into Javascript
* `UglifyCssFilter`: minifies CSS
* `UglifyJs2Filter`: minifies Javascript
* `UglifyJsFilter`: minifies Javascript
* `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
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
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
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
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
dump();
$js->dump();
$js->dump();
```
Cache Busting
-------------
You can use the CacheBustingWorker to provide unique names.
Two strategies are provided: CacheBustingWorker::STRATEGY_CONTENT (content based), CacheBustingWorker::STRATEGY_MODIFICATION (modification time based)
``` php
setAssetManager($am);
$factory->setFilterManager($fm);
$factory->setDebug(true);
$factory->addWorker(new CacheBustingWorker(CacheBustingWorker::STRATEGY_CONTENT));
$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();
```
Static Assets
-------------
Alternatively you can just write filtered assets to your web directory and be
done with it.
``` php
writeManagerAssets($am);
```
Twig
----
To use the Assetic [Twig][3] extension you must register it to your Twig
environment:
``` php
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' %}
{% 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
setLoader('twig', new TwigFormulaLoader($twig));
// loop through all your templates
foreach ($templates as $template) {
$resource = new TwigResource($twigLoader, $template);
$am->addResource($resource, 'twig');
}
$writer = new AssetWriter('/path/to/web');
$writer->writeManagerAssets($am);
```
---
Assetic is based on the Python [webassets][1] library (available on
[GitHub][2]).
[1]: http://elsdoerfer.name/docs/webassets
[2]: https://github.com/miracle2k/webassets
[3]: http://twig.sensiolabs.org
PK =\GMַ[s src/functions.phpnu W+A factory = $factory;
}
/**
* Returns an array of javascript URLs.
*
* @param array|string $inputs Input strings
* @param array|string $filters Filter names
* @param array $options An array of options
*
* @return array An array of javascript URLs
*/
function assetic_javascripts($inputs = array(), $filters = array(), array $options = array())
{
if (!isset($options['output'])) {
$options['output'] = 'js/*.js';
}
return _assetic_urls($inputs, $filters, $options);
}
/**
* Returns an array of stylesheet URLs.
*
* @param array|string $inputs Input strings
* @param array|string $filters Filter names
* @param array $options An array of options
*
* @return array An array of stylesheet URLs
*/
function assetic_stylesheets($inputs = array(), $filters = array(), array $options = array())
{
if (!isset($options['output'])) {
$options['output'] = 'css/*.css';
}
return _assetic_urls($inputs, $filters, $options);
}
/**
* Returns an image URL.
*
* @param string $input An input
* @param array|string $filters Filter names
* @param array $options An array of options
*
* @return string An image URL
*/
function assetic_image($input, $filters = array(), array $options = array())
{
if (!isset($options['output'])) {
$options['output'] = 'images/*';
}
$urls = _assetic_urls($input, $filters, $options);
return current($urls);
}
/**
* Returns an array of asset urls.
*
* @param array|string $inputs Input strings
* @param array|string $filters Filter names
* @param array $options An array of options
*
* @return array An array of URLs
*/
function _assetic_urls($inputs = array(), $filters = array(), array $options = array())
{
global $_assetic;
if (!is_array($inputs)) {
$inputs = array_filter(array_map('trim', explode(',', $inputs)));
}
if (!is_array($filters)) {
$filters = array_filter(array_map('trim', explode(',', $filters)));
}
$coll = $_assetic->factory->createAsset($inputs, $filters, $options);
$debug = isset($options['debug']) ? $options['debug'] : $_assetic->factory->isDebug();
$combine = isset($options['combine']) ? $options['combine'] : !$debug;
$one = $coll->getTargetPath();
if ($combine) {
$many = array($one);
} else {
$many = array();
foreach ($coll as $leaf) {
$many[] = $leaf->getTargetPath();
}
}
return new TraversableString($one, $many);
}
PK =\GM` src/Assetic/AssetWriter.phpnu W+A
* @author Johannes M. Schmitt
*/
class AssetWriter
{
private $dir;
private $values;
/**
* Constructor.
*
* @param string $dir The base web directory
* @param array $values Variable values
*
* @throws \InvalidArgumentException if a variable value is not a string
*/
public function __construct($dir, array $values = array())
{
foreach ($values as $var => $vals) {
foreach ($vals as $value) {
if (!is_string($value)) {
throw new \InvalidArgumentException(sprintf('All variable values must be strings, but got %s for variable "%s".', json_encode($value), $var));
}
}
}
$this->dir = $dir;
$this->values = $values;
}
public function writeManagerAssets(AssetManager $am)
{
foreach ($am->getNames() as $name) {
$this->writeAsset($am->get($name));
}
}
public function writeAsset(AssetInterface $asset)
{
foreach (VarUtils::getCombinations($asset->getVars(), $this->values) as $combination) {
$asset->setValues($combination);
static::write(
$this->dir.'/'.VarUtils::resolve(
$asset->getTargetPath(),
$asset->getVars(),
$asset->getValues()
),
$asset->dump()
);
}
}
protected static function write($path, $contents)
{
if (!is_dir($dir = dirname($path)) && false === @mkdir($dir, 0777, true)) {
throw new \RuntimeException('Unable to create directory '.$dir);
}
if (false === @file_put_contents($path, $contents)) {
throw new \RuntimeException('Unable to write file '.$path);
}
}
/**
* Not used.
*
* This method is provided for backward compatibility with certain versions
* of AsseticBundle.
*/
private function getCombinations(array $vars)
{
return VarUtils::getCombinations($vars, $this->values);
}
}
PK =\GM4 ) src/Assetic/Exception/FilterException.phpnu W+A
*/
class FilterException extends \RuntimeException implements Exception
{
private $originalMessage;
private $input;
public static function fromProcess(Process $proc)
{
$message = sprintf("An error occurred while running:\n%s", $proc->getCommandLine());
$errorOutput = $proc->getErrorOutput();
if (!empty($errorOutput)) {
$message .= "\n\nError Output:\n".str_replace("\r", '', $errorOutput);
}
$output = $proc->getOutput();
if (!empty($output)) {
$message .= "\n\nOutput:\n".str_replace("\r", '', $output);
}
return new self($message);
}
public function __construct($message, $code = 0, \Exception $previous = null)
{
parent::__construct($message, $code, $previous);
$this->originalMessage = $message;
}
public function setInput($input)
{
$this->input = $input;
$this->updateMessage();
return $this;
}
public function getInput()
{
return $this->input;
}
private function updateMessage()
{
$message = $this->originalMessage;
if (!empty($this->input)) {
$message .= "\n\nInput:\n".$this->input;
}
$this->message = $message;
}
}
PK =\GM| | # src/Assetic/Exception/Exception.phpnu W+A
*/
interface Exception
{
}
PK =\GM 1 src/Assetic/Extension/Twig/AsseticTokenParser.phpnu W+A factory = $factory;
$this->tag = $tag;
$this->output = $output;
$this->single = $single;
$this->extensions = $extensions;
}
public function parse(\Twig_Token $token)
{
$inputs = array();
$filters = array();
$name = null;
$attributes = array(
'output' => $this->output,
'var_name' => 'asset_url',
'vars' => array(),
);
$stream = $this->parser->getStream();
while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) {
if ($stream->test(\Twig_Token::STRING_TYPE)) {
// '@jquery', 'js/src/core/*', 'js/src/extra.js'
$inputs[] = $stream->next()->getValue();
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'filter')) {
// filter='yui_js'
$stream->next();
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
$filters = array_merge($filters, array_filter(array_map('trim', explode(',', $stream->expect(\Twig_Token::STRING_TYPE)->getValue()))));
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'output')) {
// output='js/packed/*.js' OR output='js/core.js'
$stream->next();
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
$attributes['output'] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'name')) {
// name='core_js'
$stream->next();
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
$name = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'as')) {
// as='the_url'
$stream->next();
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
$attributes['var_name'] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'debug')) {
// debug=true
$stream->next();
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
$attributes['debug'] = 'true' == $stream->expect(\Twig_Token::NAME_TYPE, array('true', 'false'))->getValue();
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'combine')) {
// combine=true
$stream->next();
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
$attributes['combine'] = 'true' == $stream->expect(\Twig_Token::NAME_TYPE, array('true', 'false'))->getValue();
} elseif ($stream->test(\Twig_Token::NAME_TYPE, 'vars')) {
// vars=['locale','browser']
$stream->next();
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
$stream->expect(\Twig_Token::PUNCTUATION_TYPE, '[');
while ($stream->test(\Twig_Token::STRING_TYPE)) {
$attributes['vars'][] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
if (!$stream->test(\Twig_Token::PUNCTUATION_TYPE, ',')) {
break;
}
$stream->next();
}
$stream->expect(\Twig_Token::PUNCTUATION_TYPE, ']');
} elseif ($stream->test(\Twig_Token::NAME_TYPE, $this->extensions)) {
// an arbitrary configured attribute
$key = $stream->next()->getValue();
$stream->expect(\Twig_Token::OPERATOR_TYPE, '=');
$attributes[$key] = $stream->expect(\Twig_Token::STRING_TYPE)->getValue();
} else {
$token = $stream->getCurrent();
throw new \Twig_Error_Syntax(sprintf('Unexpected token "%s" of value "%s"', \Twig_Token::typeToEnglish($token->getType(), $token->getLine()), $token->getValue()), $token->getLine());
}
}
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(array($this, 'testEndTag'), true);
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
if ($this->single && 1 < count($inputs)) {
$inputs = array_slice($inputs, -1);
}
if (!$name) {
$name = $this->factory->generateAssetName($inputs, $filters, $attributes);
}
$asset = $this->factory->createAsset($inputs, $filters, $attributes + array('name' => $name));
return $this->createNode($asset, $body, $inputs, $filters, $name, $attributes, $token->getLine(), $this->getTag());
}
public function getTag()
{
return $this->tag;
}
public function testEndTag(\Twig_Token $token)
{
return $token->test(array('end'.$this->getTag()));
}
protected function createNode(AssetInterface $asset, \Twig_NodeInterface $body, array $inputs, array $filters, $name, array $attributes = array(), $lineno = 0, $tag = null)
{
return new AsseticNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag);
}
}
PK =\GM" 4 src/Assetic/Extension/Twig/AsseticFilterFunction.phpnu W+A filter = $filter;
parent::__construct($options);
}
public function compile()
{
return sprintf('$this->env->getExtension(\'assetic\')->getFilterInvoker(\'%s\')->invoke', $this->filter);
}
}
PK =\GMI
* src/Assetic/Extension/Twig/AsseticNode.phpnu W+A $body);
$attributes = array_replace(
array('debug' => null, 'combine' => null, 'var_name' => 'asset_url'),
$attributes,
array('asset' => $asset, 'inputs' => $inputs, 'filters' => $filters, 'name' => $name)
);
parent::__construct($nodes, $attributes, $lineno, $tag);
}
public function compile(\Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this);
$combine = $this->getAttribute('combine');
$debug = $this->getAttribute('debug');
if (null === $combine && null !== $debug) {
$combine = !$debug;
}
if (null === $combine) {
$compiler
->write("if (isset(\$context['assetic']['debug']) && \$context['assetic']['debug']) {\n")
->indent()
;
$this->compileDebug($compiler);
$compiler
->outdent()
->write("} else {\n")
->indent()
;
$this->compileAsset($compiler, $this->getAttribute('asset'), $this->getAttribute('name'));
$compiler
->outdent()
->write("}\n")
;
} elseif ($combine) {
$this->compileAsset($compiler, $this->getAttribute('asset'), $this->getAttribute('name'));
} else {
$this->compileDebug($compiler);
}
$compiler
->write('unset($context[')
->repr($this->getAttribute('var_name'))
->raw("]);\n")
;
}
protected function compileDebug(\Twig_Compiler $compiler)
{
$i = 0;
foreach ($this->getAttribute('asset') as $leaf) {
$leafName = $this->getAttribute('name').'_'.$i++;
$this->compileAsset($compiler, $leaf, $leafName);
}
}
protected function compileAsset(\Twig_Compiler $compiler, AssetInterface $asset, $name)
{
if ($vars = $asset->getVars()) {
$compiler->write("// check variable conditions\n");
foreach ($vars as $var) {
$compiler
->write("if (!isset(\$context['assetic']['vars']['$var'])) {\n")
->indent()
->write("throw new \RuntimeException(sprintf('The asset \"".$name."\" expected variable \"".$var."\" to be set, but got only these vars: %s. Did you set-up a value supplier?', isset(\$context['assetic']['vars']) && \$context['assetic']['vars'] ? implode(', ', \$context['assetic']['vars']) : '# none #'));\n")
->outdent()
->write("}\n")
;
}
$compiler->raw("\n");
}
$compiler
->write("// asset \"$name\"\n")
->write('$context[')
->repr($this->getAttribute('var_name'))
->raw('] = ')
;
$this->compileAssetUrl($compiler, $asset, $name);
$compiler
->raw(";\n")
->subcompile($this->getNode('body'))
;
}
protected function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name)
{
if (!$vars = $asset->getVars()) {
$compiler->repr($asset->getTargetPath());
return;
}
$compiler
->raw("strtr(")
->string($asset->getTargetPath())
->raw(", array(");
;
$first = true;
foreach ($vars as $var) {
if (!$first) {
$compiler->raw(", ");
}
$first = false;
$compiler
->string("{".$var."}")
->raw(" => \$context['assetic']['vars']['$var']")
;
}
$compiler
->raw("))")
;
}
}
PK =\GM4c c / src/Assetic/Extension/Twig/AsseticExtension.phpnu W+A factory = $factory;
$this->functions = array();
$this->valueSupplier = $valueSupplier;
foreach ($functions as $function => $options) {
if (is_integer($function) && is_string($options)) {
$this->functions[$options] = array('filter' => $options);
} else {
$this->functions[$function] = $options + array('filter' => $function);
}
}
}
public function getTokenParsers()
{
return array(
new AsseticTokenParser($this->factory, 'javascripts', 'js/*.js'),
new AsseticTokenParser($this->factory, 'stylesheets', 'css/*.css'),
new AsseticTokenParser($this->factory, 'image', 'images/*', true),
);
}
public function getFunctions()
{
$functions = array();
foreach ($this->functions as $function => $filter) {
$functions[$function] = new AsseticFilterFunction($function);
}
return $functions;
}
public function getGlobals()
{
return array(
'assetic' => array(
'debug' => $this->factory->isDebug(),
'vars' => null !== $this->valueSupplier ? new ValueContainer($this->valueSupplier) : array(),
),
);
}
public function getFilterInvoker($function)
{
return new AsseticFilterInvoker($this->factory, $this->functions[$function]);
}
public function getName()
{
return 'assetic';
}
}
PK =\GMY - src/Assetic/Extension/Twig/ValueContainer.phpnu W+A
*/
class ValueContainer implements \ArrayAccess, \IteratorAggregate, \Countable
{
private $values;
private $valueSupplier;
public function __construct(ValueSupplierInterface $valueSupplier)
{
$this->valueSupplier = $valueSupplier;
}
public function offsetExists($offset)
{
$this->initialize();
return array_key_exists($offset, $this->values);
}
public function offsetGet($offset)
{
$this->initialize();
if (!array_key_exists($offset, $this->values)) {
throw new \OutOfRangeException(sprintf('The variable "%s" does not exist.', $offset));
}
return $this->values[$offset];
}
public function offsetSet($offset, $value)
{
throw new \BadMethodCallException('The ValueContainer is read-only.');
}
public function offsetUnset($offset)
{
throw new \BadMethodCallException('The ValueContainer is read-only.');
}
public function getIterator()
{
$this->initialize();
return new \ArrayIterator($this->values);
}
public function count()
{
$this->initialize();
return count($this->values);
}
private function initialize()
{
if (null === $this->values) {
$this->values = $this->valueSupplier->getValues();
}
}
}
PK =\GM?x x + src/Assetic/Extension/Twig/TwigResource.phpnu W+A
*/
class TwigResource implements ResourceInterface
{
private $loader;
private $name;
public function __construct(\Twig_LoaderInterface $loader, $name)
{
$this->loader = $loader;
$this->name = $name;
}
public function getContent()
{
try {
return $this->loader->getSource($this->name);
} catch (\Twig_Error_Loader $e) {
return '';
}
}
public function isFresh($timestamp)
{
try {
return $this->loader->isFresh($this->name, $timestamp);
} catch (\Twig_Error_Loader $e) {
return false;
}
}
public function __toString()
{
return $this->name;
}
}
PK =\GM 0 src/Assetic/Extension/Twig/TwigFormulaLoader.phpnu W+A
*/
class TwigFormulaLoader implements FormulaLoaderInterface
{
private $twig;
public function __construct(\Twig_Environment $twig)
{
$this->twig = $twig;
}
public function load(ResourceInterface $resource)
{
try {
$tokens = $this->twig->tokenize($resource->getContent(), (string) $resource);
$nodes = $this->twig->parse($tokens);
} catch (\Exception $e) {
return array();
}
return $this->loadNode($nodes);
}
/**
* Loads assets from the supplied node.
*
* @param \Twig_Node $node
*
* @return array An array of asset formulae indexed by name
*/
private function loadNode(\Twig_Node $node)
{
$formulae = array();
if ($node instanceof AsseticNode) {
$formulae[$node->getAttribute('name')] = array(
$node->getAttribute('inputs'),
$node->getAttribute('filters'),
array(
'output' => $node->getAttribute('asset')->getTargetPath(),
'name' => $node->getAttribute('name'),
'debug' => $node->getAttribute('debug'),
'combine' => $node->getAttribute('combine'),
'vars' => $node->getAttribute('vars'),
),
);
} elseif ($node instanceof \Twig_Node_Expression_Function) {
$name = version_compare(\Twig_Environment::VERSION, '1.2.0-DEV', '<')
? $node->getNode('name')->getAttribute('name')
: $node->getAttribute('name');
if ($this->twig->getFunction($name) instanceof AsseticFilterFunction) {
$arguments = array();
foreach ($node->getNode('arguments') as $argument) {
$arguments[] = eval('return '.$this->twig->compile($argument).';');
}
$invoker = $this->twig->getExtension('assetic')->getFilterInvoker($name);
$inputs = isset($arguments[0]) ? (array) $arguments[0] : array();
$filters = $invoker->getFilters();
$options = array_replace($invoker->getOptions(), isset($arguments[1]) ? $arguments[1] : array());
if (!isset($options['name'])) {
$options['name'] = $invoker->getFactory()->generateAssetName($inputs, $filters, $options);
}
$formulae[$options['name']] = array($inputs, $filters, $options);
}
}
foreach ($node as $child) {
if ($child instanceof \Twig_Node) {
$formulae += $this->loadNode($child);
}
}
return $formulae;
}
}
PK =\GMꬲ; ; 3 src/Assetic/Extension/Twig/AsseticFilterInvoker.phpnu W+A
*/
class AsseticFilterInvoker
{
private $factory;
private $filters;
private $options;
public function __construct($factory, $filter)
{
$this->factory = $factory;
if (is_array($filter) && isset($filter['filter'])) {
$this->filters = (array) $filter['filter'];
$this->options = isset($filter['options']) ? (array) $filter['options'] : array();
} else {
$this->filters = (array) $filter;
$this->options = array();
}
}
public function getFactory()
{
return $this->factory;
}
public function getFilters()
{
return $this->filters;
}
public function getOptions()
{
return $this->options;
}
public function invoke($input, array $options = array())
{
$asset = $this->factory->createAsset($input, $this->filters, $options + $this->options);
return $asset->getTargetPath();
}
}
PK =\GM] src/Assetic/Util/PathUtils.phpnu W+A
*/
abstract class CssUtils
{
const REGEX_URLS = '/url\((["\']?)(?P.*?)(\\1)\)/';
const REGEX_IMPORTS = '/@import (?:url\()?(\'|"|)(?P[^\'"\)\n\r]*)\1\)?;?/';
const REGEX_IMPORTS_NO_URLS = '/@import (?!url\()(\'|"|)(?P[^\'"\)\n\r]*)\1;?/';
const REGEX_IE_FILTERS = '/src=(["\']?)(?P.*?)\\1/';
/**
* Filters all references -- url() and "@import" -- through a callable.
*
* @param string $content The CSS
* @param callable $callback A PHP callable
* @param integer $limit
* @param integer $count
*
* @return string The filtered CSS
*/
public static function filterReferences($content, $callback, $limit = -1, &$count = 0)
{
$content = static::filterUrls($content, $callback, $limit, $count);
$content = static::filterImports($content, $callback, $limit, $count, false);
$content = static::filterIEFilters($content, $callback, $limit, $count);
return $content;
}
/**
* Filters all CSS url()'s through a callable.
*
* @param string $content The CSS
* @param callable $callback A PHP callable
* @param integer $limit Limit the number of replacements
* @param integer $count Will be populated with the count
*
* @return string The filtered CSS
*/
public static function filterUrls($content, $callback, $limit = -1, &$count = 0)
{
return preg_replace_callback(static::REGEX_URLS, $callback, $content, $limit, $count);
}
/**
* Filters all CSS imports through a callable.
*
* @param string $content The CSS
* @param callable $callback A PHP callable
* @param integer $limit Limit the number of replacements
* @param integer $count Will be populated with the count
* @param Boolean $includeUrl Whether to include url() in the pattern
*
* @return string The filtered CSS
*/
public static function filterImports($content, $callback, $limit = -1, &$count = 0, $includeUrl = true)
{
$pattern = $includeUrl ? static::REGEX_IMPORTS : static::REGEX_IMPORTS_NO_URLS;
return preg_replace_callback($pattern, $callback, $content, $limit, $count);
}
/**
* Filters all IE filters (AlphaImageLoader filter) through a callable.
*
* @param string $content The CSS
* @param callable $callback A PHP callable
* @param integer $limit Limit the number of replacements
* @param integer $count Will be populated with the count
*
* @return string The filtered CSS
*/
public static function filterIEFilters($content, $callback, $limit = -1, &$count = 0)
{
return preg_replace_callback(static::REGEX_IE_FILTERS, $callback, $content, $limit, $count);
}
/**
* Extracts all references from the supplied CSS content.
*
* @param string $content The CSS content
*
* @return array An array of unique URLs
*/
public static function extractImports($content)
{
$imports = array();
static::filterImports($content, function($matches) use(& $imports) {
$imports[] = $matches['url'];
});
return array_unique($imports);
}
final private function __construct() { }
}
PK =\GM"Y Y src/Assetic/Util/VarUtils.phpnu W+A
*/
abstract class VarUtils
{
/**
* Resolves variable placeholders.
*
* @param string $template A template string
* @param array $vars Variable names
* @param array $values Variable values
*
* @return string The resolved string
*
* @throws \InvalidArgumentException If there is a variable with no value
*/
public static function resolve($template, array $vars, array $values)
{
$map = array();
foreach ($vars as $var) {
if (false === strpos($template, '{'.$var.'}')) {
continue;
}
if (!isset($values[$var])) {
throw new \InvalidArgumentException(sprintf('The template "%s" contains the variable "%s", but was not given any value for it.', $template, $var));
}
$map['{'.$var.'}'] = $values[$var];
}
return strtr($template, $map);
}
public static function getCombinations(array $vars, array $values)
{
if (!$vars) {
return array(array());
}
$combinations = array();
$nbValues = array();
foreach ($values as $var => $vals) {
if (!in_array($var, $vars, true)) {
continue;
}
$nbValues[$var] = count($vals);
}
for ($i = array_product($nbValues), $c = $i * 2; $i < $c; $i++) {
$k = $i;
$combination = array();
foreach ($vars as $var) {
$combination[$var] = $values[$var][$k % $nbValues[$var]];
$k = intval($k / $nbValues[$var]);
}
$combinations[] = $combination;
}
return $combinations;
}
final private function __construct() { }
}
PK =\GMu\ \ src/Assetic/Util/LessUtils.phpnu W+A
*/
abstract class LessUtils extends CssUtils
{
const REGEX_IMPORTS = '/@import(?:-once)? (?:url\()?(\'|"|)(?P[^\'"\)\n\r]*)\1\)?;?/';
const REGEX_IMPORTS_NO_URLS = '/@import(?:-once)? (?!url\()(\'|"|)(?P[^\'"\)\n\r]*)\1;?/';
}
PK =\GM߷յn n &