mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-17 11:10:57 +01:00
Merge pull request #479 from fauxpark/filesize-patch
Add format_size Twig filter
This commit is contained in:
@@ -65,6 +65,7 @@ class Application extends SilexApplication
|
||||
$twig->addFilter(new \Twig_SimpleFilter('htmlentities', 'htmlentities'));
|
||||
$twig->addFilter(new \Twig_SimpleFilter('md5', 'md5'));
|
||||
$twig->addFilter(new \Twig_SimpleFilter('format_date', array($app, 'formatDate')));
|
||||
$twig->addFilter(new \Twig_SimpleFilter('format_size', array($app, 'formatSize')));
|
||||
|
||||
return $twig;
|
||||
}));
|
||||
@@ -97,6 +98,14 @@ class Application extends SilexApplication
|
||||
return $date->format($this['date.format']);
|
||||
}
|
||||
|
||||
public function formatSize($size)
|
||||
{
|
||||
$mod = 1000;
|
||||
$units = array('B', 'kB', 'MB', 'GB');
|
||||
for($i = 0; $size > $mod; $i++) $size /= $mod;
|
||||
return round($size, 2) . $units[$i];
|
||||
}
|
||||
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path . DIRECTORY_SEPARATOR;
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Total bytes:</strong> {{ stats.size }} bytes ({{ ((stats.size / 1024) / 1024) | number_format }} MB)
|
||||
<strong>Total bytes:</strong> {{ stats.size }} bytes ({{ stats.size | format_size }})
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
{%- endif -%}
|
||||
">{{ file.name }}</a></td>
|
||||
<td>{{ file.mode }}</td>
|
||||
<td>{% if file.size %}{{ (file.size / 1024) | number_format }} kb{% endif %}</td>
|
||||
<td>{% if file.size %}{{ file.size | format_size }}{% endif %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user