-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransTokenParser.php
50 lines (40 loc) · 1.02 KB
/
TransTokenParser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Parisek\Twig;
use Twig\TokenParser\AbstractTokenParser;
class TransTokenParser extends AbstractTokenParser {
/**
* {@inheritdoc}
*/
public function parse(\Twig\Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
$parameters = null;
// parse optional data passed after `with` keyword
if ($stream->nextIf(\Twig_Token::NAME_TYPE, 'with')) {
$parameters = $this->parser->getExpressionParser()->parseExpression();
}
$stream->expect(\Twig\Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(array($this, 'decideTransEnd'), true);
$stream->expect(\Twig\Token::BLOCK_END_TYPE);
// just return content
return $body;
}
/**
* Decide if current token marks end of Markdown block.
*
* @param \Twig\Token $token
* @return bool
*/
public function decideTransEnd(\Twig\Token $token)
{
return $token->test('endtrans');
}
/**
* {@inheritdoc}
*/
public function getTag()
{
return 'trans';
}
}