Skip to content

Commit

Permalink
[TwigBundle] added filters from Code helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Nov 19, 2010
1 parent c881329 commit a323dd0
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php
Expand Up @@ -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'))),
);
}

Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit a323dd0

Please sign in to comment.