PK ML7T T Gemfilenu W+A source "https://rubygems.org"
gem "sprockets", "~> 1.0.0"
gem "sass"
gem "compass"
PK MLk. 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 ML: 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 MLuʠ) ) 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 |
The "target path" property denotes where an asset (or an collection of assets) should be dumped.
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:
* `AutoprefixerFilter`: Parse and update vendor-specific properties using autoprefixer
* `CoffeeScriptFilter`: compiles CoffeeScript into Javascript
* `CompassFilter`: Compass CSS authoring framework
* `CssEmbedFilter`: embeds image data in your stylesheets
* `CssImportFilter`: inlines imported stylesheets
* `CssMinFilter`: minifies CSS
* `CleanCssFilter`: 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
* `JSqueezeFilter`: compresses 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
* `ReactJsxFilter`: compiles React JSX into JavaScript
* `Sass\SassFilter`: parses SASS into CSS
* `Sass\ScssFilter`: parses SCSS into CSS
* `SassphpFilter`: parses Sass into CSS using the sassphp bindings for Libsass
* `ScssphpFilter`: parses SCSS using scssphp
* `SeparatorFilter`: inserts a separator between assets to prevent merge failures
* `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();
```
The `AssetFactory` is constructed with a root directory which is used as the base directory for relative asset paths.
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.
You can also register [Workers](src/Assetic/Factory/Worker/WorkerInterface.php) on the factory and all assets created
by it will be passed to the worker's `process()` method before being returned. See _Cache Busting_ below for an example.
Dumping Assets to static files
------------------------------
You can dump all the assets an AssetManager holds to files in a directory. This will probably be below your webserver's document root
so the files can be served statically.
``` php
writeManagerAssets($am);
```
This will make use of the assets' target path.
Cache Busting
-------------
If you serve your assets from static files as just described, you can use the CacheBustingWorker to rewrite the target
paths for assets. It will insert an identifier before the filename extension that is unique for a particular version
of the asset.
This identifier is based on the modification time of the asset and will also take depended-on assets into
consideration if the applied filters support it.
``` php
setAssetManager($am);
$factory->setFilterManager($fm);
$factory->setDebug(true);
$factory->addWorker(new CacheBustingWorker());
$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();
```
Internal caching
-------
A simple caching mechanism is provided to avoid unnecessary work.
``` php
dump();
$js->dump();
$js->dump();
```
Twig
----
To use the Assetic [Twig][3] extension you must register it to your Twig
environment:
``` php
addExtension(new AsseticExtension($factory));
```
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 ML2, , 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 ML 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 ML_y ) 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 MLxY| | # src/Assetic/Exception/Exception.phpnu W+A
*/
interface Exception
{
}
PK MLl 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->getValue()), $token->getLine(), $stream->getFilename());
}
}
$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->createBodyNode($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()));
}
/**
* @param AssetInterface $asset
* @param \Twig_Node $body
* @param array $inputs
* @param array $filters
* @param string $name
* @param array $attributes
* @param int $lineno
* @param string $tag
*
* @return \Twig_Node
*/
protected function createBodyNode(AssetInterface $asset, \Twig_Node $body, array $inputs, array $filters, $name, array $attributes = array(), $lineno = 0, $tag = null)
{
$reflector = new \ReflectionMethod($this, 'createNode');
if (__CLASS__ !== $reflector->getDeclaringClass()->name) {
@trigger_error(sprintf('Overwriting %s::createNode is deprecated since 1.3. Overwrite %s instead.', __CLASS__, __METHOD__), E_USER_DEPRECATED);
return $this->createNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag);
}
return new AsseticNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag);
}
/**
* @param AssetInterface $asset
* @param \Twig_NodeInterface $body
* @param array $inputs
* @param array $filters
* @param string $name
* @param array $attributes
* @param int $lineno
* @param string $tag
*
* @return \Twig_Node
*
* @deprecated since 1.3.0, to be removed in 2.0. Use createBodyNode instead.
*/
protected function createNode(AssetInterface $asset, \Twig_NodeInterface $body, array $inputs, array $filters, $name, array $attributes = array(), $lineno = 0, $tag = null)
{
@trigger_error(sprintf('The %s method is deprecated since 1.3 and will be removed in 2.0. Use createBodyNode instead.', __METHOD__), E_USER_DEPRECATED);
if (!$body instanceof \Twig_Node) {
throw new \InvalidArgumentException('The body must be a Twig_Node. Custom implementations of Twig_NodeInterface are not supported.');
}
return new AsseticNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag);
}
}
PK MLL 4 src/Assetic/Extension/Twig/AsseticFilterFunction.phpnu W+A false,
'needs_context' => false,
'node_class' => '\Assetic\Extension\Twig\AsseticFilterNode',
)));
}
}
PK MLS*t * 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 ML 0 src/Assetic/Extension/Twig/AsseticFilterNode.phpnu W+A raw(sprintf('$this->env->getExtension(\'Assetic\\Extension\\Twig\\AsseticExtension\')->getFilterInvoker(\'%s\')->invoke', $this->getAttribute('name')));
$this->compileArguments($compiler);
}
}
PK ML6Oz / 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[] = 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 MLKmq - 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 MLeՁ + 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 method_exists($this->loader, 'getSourceContext')
? $this->loader->getSourceContext($this->name)->getCode()
: $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 ML&
0 src/Assetic/Extension/Twig/TwigFormulaLoader.phpnu W+A
*/
class TwigFormulaLoader implements FormulaLoaderInterface
{
private $twig;
private $logger;
public function __construct(\Twig_Environment $twig, LoggerInterface $logger = null)
{
$this->twig = $twig;
$this->logger = $logger;
}
public function load(ResourceInterface $resource)
{
try {
$tokens = $this->twig->tokenize(new \Twig_Source($resource->getContent(), (string) $resource));
$nodes = $this->twig->parse($tokens);
} catch (\Exception $e) {
if ($this->logger) {
$this->logger->error(sprintf('The template "%s" contains an error: %s', $resource, $e->getMessage()));
}
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 AsseticFilterNode) {
$name = $node->getAttribute('name');
$arguments = array();
foreach ($node->getNode('arguments') as $argument) {
$arguments[] = eval('return '.$this->twig->compile($argument).';');
}
$invoker = $this->twig->getExtension('Assetic\Extension\Twig\AsseticExtension')->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);
}
}
if ($node->hasAttribute('embedded_templates')) {
foreach ($node->getAttribute('embedded_templates') as $child) {
$formulae += $this->loadNode($child);
}
}
return $formulae;
}
}
PK ML*$F; ; 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 ML{eG G src/Assetic/Util/CssUtils.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/';
const REGEX_COMMENTS = '/(\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)/';
/**
* Filters all references -- url() and "@import" -- through a callable.
*
* @param string $content The CSS
* @param callable $callback A PHP callable
*
* @return string The filtered CSS
*/
public static function filterReferences($content, $callback)
{
$content = static::filterUrls($content, $callback);
$content = static::filterImports($content, $callback, false);
$content = static::filterIEFilters($content, $callback);
return $content;
}
/**
* Filters all CSS url()'s through a callable.
*
* @param string $content The CSS
* @param callable $callback A PHP callable
*
* @return string The filtered CSS
*/
public static function filterUrls($content, $callback)
{
$pattern = static::REGEX_URLS;
return static::filterCommentless($content, function ($part) use (& $callback, $pattern) {
return preg_replace_callback($pattern, $callback, $part);
});
}
/**
* Filters all CSS imports through a callable.
*
* @param string $content The CSS
* @param callable $callback A PHP callable
* @param Boolean $includeUrl Whether to include url() in the pattern
*
* @return string The filtered CSS
*/
public static function filterImports($content, $callback, $includeUrl = true)
{
$pattern = $includeUrl ? static::REGEX_IMPORTS : static::REGEX_IMPORTS_NO_URLS;
return static::filterCommentless($content, function ($part) use (& $callback, $pattern) {
return preg_replace_callback($pattern, $callback, $part);
});
}
/**
* Filters all IE filters (AlphaImageLoader filter) through a callable.
*
* @param string $content The CSS
* @param callable $callback A PHP callable
*
* @return string The filtered CSS
*/
public static function filterIEFilters($content, $callback)
{
$pattern = static::REGEX_IE_FILTERS;
return static::filterCommentless($content, function ($part) use (& $callback, $pattern) {
return preg_replace_callback($pattern, $callback, $part);
});
}
/**
* Filters each non-comment part through a callable.
*
* @param string $content The CSS
* @param callable $callback A PHP callable
*
* @return string The filtered CSS
*/
public static function filterCommentless($content, $callback)
{
$result = '';
foreach (preg_split(static::REGEX_COMMENTS, $content, -1, PREG_SPLIT_DELIM_CAPTURE) as $part) {
if (!preg_match(static::REGEX_COMMENTS, $part, $match) || $part != $match[0]) {
$part = call_user_func($callback, $part);
}
$result .= $part;
}
return $result;
}
/**
* 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(array_filter($imports));
}
final private function __construct()
{
}
}
PK ML4 src/Assetic/Util/SassUtils.phpnu W+A
*/
abstract class SassUtils extends CssUtils
{
const REGEX_COMMENTS = '/((?:\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)|\/\/[^\n]+)/';
}
PK MLAL;a a 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 ML. src/Assetic/Util/LessUtils.phpnu W+A
*/
abstract class LessUtils extends CssUtils
{
const REGEX_IMPORTS = '/@import(?:-once)? (?:\([a-z]*\) )?(?:url\()?(\'|"|)(?P[^\'"\)\n\r]*)\1\)?;?/';
const REGEX_IMPORTS_NO_URLS = '/@import(?:-once)? (?:\([a-z]*\) )?(?!url\()(\'|"|)(?P[^\'"\)\n\r]*)\1;?/';
const REGEX_COMMENTS = '/((?:\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)|\/\/[^\n]+)/';
}
PK ML6& $ src/Assetic/Util/FilesystemUtils.phpnu W+A
*/
class FilesystemUtils
{
/**
* Recursively removes a directory from the filesystem.
*/
public static function removeDirectory($directory)
{
$inner = new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS);
$outer = new \RecursiveIteratorIterator($inner, \RecursiveIteratorIterator::SELF_FIRST);
// remove the files first
foreach ($outer as $file) {
if ($file->isFile()) {
unlink($file);
}
}
// remove the sub-directories next
$files = iterator_to_array($outer);
foreach (array_reverse($files) as $file) {
/** @var \SplFileInfo $file */
if ($file->isDir()) {
rmdir($file);
}
}
// finally the directory itself
rmdir($directory);
}
/**
* Creates a throw-away directory.
*
* This is not considered a "temporary" directory because it will not be
* automatically deleted at the end of the request or process. It must be
* deleted manually.
*
* @param string $prefix A prefix for the directory name
*
* @return string The directory path
*/
public static function createThrowAwayDirectory($prefix)
{
$directory = self::getTemporaryDirectory().DIRECTORY_SEPARATOR.uniqid('assetic_'.$prefix);
mkdir($directory);
return $directory;
}
/**
* Creates a temporary file.
*
* @param string $prefix A prefix for the file name
*
* @return string The file path
*/
public static function createTemporaryFile($prefix)
{
return tempnam(self::getTemporaryDirectory(), 'assetic_'.$prefix);
}
public static function getTemporaryDirectory()
{
return realpath(sys_get_temp_dir());
}
}
PK ML)`n n &