Guest User

Untitled

a guest
Aug 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2.  
  3. /**
  4. * Loads a default set of filters and extensions for
  5. * Twig based on Kohana helpers
  6. *
  7. * @package kohana-twig
  8. * @author Jonathan Geiger
  9. */
  10. class Kohana_Twig_Extensions extends Twig_Extension
  11. {
  12. /**
  13. * Returns the added token parsers
  14. *
  15. * @return array
  16. * @author Jonathan Geiger
  17. */
  18. public function getTokenParsers()
  19. {
  20. return array(
  21. new Kohana_Twig_HTML_TokenParser(),
  22. new Kohana_Twig_Form_TokenParser(),
  23. new Kohana_Twig_URL_TokenParser(),
  24. new Kohana_Twig_Cache_TokenParser(),
  25. new Kohana_Twig_Trans_TokenParser(),
  26. new Kohana_Twig_Request_TokenParser(),
  27. );
  28. }
  29.  
  30. /**
  31. * Returns the added filters
  32. *
  33. * @return array
  34. * @author Jonathan Geiger
  35. */
  36. public function getFilters()
  37. {
  38. return array(
  39. // Translation
  40. 'translate' => new Twig_Filter_Function('__'),
  41. 'trans' => new Twig_Filter_Function('__'),
  42.  
  43. // Date and time
  44. 'timestamp' => new Twig_Filter_Function('strtotime'),
  45. 'timesince' => new Twig_Filter_Function('Kohana_Twig_Filters::timesince'),
  46. 'fuzzy_timesince' => new Twig_Filter_Function('date::fuzzy_span'),
  47.  
  48. // Strings
  49. 'plural' => new Twig_Filter_Function('inflector::plural'),
  50. 'singular' => new Twig_Filter_Function('inflector::singular'),
  51. 'humanize' => new Twig_Filter_Function('inflector::humanize'),
  52.  
  53. // HTML
  54. 'obfuscate' => new Twig_Filter_Function('html::obfuscate'),
  55.  
  56. // Numbers
  57. 'ordinal' => new Twig_Filter_Function('Kohana_Twig_Filters::ordinal'),
  58. 'num_format' => new Twig_Filter_Function('num::format'),
  59.  
  60. // Text
  61. 'limit_words' => new Twig_Filter_Function('text::limit_words'),
  62. 'limit_chars' => new Twig_Filter_Function('text::limit_chars'),
  63. 'auto_link' => new Twig_Filter_Function('text::auto_link'),
  64. 'auto_p' => new Twig_Filter_Function('text::auto_p'),
  65. 'bytes' => new Twig_Filter_Function('text::bytes'),
  66.  
  67. 'urltitle' => new Twig_Filter_Function('url::title'),
  68. );
  69. }
  70.  
  71. /**
  72. * @return string
  73. * @author Jonathan Geiger
  74. */
  75. public function getName()
  76. {
  77. return 'kohana_twig';
  78. }
  79. }
Add Comment
Please, Sign In to add comment