コード例 #1
0
ファイル: Assets.php プロジェクト: bradstinson/assets
 /**
  * Renders CSS/JS files (returns HTML tags)
  * @param  mixed    $type   Can be NULL, 'css', or 'js'
  * @return string
  */
 public static function render($type = NULL)
 {
     // If $type is null, render both types
     if (!$type) {
         $type = array('css', 'js');
     }
     // If $type is string, convert to array
     $types = is_string($type) ? array($type) : $type;
     $response = array();
     foreach ($types as $type) {
         $collection = self::$collections[$type];
         $collection->load();
         $compiler = new Assets\Compiler($collection, $type, self::$cache_path);
         $compiler->compile();
         if (file_exists(self::$cache_path . $compiler->getCompiledName($type))) {
             $url = self::$cache_url . $compiler->getCompiledName();
             $html = new Assets\Html($type, $url);
             $response[] = $html->render();
         }
     }
     return implode(PHP_EOL, $response);
 }