-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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'; | ||
} | ||
} |