Mercurial > hg > dml-open-vis
diff src/Kachkaev/JstmplBundle/Twig/JstmplExtension.php @ 0:493bcb69166c
added public content
author | Daniel Wolff |
---|---|
date | Tue, 09 Feb 2016 20:54:02 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Kachkaev/JstmplBundle/Twig/JstmplExtension.php Tue Feb 09 20:54:02 2016 +0100 @@ -0,0 +1,58 @@ +<?php +namespace Kachkaev\JstmplBundle\Twig; + +use Symfony\Component\DependencyInjection\ContainerInterface; +use Twig_Extension; +use Twig_Function_Method; + +class JstmplExtension extends Twig_Extension +{ + protected $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + /** + * @inheritdoc + */ + public function getFunctions() + { + $functions = array(); + + $mappings = array( + 'tmpl_path' => 'getTmplPath', + ); + + foreach($mappings as $twigFunction => $method) { + $functions[$twigFunction] = new Twig_Function_Method($this, $method); + } + + $safeMappings = array( + ); + + foreach($safeMappings as $twigFunction => $method) { + $functions[$twigFunction] = new Twig_Function_Method($this, $method, array ('is_safe' => array('html'))); + } + + return $functions; + } + + public function getTokenParsers() + { + return array( + new JstmplTokenParser() + ); + } + + public function getName() + { + return 'TmplExtension'; + } + + public function getTmplPath($name) + { + return "/js/tmpl/$name.js"; + } +}