mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-17 19:20:56 +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('htmlentities', 'htmlentities'));
|
||||||
$twig->addFilter(new \Twig_SimpleFilter('md5', 'md5'));
|
$twig->addFilter(new \Twig_SimpleFilter('md5', 'md5'));
|
||||||
$twig->addFilter(new \Twig_SimpleFilter('format_date', array($app, 'formatDate')));
|
$twig->addFilter(new \Twig_SimpleFilter('format_date', array($app, 'formatDate')));
|
||||||
|
$twig->addFilter(new \Twig_SimpleFilter('format_size', array($app, 'formatSize')));
|
||||||
|
|
||||||
return $twig;
|
return $twig;
|
||||||
}));
|
}));
|
||||||
@@ -97,6 +98,14 @@ class Application extends SilexApplication
|
|||||||
return $date->format($this['date.format']);
|
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()
|
public function getPath()
|
||||||
{
|
{
|
||||||
return $this->path . DIRECTORY_SEPARATOR;
|
return $this->path . DIRECTORY_SEPARATOR;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<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>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
">{{ file.name }}</a></td>
|
">{{ file.name }}</a></td>
|
||||||
<td>{{ file.mode }}</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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user