mustache.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Fuel
  4. *
  5. * Fuel is a fast, lightweight, community driven PHP5 framework.
  6. *
  7. * @package Fuel
  8. * @version 1.5
  9. * @author Fuel Development Team
  10. * @license MIT License
  11. * @copyright 2010 - 2013 Fuel Development Team
  12. * @link http://fuelphp.com
  13. */
  14. namespace Parser;
  15. use Mustache;
  16. class View_Mustache extends \View
  17. {
  18. protected static $_parser;
  19. protected function process_file($file_override = false)
  20. {
  21. $file = $file_override ?: $this->file_name;
  22. $data = $this->get_data();
  23. try
  24. {
  25. return static::parser()->render(file_get_contents($file), $data);
  26. }
  27. catch (\Exception $e)
  28. {
  29. // Delete the output buffer & re-throw the exception
  30. ob_end_clean();
  31. throw $e;
  32. }
  33. }
  34. public $extension = 'mustache';
  35. /**
  36. * Returns the Parser lib object
  37. *
  38. * @return Mustache
  39. */
  40. public static function parser()
  41. {
  42. if ( ! empty(static::$_parser))
  43. {
  44. return static::$_parser;
  45. }
  46. $options = array(
  47. 'delimiters' => array_values(\Config::get('parser.View_Mustache.delimiters', array('{{','}}'))),
  48. 'charset' => \Config::get('parser.View_Mustache.environment.charset', 'UTF-8'),
  49. 'pragmas' => \Config::get('parser.View_Mustache.environment.pragmas', array()),
  50. );
  51. static::$_parser = new Mustache(null, null, null, $options);
  52. return static::$_parser;
  53. }
  54. }
  55. // end of file mustache.php