diff --git a/src/GitList/Application.php b/src/GitList/Application.php index 18cc681..34eb03e 100644 --- a/src/GitList/Application.php +++ b/src/GitList/Application.php @@ -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; diff --git a/themes/default/twig/stats.twig b/themes/default/twig/stats.twig index 7d36093..495663e 100644 --- a/themes/default/twig/stats.twig +++ b/themes/default/twig/stats.twig @@ -37,7 +37,7 @@
- Total bytes: {{ stats.size }} bytes ({{ ((stats.size / 1024) / 1024) | number_format }} MB) + Total bytes: {{ stats.size }} bytes ({{ stats.size | format_size }})
diff --git a/themes/default/twig/tree.twig b/themes/default/twig/tree.twig index a33bbb4..828275f 100644 --- a/themes/default/twig/tree.twig +++ b/themes/default/twig/tree.twig @@ -50,7 +50,7 @@ {%- endif -%} ">{{ file.name }}