Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Assetic: Updated for latest Assetic development #80

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

Merged
2 commits merged into from
Feb 23, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/AsseticBundle/AsseticBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new TemplatingPass());
$container->addCompilerPass(new AssetManagerPass());
$container->addCompilerPass(new FilterManagerPass());
$container->addCompilerPass(new TemplatingPass());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Symfony\Bundle\AsseticBundle\CacheWarmer;

use Assetic\Factory\LazyAssetManager;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer;

class AssetManagerCacheWarmer extends CacheWarmer
{
protected $am;

public function __construct(LazyAssetManager $am)
{
$this->am = $am;
}

public function warmUp($cacheDir)
{
$this->am->load();
}

public function isOptional()
{
return true;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Symfony\Bundle\AsseticBundle\DependencyInjection;

use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* Semantic asset configuration.
Expand Down Expand Up @@ -94,6 +96,56 @@ public function load(array $configs, ContainerBuilder $container)
if ($container->hasParameter('assetic.less.compress')) {
$container->getDefinition('assetic.filter.less')->addMethodCall('setCompress', array('%assetic.less.compress%'));
}

$this->registerFormulaResources($container);
}

protected function registerFormulaResources(ContainerBuilder $container)
{
// bundle views/ directories
$am = $container->getDefinition('assetic.asset_manager');
foreach ($container->getParameter('kernel.bundles') as $name => $class) {
$rc = new \ReflectionClass($class);
if (is_dir($dir = dirname($rc->getFileName()).'/Resources/views')) {
foreach (array('twig', 'php') as $engine) {
$container->setDefinition(
'assetic.'.$engine.'_directory_resource.'.$name,
$this->createDirectoryResourceDefinition($name, $dir, $engine)
);
}
}
}

// kernel views/ directory
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/views')) {
foreach (array('twig', 'php') as $engine) {
$container->setDefinition(
'assetic.'.$engine.'_directory_resource.kernel',
$this->createDirectoryResourceDefinition('', $dir, $engine)
);
}
}
}

/**
* @todo decorate an abstract xml definition
*/
protected function createDirectoryResourceDefinition($bundle, $dir, $engine)
{
$definition = new Definition('%assetic.directory_resource.class%');

$definition
->addArgument(new Reference('templating.name_parser'))
->addArgument(new Reference('templating.loader'))
->addArgument($bundle)
->addArgument($dir)
->addArgument('/\.'.$engine.'$/')
->addTag('assetic.templating.'.$engine)
->addTag('assetic.formula_resource', array('loader' => $engine))
->setPublic(false)
;

return $definition;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,34 @@ public function process(ContainerBuilder $container)
}

$am = $container->getDefinition('assetic.asset_manager');

// add assets
foreach ($container->findTaggedServiceIds('assetic.asset') as $id => $attributes) {
foreach ($attributes as $attr) {
if (isset($attr['alias'])) {
$am->addMethodCall('set', array($attr['alias'], new Reference($id)));
}
}
}

// add loaders
$loaders = array();
foreach ($container->findTaggedServiceIds('assetic.formula_loader') as $id => $attributes) {
foreach ($attributes as $attr) {
if (isset($attr['alias'])) {
$loaders[$attr['alias']] = new Reference($id);
}
}
}
$am->setArgument(1, $loaders);

// add resources
foreach ($container->findTaggedServiceIds('assetic.formula_resource') as $id => $attributes) {
foreach ($attributes as $attr) {
if (isset($attr['loader'])) {
$am->addMethodCall('addResource', array($attr['loader'], new Reference($id)));
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
* This pass removes services associated with unused templating engines.
*
* @author Kris Wallsmith <[email protected]>
*/
class TemplatingPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
Expand All @@ -25,17 +30,13 @@ public function process(ContainerBuilder $container)
$am = $container->getDefinition('assetic.asset_manager');
$engines = $container->getParameterBag()->resolveValue($container->getParameter('templating.engines'));

if (in_array('twig', $engines)) {
$am->addMethodCall('addCacheFile', array('%kernel.cache_dir%/assetic_twig_assets.php'));
} else {
if (!in_array('twig', $engines)) {
foreach ($container->findTaggedServiceIds('assetic.templating.twig') as $id => $attr) {
$container->remove($id);
}
}

if (in_array('php', $engines)) {
// $am->addMethodCall('addCacheFile', array('%kernel.cache_dir%/assetic_php_assets.php'));
} else {
if (!in_array('php', $engines)) {
foreach ($container->findTaggedServiceIds('assetic.templating.php') as $id => $attr) {
$container->remove($id);
}
Expand Down
90 changes: 0 additions & 90 deletions src/Symfony/Bundle/AsseticBundle/Factory/AssetManager.php

This file was deleted.

Loading