示例#1
0
文件: assets.php 项目: hbnro/habanero
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);
}
示例#2
0
function plain($text)
{
    return \Labourer\Web\Text::plain(\Labourer\Web\Html::unents($text));
}
示例#3
0
文件: Assets.php 项目: hbnro/habanero
 public static function tag_for($path)
 {
     $type = \IO\File::ext($path);
     switch ($type) {
         case 'css':
             return \Labourer\Web\Html::link('stylesheet', static::url_for($path, 'styles_dir'), array('type' => 'text/css'));
         case 'js':
             return \Labourer\Web\Html::script(static::url_for($path, 'scripts_dir'));
         case 'jpeg':
         case 'jpg':
         case 'png':
         case 'gif':
             return \Labourer\Web\Html::img(static::url_for($path, 'images_dir'), $path);
         default:
             throw new \Exception("Unsupported tag for '{$type}'");
     }
 }