From a323dd0e9365f65e2f938127d5bab8f69b73a4c8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 19 Nov 2010 10:14:45 +0100 Subject: [PATCH] [TwigBundle] added filters from Code helpers --- .../Extension/TemplatingExtension.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php index 36e8f626c964..e0d295f11c19 100644 --- a/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php +++ b/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php @@ -50,6 +50,14 @@ public function getFilters() { return array( 'yaml' => new \Twig_Filter_Method($this, 'yaml'), + 'dump' => new \Twig_Filter_Method($this, 'dump'), + 'abbr_class' => new \Twig_Filter_Method($this, 'abbrClass', array('is_safe' => array('html'))), + 'abbr_method' => new \Twig_Filter_Method($this, 'abbrMethod', array('is_safe' => array('html'))), + 'format_args' => new \Twig_Filter_Method($this, 'formatArgs', array('is_safe' => array('html'))), + 'format_args_as_text' => new \Twig_Filter_Method($this, 'formatArgsAsText', array('is_safe' => array('html'))), + 'file_excerpt' => new \Twig_Filter_Method($this, 'fileExcerpt', array('is_safe' => array('html'))), + 'format_file' => new \Twig_Filter_Method($this, 'formatFile', array('is_safe' => array('html'))), + 'format_file_from_text' => new \Twig_Filter_Method($this, 'formatFileFromText', array('is_safe' => array('html'))), ); } @@ -104,6 +112,54 @@ public function yaml($input, $inline = 0) return $dumper->dump($input, $inline); } + public function abbrClass($class) + { + return $this->templating->get('code')->abbrClass($class); + } + + public function abbrMethod($method) + { + return $this->templating->get('code')->abbrMethod($method); + } + + public function formatArgs($args) + { + return $this->templating->get('code')->formatArgs($args); + } + + public function formatArgsAsText($args) + { + return $this->templating->get('code')->formatArgsAsText($args); + } + + public function fileExcerpt($file, $line) + { + return $this->templating->get('code')->fileExcerpt($file, $line); + } + + public function formatFile($file, $line) + { + return $this->templating->get('code')->formatFile($file, $line); + } + + public function formatFileFromText($text) + { + return $this->templating->get('code')->formatFileFromText($text); + } + + public function dump($value) + { + if (is_resource($value)) { + return '%Resource%'; + } + + if (is_array($value) || is_object($value)) { + return '%'.gettype($value).'% '.$this->yaml($value); + } + + return $value; + } + /** * Returns the name of the extension. *