Merge branch 'smarty' into admin

Conflicts:
	core/lib/Thelia/Config/Resources/config.xml
	core/lib/Thelia/Core/EventListener/ViewListener.php
	core/lib/Thelia/Core/Template/SmartyParser.php
	templates/smarty-sample/index.html
This commit is contained in:
franck
2013-06-19 11:20:41 +02:00
19 changed files with 9846 additions and 97 deletions

View File

@@ -50,6 +50,10 @@
</call>
</service>
<service id="smarty.plugin.assetic" class="Thelia\Core\Template\Smarty\Plugins\Assetic" >
<tag name="smarty.register_plugin"/>
</service>
<service id="http_kernel" class="Thelia\Core\TheliaHttpKernel">
<argument type="service" id="event_dispatcher" />
<argument type="service" id="service_container" />

View File

@@ -28,6 +28,7 @@ use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Scope;
use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;
use Thelia\Core\DependencyInjection\Compiler\RegisterSmartyPluginPass;
/**
* First Bundle use in Thelia
@@ -56,5 +57,6 @@ class TheliaBundle extends Bundle
$container->addScope(new Scope('request'));
$container->addCompilerPass(new RegisterListenersPass());
$container->addCompilerPass(new RegisterSmartyPluginPass());
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* Created by JetBrains PhpStorm.
* User: manu
* Date: 18/06/13
* Time: 21:55
* To change this template use File | Settings | File Templates.
*/
namespace Thelia\Core\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
class RegisterSmartyPluginPass implements CompilerPassInterface {
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param ContainerBuilder $container
*
* @api
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition("thelia.parser")) {
return;
}
$smarty = $container->getDefinition("thelia.parser");
foreach ($container->findTaggedServiceIds("smarty.register_plugin") as $id => $plugin) {
$smarty->addMethodCall("addPlugins", array(new Reference($id)));
/*$register_plugin = $container->get($id);
$reflectionObject = new \ReflectionObject($register_plugin);
$interface = "Thelia\Core\Template\Smarty\SmartyPluginInterface";
if (!$reflectionObject->implementsInterface($interface)) {
throw new \RuntimeException(sprintf("%s class must implement %s interface",$reflectionObject->getName(), $interface));
}
$plugins = $register_plugin->registerPlugins();
if(!is_array($plugins)) {
$plugins = array($plugins);
}
foreach($plugins as $plugin) {
$smarty->addMethodCall("registerPlugin", array(
$plugin->type,
$plugin->name,
array(
$plugin->class,
$plugin->method
)
));
}*/
}
}
}

View File

@@ -67,7 +67,9 @@ class ViewListener implements EventSubscriberInterface
*/
public function onKernelView(GetResponseForControllerResultEvent $event)
{
$parser = $this->container->get('thelia.parser');
try {
$content = $parser->getContent();

View File

@@ -34,6 +34,13 @@ use Assetic\Cache\FilesystemCache;
class AsseticManager {
protected $options;
public function __construct($_options = array()) {
$this->options = $_options;
}
/**
* Generates assets from $asset_path in $output_path, using $filters.
*

View File

@@ -0,0 +1,26 @@
<?php
/**
* Created by JetBrains PhpStorm.
* User: manu
* Date: 18/06/13
* Time: 22:41
* To change this template use File | Settings | File Templates.
*/
namespace Thelia\Core\Template\Smarty;
class RegisterSmartyPlugin {
public $type;
public $name;
public $class;
public $method;
public function __construct($type, $name, $class, $method)
{
$this->type = $type;
$this->name = $name;
$this->class = $class;
$this->method = $method;
}
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* Created by JetBrains PhpStorm.
* User: manu
* Date: 18/06/13
* Time: 22:38
* To change this template use File | Settings | File Templates.
*/
namespace Thelia\Core\Template\Smarty;
interface SmartyPluginInterface {
/**
* @return mixed
*/
public function registerPlugins();
}

View File

@@ -8,8 +8,8 @@ use \Smarty;
use Thelia\Core\Template\ParserInterface;
use Thelia\Core\Template\Loop\Category;
use Thelia\Tpex\Element\Loop\BaseLoop;
use Thelia\Core\Template\Assets\SmartyAssetsManager;
use Thelia\Core\Template\Smarty\SmartyPluginInterface;
/**
*
@@ -17,6 +17,8 @@ use Thelia\Core\Template\Assets\SmartyAssetsManager;
*/
class SmartyParser extends Smarty implements ParserInterface {
public $plugins = array();
protected $container;
protected $template = "smarty-sample";
@@ -67,11 +69,6 @@ class SmartyParser extends Smarty implements ParserInterface {
// Register Thelia modules inclusion function 'thelia_module'
$this->registerPlugin('function', 'thelia_module', array($this, 'theliaModule'));
// Register asset management block plugins
$this->registerPlugin('block', 'stylesheets', array($this, 'theliaBlockStylesheets'));
$this->registerPlugin('block', 'javascripts', array($this, 'theliaBlockJavascripts'));
$this->registerPlugin('block', 'images' , array($this, 'theliaBlockImages'));
}
/**
@@ -205,22 +202,6 @@ class SmartyParser extends Smarty implements ParserInterface {
return "";
}
public function theliaBlockJavascripts($params, $content, \Smarty_Internal_Template $template, &$repeat)
{
return $this->getAssetManager()->processSmartyPluginCall('js', $params, $content, $template, $repeat);
}
public function theliaBlockImages($params, $content, \Smarty_Internal_Template $template, &$repeat)
{
return $this->getAssetManager()->processSmartyPluginCall(SmartyAssetsManager::ASSET_TYPE_AUTO, $params, $content, $template, $repeat);
}
public function theliaBlockStylesheets($params, $content, \Smarty_Internal_Template $template, &$repeat)
{
return $this->getAssetManager()->processSmartyPluginCall('css', $params, $content, $template, $repeat);
}
/**
*
* This method must return a Symfony\Component\HttpFoudation\Response instance or the content of the response
@@ -228,6 +209,8 @@ class SmartyParser extends Smarty implements ParserInterface {
*/
public function getContent()
{
$this->registerPlugins();
return $this->fetch($this->getTemplateFilePath());
}
@@ -316,6 +299,34 @@ class SmartyParser extends Smarty implements ParserInterface {
}
}
public function addPlugins(SmartyPluginInterface $plugin)
{
$this->plugins[] = $plugin;
}
public function registerPlugins()
{
foreach ($this->plugins as $register_plugin) {
$plugins = $register_plugin->registerPlugins();
if(!is_array($plugins)) {
$plugins = array($plugins);
}
foreach ($plugins as $plugin) {
$this->registerPlugin(
$plugin->type,
$plugin->name,
array(
$plugin->class,
$plugin->method
)
);
}
}
}
/**
* Returns the value of a loop argument.
*
@@ -323,7 +334,7 @@ class SmartyParser extends Smarty implements ParserInterface {
* @param unknown $smartyParam
* @throws \InvalidArgumentException
*/
protected function getLoopArgument(BaseLoop $loop, $smartyParam)
protected function getLoopArgument($loop, $smartyParam)
{
$defaultItemsParams = array('required' => true);

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,13 @@
{* Include required JS files *}
{javascripts file='../assets/js/jquery.min.js'}
<link rel="stylesheet" href="{$asset_url}" target="screen">
{/javascripts}
{javascripts file='../assets/bootstrap/js/bootstrap.min.js'}
<link rel="stylesheet" href="{$asset_url}" target="screen">
{/javascripts}
{* TODO allow modules to include JS here *}
</body>
</html>

View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="{$lang}">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{stylesheets file='../assets/css/*' filters='less,cssrewrite'}
<link rel="stylesheet" href="{$asset_url}">
{/stylesheets}
{stylesheets file='../assets/bootstrap/css/bootstrap.min.css' filters='cssrewrite'}
<link rel="stylesheet" href="{$asset_url}">
{/stylesheets}
{stylesheets file='../assets/bootstrap/css/bootstrap-responsive.min.css' filters='cssrewrite'}
<link rel="stylesheet" href="{$asset_url}">
{/stylesheets}
{* TODO allow modules to include CSS here *}
</head>
<body>