jade.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 Everzet\Jade;
  16. class View_Jade extends \View
  17. {
  18. protected static $_jade;
  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()->cache($file);
  25. return parent::process_file($file);
  26. }
  27. public $extension = 'jade';
  28. /**
  29. * Returns the Parser lib object
  30. *
  31. * @return Jade\Parser
  32. */
  33. public static function parser()
  34. {
  35. if ( ! empty(static::$_parser))
  36. {
  37. return static::$_parser;
  38. }
  39. $parser = new Jade\Parser(new Jade\Lexer\Lexer());
  40. $dumper = new Jade\Dumper\PHPDumper();
  41. $dumper->registerVisitor('tag', new Jade\Visitor\AutotagsVisitor());
  42. $dumper->registerFilter('javascript', new Jade\Filter\JavaScriptFilter());
  43. $dumper->registerFilter('cdata', new Jade\Filter\CDATAFilter());
  44. $dumper->registerFilter('php', new Jade\Filter\PHPFilter());
  45. $dumper->registerFilter('style', new Jade\Filter\CSSFilter());
  46. static::$_jade = new Jade\Jade($parser, $dumper, static::$_cache);
  47. return static::$_jade;
  48. }
  49. // Jade stores cached templates as the filename in plain text,
  50. // so there is a high chance of name collisions (ex: index.jade).
  51. // This function attempts to create a unique directory for each
  52. // compiled template.
  53. public function cache_init($file_path)
  54. {
  55. $cache_key = md5($file_path);
  56. $cache_path = \Config::get('parser.View_Jade.cache_dir', null)
  57. .substr($cache_key, 0, 2).DS.substr($cache_key, 2, 2);
  58. if ($cache_path !== null AND ! is_dir($cache_path))
  59. {
  60. mkdir($cache_path, 0777, true);
  61. }
  62. static::$_cache = $cache_path;
  63. }
  64. }
  65. /* end of file jade.php */