Beispiel #1
0
function image_tag($src, $alt = NULL, array $attrs = array())
{
    if (is_array($alt)) {
        $attrs = $alt;
        $alt = $src;
    }
    if (!$alt or $alt === $src) {
        $ext = \IO\File::ext($src, TRUE);
        $alt = titlecase(basename($src, $ext));
    }
    $attrs['alt'] = $attrs['title'] = $alt;
    try {
        $img = \Tailor\Helpers::image($src);
        $attrs['width'] = $img['dims'][0];
        $attrs['height'] = $img['dims'][1];
        $attrs['src'] = asset_url($src);
    } catch (\Exception $e) {
        $attrs['src'] = $src;
    }
    return \Labourer\Web\Html::tag('img', $attrs);
}
Beispiel #2
0
 $out = path($output_dir, $path, "{$name}.{$type}");
 $dir = dirname($out);
 is_dir($dir) or mkdir($dir, 0777, TRUE);
 if (!is_file($out) or filemtime($file) > filemtime($out)) {
     switch ($type) {
         case 'html':
             $uri = $path ? "/{$path}" : '';
             $uri .= $name != 'index' ? "/{$name}.{$type}" : '/';
             assign('current_url', $uri);
             if ($base) {
                 $view = \Tailor\Base::compile($file);
             } else {
                 $view = read($file);
             }
             $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);
Beispiel #3
0
 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;
 }