haml.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 HamlParser;
  16. class View_Haml extends \View
  17. {
  18. protected static $_parser;
  19. protected static $_cache;
  20. protected function process_file($file_override = false)
  21. {
  22. $file = $file_override ?: $this->file_name;
  23. static::cache_init($file);
  24. $file = static::parser()->parse($file, static::$_cache);
  25. return parent::process_file($file);
  26. }
  27. public $extension = 'haml';
  28. /**
  29. * Returns the Parser lib object
  30. *
  31. * @return HamlParser
  32. */
  33. public static function parser()
  34. {
  35. if ( ! empty(static::$_parser))
  36. {
  37. return static::$_parser;
  38. }
  39. static::$_parser = new HamlParser();
  40. return static::$_parser;
  41. }
  42. // Jade stores cached templates as the filename in plain text,
  43. // so there is a high chance of name collisions (ex: index.jade).
  44. // This function attempts to create a unique directory for each
  45. // compiled template.
  46. // TODO: Extend Jade's caching class?
  47. public function cache_init($file_path)
  48. {
  49. $cache_key = md5($file_path);
  50. $cache_path = \Config::get('parser.View_Haml.cache_dir', null)
  51. .substr($cache_key, 0, 2).DS.substr($cache_key, 2, 2);
  52. if ($cache_path !== null AND ! is_dir($cache_path))
  53. {
  54. mkdir($cache_path, 0777, true);
  55. }
  56. static::$_cache = $cache_path;
  57. }
  58. }
  59. /* end of file haml.php */