コード例 #1
0
ファイル: do_compile.php プロジェクト: hbnro/habanero
                 $layout = fetch('layout') ?: 'default';
                 $layout = \Tailor\Helpers::resolve("layouts/{$layout}", 'views_dir');
                 $hash = "{$layout}@";
                 $hash .= md5_file($file);
                 $hash .= filemtime($file);
                 if (is_file($layout)) {
                     $view = adjust_tags($view, \Tailor\Base::compile($layout));
                 }
                 status('partial', $out);
                 write($out, $view);
                 break;
             case 'css':
             case 'js':
             default:
                 if ($base) {
                     $view = \Tailor\Base::compile($file);
                     status('partial', $out);
                     write($out, $view);
                 } else {
                     status('copy', $out);
                     copy($file, $out);
                 }
                 break;
         }
     }
     // TODO: more formats or better check-up?
 } elseif (preg_match('/\\.(?:jpe?g|png|gif|woff|eot|ttf|svg|ico|xml|rss|txt|webm|mp[34]|og[gv])$/', $file)) {
     $out = path($output_dir, $path, basename($file));
     $dir = dirname($out);
     is_dir($dir) or mkdir($dir, 0777, TRUE);
     status('copy', $out);
コード例 #2
0
ファイル: assets_precompile.php プロジェクト: hbnro/habanero
 // asset mashup, grouped
 if (!empty($tmp['include'])) {
     foreach ($tmp['include'] as $test) {
         $ext = \IO\File::ext($test);
         $key = str_replace(APP_PATH . DIRECTORY_SEPARATOR, '', $test);
         $name = join('.', array_slice(explode('.', basename($test)), 0, 2));
         $path = str_replace(path(APP_PATH, 'app', 'assets', $type), '__', dirname($test));
         if ($ext != $type) {
             $cache_file = path($cache_dir, strtr("{$path}/{$name}", '\\/', '__'));
             if (is_file($cache_file)) {
                 $out[$key] = !empty($cache[$key]) ? $cache[$key] : ($cache[$key] = read($cache_file));
             } else {
                 if (!empty($cache[$key])) {
                     $out[$key] = $cache[$key];
                 } else {
                     $out[$key] = \Tailor\Base::compile($test);
                     write($cache_file, $out[$key]);
                 }
             }
         } else {
             $out[$key] = read($test);
         }
         if ($type === 'css') {
             $out[$key] = css_min(solve_paths($out[$key]));
         } else {
             if (!preg_match('/\\.(min|pack)\\.js$/', $test)) {
                 $out[$key] = js_min($out[$key]);
             }
         }
         status('prepare', "{$key}");
     }
コード例 #3
0
ファイル: Assets.php プロジェクト: hbnro/habanero
 public static function read($path)
 {
     $ext = \IO\File::ext($path);
     $type = \IO\Helpers::mimetype($ext);
     $dir = \Tailor\Config::get(static::guess($path));
     $path = trim(strtr($path, '\\/', '//'), '/');
     $file = substr($path, strpos($path, '/') + 1);
     $base = path($dir, $file);
     $test = \Tailor\Helpers::findfile("{$base}*", 0);
     if (!is_file($test)) {
         throw new \Exception("File '{$base}' not found");
     }
     switch ($ext) {
         case 'css':
         case 'js':
             if (\IO\File::ext($test) === $ext) {
                 $output = \IO\File::read($test);
             } else {
                 $tmp = path(\Tailor\Config::get('cache_dir'), strtr($file, '\\/', '__'));
                 if (is_file($tmp)) {
                     if (filemtime($test) > filemtime($tmp)) {
                         unlink($tmp);
                     }
                 }
                 if (!is_file($tmp)) {
                     $tpl = \Tailor\Base::compile($test);
                     $now = date('Y-m-d H:i:s', filemtime($test));
                     $output = "/* {$now} ./assets/{$ext}/{$file} */\n{$tpl}";
                     \IO\File::write($tmp, $output);
                 } else {
                     $output = \IO\File::read($tmp);
                 }
             }
             break;
         default:
             $output = \IO\File::read($test);
             break;
     }
     return compact('output', 'type');
 }