Guest User

Untitled

a guest
Aug 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. <?php
  2.  
  3. App::import('Lib', 'AssetCompress.AssetFilterInterface');
  4.  
  5. class Jst extends AssetFilter {
  6.  
  7. /**
  8. * To use Handlebars.js instead of Underscore.js templates,
  9. * override the template_func settings in the INI file like so:
  10. *
  11. * [filter_Jst]
  12. * template_func = Handlebars.template
  13. *
  14. * The templates will be stored inside a global object called 'JST'
  15. * and keyed by file path, with the extension and base bath stripped.
  16. *
  17. * options:
  18. *
  19. * - ext : extension to strip from path when naming
  20. *
  21. * - base_dir_name : everything up to and including this directory
  22. * name will be stripped when naming
  23. */
  24.  
  25. protected $_settings = array(
  26. 'ext' => '.jst',
  27. 'base_dir_name' => 'views',
  28. 'template_func' => '_.template'
  29. );
  30.  
  31. public function input($file, $contents) {
  32. extract($this->_settings);
  33.  
  34. $name = $file;
  35. $name = preg_replace('/'.$ext.'$/','',$name);
  36. $name = preg_replace('#.*/'.$base_dir_name.'/#','',$name);
  37.  
  38. $contents = str_replace(array("\n","'"), array('\n',"\'"), $contents);
  39.  
  40. $out = '';
  41. $out .= "var JST = JST || {};\n";
  42. $out .= "JST['$name'] = " . $template_func . "('" . $contents . "');\n";
  43.  
  44. return $out;
  45. }
  46.  
  47. }
  48.  
  49.  
  50. ?>
Add Comment
Please, Sign In to add comment