changeset 4411:47e54cf3047b

files: preview of images
author Martin Vium <martinv@unity3d.com>
date Tue, 12 Nov 2013 11:10:38 +0100
parents a1aa34845e94
children e457b951aabe
files kallithea/lib/vcs/nodes.py kallithea/public/css/style.css kallithea/templates/files/files_source.html
diffstat 3 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/vcs/nodes.py	Fri Aug 01 20:28:42 2014 +0200
+++ b/kallithea/lib/vcs/nodes.py	Tue Nov 12 11:10:38 2013 +0100
@@ -422,6 +422,14 @@
         _bin = '\0' in self._get_content()
         return _bin
 
+    def is_browser_compatible_image(self):
+        return self.mimetype in [
+            "image/gif",
+            "image/jpeg",
+            "image/png",
+            "image/bmp"
+        ]
+
     @LazyProperty
     def extension(self):
         """Returns filenode extension"""
--- a/kallithea/public/css/style.css	Fri Aug 01 20:28:42 2014 +0200
+++ b/kallithea/public/css/style.css	Tue Nov 12 11:10:38 2013 +0100
@@ -5122,6 +5122,12 @@
     margin: -2px;
 }
 
+.img-preview {
+    max-width: 100%;
+    height: auto;
+    margin: 5px;
+}
+
 div.prev-next-comment div.prev-comment,
 div.prev-next-comment div.next-comment {
     display: inline-block;
--- a/kallithea/templates/files/files_source.html	Fri Aug 01 20:28:42 2014 +0200
+++ b/kallithea/templates/files/files_source.html	Tue Nov 12 11:10:38 2013 +0100
@@ -56,12 +56,14 @@
         <div class="commit">${h.urlify_commit(c.file_changeset.message,c.repo_name)}</div>
     </div>
     <div class="code-body">
-       %if c.file.is_binary:
-           <div style="padding:5px">
-           ${_('Binary file (%s)') % c.file.mimetype}
-           </div>
-       %else:
-        % if c.file.size < c.cut_off_limit:
+      %if c.file.is_browser_compatible_image():
+        <img src="${h.url('files_raw_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path)}" class="img-preview"/>
+      %elif c.file.is_binary:
+        <div style="padding:5px">
+          ${_('Binary file (%s)') % c.file.mimetype}
+        </div>
+      %else:
+        %if c.file.size < c.cut_off_limit:
             %if c.annotate:
               ${h.pygmentize_annotation(c.repo_name,c.file,linenos=True,anchorlinenos=True,lineanchors='L',cssclass="code-highlight")}
             %else:
@@ -71,7 +73,7 @@
             ${_('File is too big to display')} ${h.link_to(_('Show as raw'),
             h.url('files_raw_home',repo_name=c.repo_name,revision=c.file_changeset.raw_id,f_path=c.f_path))}
         %endif
-     %endif
+      %endif
     </div>
 </div>