1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-25 16:00:22 +01:00

Continue upgrading Twig

This commit is contained in:
Michael Foster 2013-08-01 15:55:28 -04:00
parent 538e88b7bd
commit 48c5fb4615
4 changed files with 34 additions and 31 deletions

View File

@ -28,7 +28,7 @@ class Twig_Extensions_Extension_I18n extends Twig_Extension
public function getFilters()
{
return array(
'trans' => new Twig_Filter_Function('gettext'),
new Twig_SimpleFilter('trans', 'gettext'),
);
}

View File

@ -9,23 +9,23 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
*/
public function getFilters()
{
return Array(
'filesize' => new Twig_Filter_Function('format_bytes'),
'truncate' => new Twig_Filter_Function('twig_truncate_filter'),
'truncate_body' => new Twig_Filter_Function('truncate'),
'extension' => new Twig_Filter_Function('twig_extension_filter'),
'sprintf' => new Twig_Filter_Function('sprintf'),
'capcode' => new Twig_Filter_Function('capcode'),
'hasPermission' => new Twig_Filter_Function('twig_hasPermission_filter'),
'date' => new Twig_Filter_Function('twig_date_filter'),
'poster_id' => new Twig_Filter_Function('poster_id'),
'remove_whitespace' => new Twig_Filter_Function('twig_remove_whitespace_filter'),
'count' => new Twig_Filter_Function('count'),
'ago' => new Twig_Filter_Function('ago'),
'until' => new Twig_Filter_Function('until'),
'push' => new Twig_Filter_Function('twig_push_filter'),
'bidi_cleanup' => new Twig_Filter_Function('bidi_cleanup'),
'addslashes' => new Twig_Filter_Function('addslashes')
return array(
new Twig_SimpleFilter('filesize', 'format_bytes'),
new Twig_SimpleFilter('truncate', 'twig_truncate_filter'),
new Twig_SimpleFilter('truncate_body', 'truncate'),
new Twig_SimpleFilter('extension', 'twig_extension_filter'),
new Twig_SimpleFilter('sprintf', 'sprintf'),
new Twig_SimpleFilter('capcode', 'capcode'),
new Twig_SimpleFilter('hasPermission', 'twig_hasPermission_filter'),
new Twig_SimpleFilter('date', 'twig_date_filter'),
new Twig_SimpleFilter('poster_id', 'poster_id'),
new Twig_SimpleFilter('remove_whitespace', 'twig_remove_whitespace_filter'),
new Twig_SimpleFilter('count', 'count'),
new Twig_SimpleFilter('ago', 'ago'),
new Twig_SimpleFilter('until', 'until'),
new Twig_SimpleFilter('push', 'twig_push_filter'),
new Twig_SimpleFilter('bidi_cleanup', 'bidi_cleanup'),
new Twig_SimpleFilter('addslashes', 'addslashes')
);
}
@ -36,12 +36,12 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
*/
public function getFunctions()
{
return Array(
'time' => new Twig_Filter_Function('time'),
'floor' => new Twig_Filter_Function('floor'),
'timezone' => new Twig_Filter_Function('twig_timezone_function'),
'hiddenInputs' => new Twig_Filter_Function('hiddenInputs'),
'hiddenInputsHash' => new Twig_Filter_Function('hiddenInputsHash'),
return array(
new Twig_SimpleFunction('time', 'time'),
new Twig_SimpleFunction('floor', 'floor'),
new Twig_SimpleFunction('timezone', 'twig_timezone_function'),
new Twig_SimpleFunction('hiddenInputs', 'hiddenInputs'),
new Twig_SimpleFunction('hiddenInputsHash', 'hiddenInputsHash'),
);
}

View File

@ -94,22 +94,25 @@ class Twig_Extensions_Node_Trans extends Twig_Node
;
}
$compiler->raw(');');
$compiler->raw(");\n");
}
}
protected function compileString(Twig_NodeInterface $body)
{
if ($body instanceof Twig_Node_Expression_Name || $body instanceof Twig_Node_Expression_Constant) {
if ($body instanceof Twig_Node_Expression_Name || $body instanceof Twig_Node_Expression_Constant || $body instanceof Twig_Node_Expression_TempName) {
return array($body, array());
}
$vars = array();
if (count($body)) {
$msg = '';
foreach ($body as $node) {
if (get_class($node) === 'Twig_Node' && $node->getNode(0) instanceof Twig_Node_SetTemp) {
$node = $node->getNode(1);
}
if ($node instanceof Twig_Node_Print) {
$n = $node->getNode('expr');
while ($n instanceof Twig_Node_Expression_Filter) {
@ -127,4 +130,4 @@ class Twig_Extensions_Node_Trans extends Twig_Node
return array(new Twig_Node(array(new Twig_Node_Expression_Constant(trim($msg), $body->getLine()))), $vars);
}
}
}

View File

@ -43,12 +43,12 @@ class Twig_Extensions_TokenParser_Trans extends Twig_TokenParser
return new Twig_Extensions_Node_Trans($body, $plural, $count, $lineno, $this->getTag());
}
public function decideForFork($token)
public function decideForFork(Twig_Token $token)
{
return $token->test(array('plural', 'endtrans'));
}
public function decideForEnd($token)
public function decideForEnd(Twig_Token $token)
{
return $token->test('endtrans');
}
@ -77,4 +77,4 @@ class Twig_Extensions_TokenParser_Trans extends Twig_TokenParser
throw new Twig_Error_Syntax(sprintf('The text to be translated with "trans" can only contain references to simple variables'), $lineno);
}
}
}
}