Add a new view modifier which allows the shortening of long strings such as branch or tag names. Use that in the tree view and display the full name in a title tag.

This commit is contained in:
Thomas Keller 2010-04-29 23:35:57 +02:00
parent cf22909722
commit 995f1a13c3
3 changed files with 28 additions and 10 deletions

View File

@ -92,6 +92,7 @@ class IDF_Middleware
array(
'size' => 'IDF_Views_Source_PrettySize',
'ssize' => 'IDF_Views_Source_PrettySizeSimple',
'shorten' => 'IDF_Views_Source_ShortenString',
));
}
}

View File

@ -597,3 +597,16 @@ function IDF_Views_Source_PrettySizeSimple($size)
return Pluf_Utils::prettySize($size);
}
function IDF_Views_Source_ShortenString($string, $length)
{
$ellipse = "...";
$length = max(strlen($ellipse) + 2, $length);
$preflen = ceil($length / 10);
if (mb_strlen($string) < $length)
return $string;
return substr($string, 0, $preflen).$ellipse.
substr($string, -($length - $preflen - mb_strlen($ellipse)));
}

View File

@ -58,14 +58,18 @@
<p><strong>{trans 'Branches:'}</strong><br/>
{foreach $branches as $branch => $path}
{aurl 'url', 'IDF_Views_Source::treeBase', array($project.shortname, $branch)}
<span class="label{if in_array($branch, $tree_in)} active{/if}"><a href="{$url}" class="label">{if $path}{$path}{else}{$branch}{/if}</a></span><br/>
<span class="label{if in_array($branch, $tree_in)} active{/if}"><a href="{$url}" class="label" title="{if $path}{$path}{else}{$branch}{/if}">
{if $path}{$path|shorten:25}{else}{$branch|shorten:25}{/if}
</a></span><br/>
{/foreach}
</p>
{if $tags}
<p><strong>{trans 'Tags:'}</strong><br/>
{foreach $tags as $tag => $path}
{aurl 'url', 'IDF_Views_Source::treeBase', array($project.shortname, $tag)}
<span class="label{if in_array($tag, $tags_in)} active{/if}"><a href="{$url}" class="label">{if $path}{$path}{else}{$tag}{/if}</a></span><br/>
<span class="label{if in_array($tag, $tags_in)} active{/if}"><a href="{$url}" class="label" title="{if $path}{$path}{else}{$tag}{/if}">
{if $path}{$path|shorten:25}{else}{$tag|shorten:25}{/if}
</a></span><br/>
{/foreach}
</p>
{/if}