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:
@@ -50,6 +50,10 @@
|
|||||||
</call>
|
</call>
|
||||||
</service>
|
</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">
|
<service id="http_kernel" class="Thelia\Core\TheliaHttpKernel">
|
||||||
<argument type="service" id="event_dispatcher" />
|
<argument type="service" id="event_dispatcher" />
|
||||||
<argument type="service" id="service_container" />
|
<argument type="service" id="service_container" />
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ use Symfony\Component\DependencyInjection\Reference;
|
|||||||
use Symfony\Component\DependencyInjection\Scope;
|
use Symfony\Component\DependencyInjection\Scope;
|
||||||
|
|
||||||
use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;
|
use Thelia\Core\DependencyInjection\Compiler\RegisterListenersPass;
|
||||||
|
use Thelia\Core\DependencyInjection\Compiler\RegisterSmartyPluginPass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First Bundle use in Thelia
|
* First Bundle use in Thelia
|
||||||
@@ -56,5 +57,6 @@ class TheliaBundle extends Bundle
|
|||||||
$container->addScope(new Scope('request'));
|
$container->addScope(new Scope('request'));
|
||||||
|
|
||||||
$container->addCompilerPass(new RegisterListenersPass());
|
$container->addCompilerPass(new RegisterListenersPass());
|
||||||
|
$container->addCompilerPass(new RegisterSmartyPluginPass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,7 +67,9 @@ class ViewListener implements EventSubscriberInterface
|
|||||||
*/
|
*/
|
||||||
public function onKernelView(GetResponseForControllerResultEvent $event)
|
public function onKernelView(GetResponseForControllerResultEvent $event)
|
||||||
{
|
{
|
||||||
|
|
||||||
$parser = $this->container->get('thelia.parser');
|
$parser = $this->container->get('thelia.parser');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$content = $parser->getContent();
|
$content = $parser->getContent();
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,13 @@ use Assetic\Cache\FilesystemCache;
|
|||||||
|
|
||||||
class AsseticManager {
|
class AsseticManager {
|
||||||
|
|
||||||
|
protected $options;
|
||||||
|
|
||||||
|
public function __construct($_options = array()) {
|
||||||
|
|
||||||
|
$this->options = $_options;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates assets from $asset_path in $output_path, using $filters.
|
* Generates assets from $asset_path in $output_path, using $filters.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -8,8 +8,8 @@ use \Smarty;
|
|||||||
|
|
||||||
use Thelia\Core\Template\ParserInterface;
|
use Thelia\Core\Template\ParserInterface;
|
||||||
use Thelia\Core\Template\Loop\Category;
|
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 {
|
class SmartyParser extends Smarty implements ParserInterface {
|
||||||
|
|
||||||
|
public $plugins = array();
|
||||||
|
|
||||||
protected $container;
|
protected $container;
|
||||||
|
|
||||||
protected $template = "smarty-sample";
|
protected $template = "smarty-sample";
|
||||||
@@ -67,11 +69,6 @@ class SmartyParser extends Smarty implements ParserInterface {
|
|||||||
|
|
||||||
// Register Thelia modules inclusion function 'thelia_module'
|
// Register Thelia modules inclusion function 'thelia_module'
|
||||||
$this->registerPlugin('function', 'thelia_module', array($this, 'theliaModule'));
|
$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 "";
|
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
|
* 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()
|
public function getContent()
|
||||||
{
|
{
|
||||||
|
$this->registerPlugins();
|
||||||
|
|
||||||
return $this->fetch($this->getTemplateFilePath());
|
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.
|
* Returns the value of a loop argument.
|
||||||
*
|
*
|
||||||
@@ -323,7 +334,7 @@ class SmartyParser extends Smarty implements ParserInterface {
|
|||||||
* @param unknown $smartyParam
|
* @param unknown $smartyParam
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
protected function getLoopArgument(BaseLoop $loop, $smartyParam)
|
protected function getLoopArgument($loop, $smartyParam)
|
||||||
{
|
{
|
||||||
$defaultItemsParams = array('required' => true);
|
$defaultItemsParams = array('required' => true);
|
||||||
|
|
||||||
|
|||||||
1109
templates/smarty-sample/assets/bootstrap/css/bootstrap-responsive.css
vendored
Normal file
1109
templates/smarty-sample/assets/bootstrap/css/bootstrap-responsive.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
9
templates/smarty-sample/assets/bootstrap/css/bootstrap-responsive.min.css
vendored
Normal file
9
templates/smarty-sample/assets/bootstrap/css/bootstrap-responsive.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
6167
templates/smarty-sample/assets/bootstrap/css/bootstrap.css
vendored
Normal file
6167
templates/smarty-sample/assets/bootstrap/css/bootstrap.css
vendored
Normal file
File diff suppressed because it is too large
Load Diff
9
templates/smarty-sample/assets/bootstrap/css/bootstrap.min.css
vendored
Normal file
9
templates/smarty-sample/assets/bootstrap/css/bootstrap.min.css
vendored
Normal file
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 |
2280
templates/smarty-sample/assets/bootstrap/js/bootstrap.js
vendored
Normal file
2280
templates/smarty-sample/assets/bootstrap/js/bootstrap.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
6
templates/smarty-sample/assets/bootstrap/js/bootstrap.min.js
vendored
Normal file
6
templates/smarty-sample/assets/bootstrap/js/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
13
templates/smarty-sample/includes/footer.inc.tpl
Normal file
13
templates/smarty-sample/includes/footer.inc.tpl
Normal 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>
|
||||||
21
templates/smarty-sample/includes/header.inc.tpl
Normal file
21
templates/smarty-sample/includes/header.inc.tpl
Normal 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>
|
||||||
0
templates/smarty-sample/includes/menu.tpl
Normal file
0
templates/smarty-sample/includes/menu.tpl
Normal file
Reference in New Issue
Block a user