Adds is_rtl() function to Twig
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace MailPoet\Twig;
|
namespace MailPoet\Twig;
|
||||||
|
|
||||||
use MailPoet\Config\ServicesChecker;
|
use MailPoet\Config\ServicesChecker;
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
@@ -86,6 +88,11 @@ class Functions extends \Twig_Extension {
|
|||||||
'do_action',
|
'do_action',
|
||||||
'do_action',
|
'do_action',
|
||||||
array('is_safe' => array('all'))
|
array('is_safe' => array('all'))
|
||||||
|
),
|
||||||
|
new \Twig_SimpleFunction(
|
||||||
|
'is_rtl',
|
||||||
|
array($this, 'isRtl'),
|
||||||
|
array('is_safe' => array('all'))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -162,4 +169,8 @@ class Functions extends \Twig_Extension {
|
|||||||
$checker = new ServicesChecker();
|
$checker = new ServicesChecker();
|
||||||
return $checker->isPremiumKeyValid(false);
|
return $checker->isPremiumKeyValid(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isRtl() {
|
||||||
|
return is_rtl();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
22
tests/unit/Twig/FunctionsTest.php
Normal file
22
tests/unit/Twig/FunctionsTest.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Test\Twig;
|
||||||
|
|
||||||
|
use AspectMock\Test as Mock;
|
||||||
|
use MailPoet\Twig\Functions;
|
||||||
|
|
||||||
|
class FunctionsTest extends \MailPoetTest {
|
||||||
|
function testItExecutesIsRtlFunction() {
|
||||||
|
$template = array('template' => '{% if is_rtl() %}rtl{% endif %}');
|
||||||
|
$twig = new \Twig_Environment(new \Twig_Loader_Array($template));
|
||||||
|
$twig->addExtension(new Functions());
|
||||||
|
|
||||||
|
Mock::func('MailPoet\Twig', 'is_rtl', true);
|
||||||
|
$result = $twig->render('template');
|
||||||
|
expect($result)->equals('rtl');
|
||||||
|
|
||||||
|
Mock::func('MailPoet\Twig', 'is_rtl', false);
|
||||||
|
$result = $twig->render('template');
|
||||||
|
expect($result)->isEmpty();
|
||||||
|
}
|
||||||
|
}
|
@@ -35,7 +35,7 @@ jQuery('.toplevel_page_mailpoet-newsletters.menu-top-last')
|
|||||||
<%= do_action('mailpoet_styles_admin_after') %>
|
<%= do_action('mailpoet_styles_admin_after') %>
|
||||||
|
|
||||||
<!-- rtl specific stylesheet -->
|
<!-- rtl specific stylesheet -->
|
||||||
<% if is_rtl %>
|
<% if is_rtl() %>
|
||||||
<%= stylesheet('rtl.css') %>
|
<%= stylesheet('rtl.css') %>
|
||||||
<% endif %>
|
<% endif %>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user