| @@ 24-46 (lines=23) @@ | ||
| 21 | use TwigJs\JsCompiler; |
|
| 22 | use TwigJs\TypeCompilerInterface; |
|
| 23 | ||
| 24 | class BlockReferenceCompiler implements TypeCompilerInterface |
|
| 25 | { |
|
| 26 | public function getType() |
|
| 27 | { |
|
| 28 | return 'Twig_Node_BlockReference'; |
|
| 29 | } |
|
| 30 | ||
| 31 | public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) |
|
| 32 | { |
|
| 33 | if (!$node instanceof \Twig_Node_BlockReference) { |
|
| 34 | throw new \RuntimeException( |
|
| 35 | sprintf('$node must be an instanceof of \Twig_Node_BlockReference, but got "%s".', get_class($node)) |
|
| 36 | ); |
|
| 37 | } |
|
| 38 | ||
| 39 | $compiler |
|
| 40 | ->addDebugInfo($node) |
|
| 41 | ->write( |
|
| 42 | sprintf("sb.append(this.renderBlock(%s, context, blocks));\n", json_encode($node->getAttribute('name'))) |
|
| 43 | ) |
|
| 44 | ; |
|
| 45 | } |
|
| 46 | } |
|
| 47 | ||
| @@ 24-47 (lines=24) @@ | ||
| 21 | use TwigJs\JsCompiler; |
|
| 22 | use TwigJs\TypeCompilerInterface; |
|
| 23 | ||
| 24 | class ExtensionReferenceCompiler implements TypeCompilerInterface |
|
| 25 | { |
|
| 26 | public function getType() |
|
| 27 | { |
|
| 28 | return 'Twig_Node_ExtensionReference'; |
|
| 29 | } |
|
| 30 | ||
| 31 | public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) |
|
| 32 | { |
|
| 33 | if (!$node instanceof \Twig_Node_ExtensionReference) { |
|
| 34 | throw new \RuntimeException( |
|
| 35 | sprintf( |
|
| 36 | '$node must be an instanceof of \Twig_Node_ExtensionReference, but got "%s".', |
|
| 37 | get_class($node) |
|
| 38 | ) |
|
| 39 | ); |
|
| 40 | } |
|
| 41 | ||
| 42 | $compiler |
|
| 43 | ->addDebugInfo($node) |
|
| 44 | ->write(sprintf("this.env_.getExtension(%s);\n", json_encode($node->getAttribute('name')))) |
|
| 45 | ; |
|
| 46 | } |
|
| 47 | } |
|
| 48 | ||