<?php if (arg('v f i c j a views fonts images styles scripts all')) { $cache = array(); $cache_dir = \Tailor\Config::get('cache_dir'); $base_path = path(APP_PATH, 'app', 'assets'); $views_dir = path(APP_PATH, 'app', 'views'); $static_dir = path(APP_PATH, 'static'); // views if (arg('v views all') && is_dir($views_dir)) { \IO\Dir::each($views_dir, '*', function ($file) { if (is_file($file)) { $name = join('.', array_slice(explode('.', basename($file)), 0, 2)); $path = str_replace(path(APP_PATH, 'app', 'views') . DIRECTORY_SEPARATOR, '', dirname($file)); $cache_dir = \Tailor\Config::get('cache_dir'); $cache_file = path($cache_dir, strtr("{$path}/{$name}", '\\/', '__')); write(path(dirname($cache_file), basename($cache_file)), \Tailor\Base::compile($file)); status('prepare', "{$path}/{$name}"); } }); } $handler = function ($on) use($base_path, $static_dir) { $dir = path($static_dir, $on); $path = path($base_path, $on); return function ($file) use($on, $dir, $path, $base_path, $static_dir) { if (is_file($file)) { $file_hash = md5(md5_file($file) . filesize($file)); $file_name = str_replace($path . DIRECTORY_SEPARATOR, '', \IO\File::extn($file)) . $file_hash . \IO\File::ext($file, TRUE); $file_path = path($dir, $file_name); if (s3_handle()) { s3_upload_asset($file, str_replace($static_dir . DIRECTORY_SEPARATOR, '', $file_path));
private static function extract($from, $on) { $out = array(); is_file($from) or $from = \Tailor\Helpers::resolve($from, $on); if (!is_file($from)) { throw new \Exception("The file '{$from}' does not exists"); } $ext = static::extension($on); $dir = \Tailor\Config::get($on); $url = \Tailor\Config::get(str_replace('_dir', '_url', $on)); // TODO: accept other formats? if (preg_match_all('/\\s+\\*=\\s+(\\w+)\\s+(\\S+)/m', read($from), $match)) { foreach ($match[1] as $i => $key) { $tmp = path($dir, $match[2][$i]); $old = \Tailor\Helpers::findfile("{$tmp}*", 0); if (is_dir($old)) { \IO\Dir::open($old, function ($file) use(&$out, $key) { $out[$key][] = $file; }); } else { if (!is_file($old)) { $old = "{$url}/{$match[2][$i]}"; substr($old, -strlen($ext)) != $ext && ($old .= ".{$ext}"); } $out[$key][] = $old; } } } return $out; }