[AsseticBundle] added support for Twig functions
This commit is contained in:
parent
59c6609aec
commit
f3728744b4
@ -71,6 +71,9 @@ class AsseticExtension extends Extension
|
||||
}
|
||||
}
|
||||
|
||||
// twig functions
|
||||
$container->getDefinition('assetic.twig_extension')->replaceArgument(2, $config['twig']['functions']);
|
||||
|
||||
// choose dynamic or static
|
||||
if ($parameterBag->resolveValue($parameterBag->get('assetic.use_controller'))) {
|
||||
$loader->load('controller.xml');
|
||||
|
@ -91,6 +91,29 @@ class Configuration implements ConfigurationInterface
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
||||
// twig
|
||||
->children()
|
||||
->arrayNode('twig')
|
||||
->addDefaultsIfNotSet()
|
||||
->defaultValue(array())
|
||||
->fixXmlConfig('function')
|
||||
->children()
|
||||
->arrayNode('functions')
|
||||
->addDefaultsIfNotSet()
|
||||
->defaultValue(array())
|
||||
->useAttributeAsKey('name')
|
||||
->prototype('variable')
|
||||
->treatNullLike(array())
|
||||
->validate()
|
||||
->ifTrue(function($v) { return !is_array($v); })
|
||||
->thenInvalid('The assetic.twig.functions config %s must be either null or an array.')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
return $builder;
|
||||
|
@ -11,6 +11,7 @@
|
||||
<xsd:sequence>
|
||||
<xsd:element name="bundle" type="bundle" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="filter" type="filter" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="twig" type="twig" minOccurs="0" maxOccurs="unbounded" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="debug" type="xsd:string" />
|
||||
<xsd:attribute name="use-controller" type="xsd:string" />
|
||||
@ -32,4 +33,15 @@
|
||||
<xsd:attribute name="resource" type="xsd:string" />
|
||||
<xsd:anyAttribute namespace="##any" processContents="lax" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="twig">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="function" type="twig_function" minOccurs="0" maxOccurs="unbounded" />
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="twig_function">
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
<xsd:anyAttribute namespace="##any" processContents="lax" />
|
||||
</xsd:complexType>
|
||||
</xsd:schema>
|
||||
|
@ -14,8 +14,8 @@
|
||||
<tag name="twig.extension" />
|
||||
<tag name="assetic.templating.twig" />
|
||||
<argument type="service" id="assetic.asset_factory" />
|
||||
<argument>%assetic.debug%</argument>
|
||||
<argument>%assetic.use_controller%</argument>
|
||||
<argument type="collection" />
|
||||
</service>
|
||||
<service id="assetic.twig_formula_loader" class="%assetic.cached_formula_loader.class%" public="false">
|
||||
<tag name="assetic.formula_loader" alias="twig" />
|
||||
|
@ -20,3 +20,9 @@ assetic:
|
||||
use_controller: true
|
||||
read_from: "%kernel.root_dir%/web"
|
||||
bundles: [TestBundle]
|
||||
filters:
|
||||
yui_css:
|
||||
jar: %kernel.root_dir/java/yui-compressor-2.4.6.jar
|
||||
twig:
|
||||
functions:
|
||||
yui_css: { output: css/*.css }
|
||||
|
@ -23,9 +23,9 @@ class AsseticExtension extends BaseAsseticExtension
|
||||
{
|
||||
private $useController;
|
||||
|
||||
public function __construct(AssetFactory $factory, $debug = false, $useController = false)
|
||||
public function __construct(AssetFactory $factory, $useController = false, $functions = array())
|
||||
{
|
||||
parent::__construct($factory, $debug);
|
||||
parent::__construct($factory, $functions);
|
||||
|
||||
$this->useController = $useController;
|
||||
}
|
||||
|
Reference in New Issue
Block a user