Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- App::import('Lib', 'AssetCompress.AssetFilterInterface');
- class Jst extends AssetFilter {
- /**
- * To use Handlebars.js instead of Underscore.js templates,
- * override the template_func settings in the INI file like so:
- *
- * [filter_Jst]
- * template_func = Handlebars.template
- *
- * The templates will be stored inside a global object called 'JST'
- * and keyed by file path, with the extension and base bath stripped.
- *
- * options:
- *
- * - ext : extension to strip from path when naming
- *
- * - base_dir_name : everything up to and including this directory
- * name will be stripped when naming
- */
- protected $_settings = array(
- 'ext' => '.jst',
- 'base_dir_name' => 'views',
- 'template_func' => '_.template'
- );
- public function input($file, $contents) {
- extract($this->_settings);
- $name = $file;
- $name = preg_replace('/'.$ext.'$/','',$name);
- $name = preg_replace('#.*/'.$base_dir_name.'/#','',$name);
- $contents = str_replace(array("\n","'"), array('\n',"\'"), $contents);
- $out = '';
- $out .= "var JST = JST || {};\n";
- $out .= "JST['$name'] = " . $template_func . "('" . $contents . "');\n";
- return $out;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment