Adds is_rtl() function to Twig

This commit is contained in:
Vlad
2017-09-06 20:55:44 -04:00
parent e012bd6cbe
commit 6584250d1a
3 changed files with 34 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
<?php
namespace MailPoet\Twig;
use MailPoet\Config\ServicesChecker;
if(!defined('ABSPATH')) exit;
@@ -86,6 +88,11 @@ class Functions extends \Twig_Extension {
'do_action',
'do_action',
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();
return $checker->isPremiumKeyValid(false);
}
function isRtl() {
return is_rtl();
}
}

View 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();
}
}

View File

@@ -35,7 +35,7 @@ jQuery('.toplevel_page_mailpoet-newsletters.menu-top-last')
<%= do_action('mailpoet_styles_admin_after') %>
<!-- rtl specific stylesheet -->
<% if is_rtl %>
<% if is_rtl() %>
<%= stylesheet('rtl.css') %>
<% endif %>