Skip to content

Commit

Permalink
Merge pull request #393 from dkisselev/simple-function
Browse files Browse the repository at this point in the history
Switch twig extensions to use SimpleFunction/SimpleFilter
  • Loading branch information
Florian Eckerstorfer committed Nov 4, 2015
2 parents e3026b2 + 3f3a267 commit 55ae969
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 47 deletions.
8 changes: 4 additions & 4 deletions Twig/BootstrapBadgeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Braincrafted\Bundle\BootstrapBundle\Twig;

use Twig_Extension;
use Twig_Function_Method;
use Twig_SimpleFunction;

/**
* BootstrapLabelExtension
Expand All @@ -29,9 +29,9 @@ class BootstrapBadgeExtension extends Twig_Extension
public function getFunctions()
{
return array(
'badge' => new Twig_Function_Method(
$this,
'badgeFunction',
new Twig_SimpleFunction(
'badge',
array($this, 'badgeFunction'),
array('pre_escape' => 'html', 'is_safe' => array('html'))
)
);
Expand Down
9 changes: 6 additions & 3 deletions Twig/BootstrapButtonExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

namespace Braincrafted\Bundle\BootstrapBundle\Twig;

class BootstrapButtonExtension extends \Twig_Extension
use Twig_Extension;
use Twig_SimpleFunction;

class BootstrapButtonExtension extends Twig_Extension
{
/**
* @var BootstrapIconExtension
Expand Down Expand Up @@ -35,8 +38,8 @@ public function __construct(BootstrapIconExtension $iconExtension)
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('button', array($this, 'buttonFunction'), array('is_safe' => array('html'))),
new \Twig_SimpleFunction('button_link', array($this, 'buttonLinkFunction'), array('is_safe' => array('html'))),
new Twig_SimpleFunction('button', array($this, 'buttonFunction'), array('is_safe' => array('html'))),
new Twig_SimpleFunction('button_link', array($this, 'buttonLinkFunction'), array('is_safe' => array('html'))),
);
}

Expand Down
57 changes: 32 additions & 25 deletions Twig/BootstrapFormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

namespace Braincrafted\Bundle\BootstrapBundle\Twig;

use Twig_Extension;
use Twig_SimpleFunction;


/**
* BootstrapFormExtension
*
Expand All @@ -16,7 +20,7 @@
* @license http://opensource.org/licenses/MIT The MIT License
* @link http://bootstrap.braincrafted.com Bootstrap for Symfony2
*/
class BootstrapFormExtension extends \Twig_Extension
class BootstrapFormExtension extends Twig_Extension
{
/** @var string */
private $style;
Expand All @@ -42,33 +46,36 @@ class BootstrapFormExtension extends \Twig_Extension
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('bootstrap_set_style', array($this, 'setStyle')),
new \Twig_SimpleFunction('bootstrap_get_style', array($this, 'getStyle')),
new \Twig_SimpleFunction('bootstrap_set_col_size', array($this, 'setColSize')),
new \Twig_SimpleFunction('bootstrap_get_col_size', array($this, 'getColSize')),
new \Twig_SimpleFunction('bootstrap_set_widget_col', array($this, 'setWidgetCol')),
new \Twig_SimpleFunction('bootstrap_get_widget_col', array($this, 'getWidgetCol')),
new \Twig_SimpleFunction('bootstrap_set_label_col', array($this, 'setLabelCol')),
new \Twig_SimpleFunction('bootstrap_get_label_col', array($this, 'getLabelCol')),
new \Twig_SimpleFunction('bootstrap_set_simple_col', array($this, 'setSimpleCol')),
new \Twig_SimpleFunction('bootstrap_get_simple_col', array($this, 'getSimpleCol')),
new \Twig_SimpleFunction('bootstrap_backup_form_settings', array($this, 'backupFormSettings')),
new \Twig_SimpleFunction('bootstrap_restore_form_settings', array($this, 'restoreFormSettings')),
'checkbox_row' => new \Twig_Function_Node(
'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode',
array('is_safe' => array('html'))
new Twig_SimpleFunction('bootstrap_set_style', array($this, 'setStyle')),
new Twig_SimpleFunction('bootstrap_get_style', array($this, 'getStyle')),
new Twig_SimpleFunction('bootstrap_set_col_size', array($this, 'setColSize')),
new Twig_SimpleFunction('bootstrap_get_col_size', array($this, 'getColSize')),
new Twig_SimpleFunction('bootstrap_set_widget_col', array($this, 'setWidgetCol')),
new Twig_SimpleFunction('bootstrap_get_widget_col', array($this, 'getWidgetCol')),
new Twig_SimpleFunction('bootstrap_set_label_col', array($this, 'setLabelCol')),
new Twig_SimpleFunction('bootstrap_get_label_col', array($this, 'getLabelCol')),
new Twig_SimpleFunction('bootstrap_set_simple_col', array($this, 'setSimpleCol')),
new Twig_SimpleFunction('bootstrap_get_simple_col', array($this, 'getSimpleCol')),
new Twig_SimpleFunction('bootstrap_backup_form_settings', array($this, 'backupFormSettings')),
new Twig_SimpleFunction('bootstrap_restore_form_settings', array($this, 'restoreFormSettings')),
new Twig_SimpleFunction(
'checkbox_row',
null,
array('is_safe' => array('html'), 'node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode')
),
'radio_row' => new \Twig_Function_Node(
'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode',
array('is_safe' => array('html'))
new Twig_SimpleFunction(
'radio_row',
null,
array('is_safe' => array('html'), 'node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode')
),
'global_form_errors' => new \Twig_Function_Node(
'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode',
array('is_safe' => array('html'))
new Twig_SimpleFunction(
'global_form_errors',
null,
array('is_safe' => array('html'), 'node_class' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode')
),
'form_control_static' => new \Twig_Function_Method(
$this,
'formControlStaticFunction',
new Twig_SimpleFunction(
'form_control_static',
array($this, 'formControlStaticFunction'),
array('is_safe' => array('html'))
)
);
Expand Down
16 changes: 8 additions & 8 deletions Twig/BootstrapIconExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
namespace Braincrafted\Bundle\BootstrapBundle\Twig;

use Twig_Extension;
use Twig_Filter_Method;
use Twig_Function_Method;
use Twig_SimpleFilter;
use Twig_SimpleFunction;

/**
* BootstrapIconExtension
Expand Down Expand Up @@ -48,9 +48,9 @@ public function __construct($iconPrefix, $iconTag = 'span')
public function getFilters()
{
return array(
'parse_icons' => new Twig_Filter_Method(
$this,
'parseIconsFilter',
new Twig_SimpleFilter(
'parse_icons',
array($this, 'parseIconsFilter'),
array('pre_escape' => 'html', 'is_safe' => array('html'))
)
);
Expand All @@ -62,9 +62,9 @@ public function getFilters()
public function getFunctions()
{
return array(
'icon' => new Twig_Function_Method(
$this,
'iconFunction',
new Twig_SimpleFunction(
'icon',
array($this, 'iconFunction'),
array('pre_escape' => 'html', 'is_safe' => array('html'))
)
);
Expand Down
14 changes: 7 additions & 7 deletions Twig/BootstrapLabelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Braincrafted\Bundle\BootstrapBundle\Twig;

use Twig_Extension;
use Twig_Function_Method;
use Twig_SimpleFunction;

/**
* BootstrapLabelExtension
Expand All @@ -31,12 +31,12 @@ public function getFunctions()
$options = array('pre_escape' => 'html', 'is_safe' => array('html'));

return array(
'label' => new Twig_Function_Method($this, 'labelFunction', $options),
'label_primary' => new Twig_Function_Method($this, 'labelPrimaryFunction', $options),
'label_success' => new Twig_Function_Method($this, 'labelSuccessFunction', $options),
'label_info' => new Twig_Function_Method($this, 'labelInfoFunction', $options),
'label_warning' => new Twig_Function_Method($this, 'labelWarningFunction', $options),
'label_danger' => new Twig_Function_Method($this, 'labelDangerFunction', $options)
new Twig_SimpleFunction('label', array($this, 'labelFunction'), $options),
new Twig_SimpleFunction('label_primary', array($this, 'labelPrimaryFunction'), $options),
new Twig_SimpleFunction('label_success', array($this, 'labelSuccessFunction'), $options),
new Twig_SimpleFunction('label_info', array($this, 'labelInfoFunction'), $options),
new Twig_SimpleFunction('label_warning', array($this, 'labelWarningFunction'), $options),
new Twig_SimpleFunction('label_danger', array($this, 'labelDangerFunction'), $options)
);
}

Expand Down

0 comments on commit 55ae969

Please sign in to comment.