diff MoinMoin/themes/__init__.py @ 126:81f0ff7a5cae

global / subitem index: do not show mimetype as text, but is a mimetype specific link class / icon
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 14 Mar 2011 04:18:36 +0100
parents db239a9ef5d0
children 75312c9b94e3
line wrap: on
line diff
--- a/MoinMoin/themes/__init__.py	Mon Mar 14 03:04:21 2011 +0100
+++ b/MoinMoin/themes/__init__.py	Mon Mar 14 04:18:36 2011 +0100
@@ -396,8 +396,24 @@
     return name
 
 
+MIMETYPE_TO_CLASS = {
+    'application/pdf': 'pdf',
+}
+
+def mimetype_to_class(mimetype):
+    """
+    Convert a mimetype string to a css class.
+    """
+    cls = MIMETYPE_TO_CLASS.get(mimetype)
+    if not cls:
+        # just use the major part of mimetype
+        cls = mimetype.split('/', 1)[0]
+    return 'moin-mime-%s' % cls
+
+
 def setup_jinja_env():
     app.jinja_env.filters['shorten_item_name'] = shorten_item_name
+    app.jinja_env.filters['mimetype_to_class'] = mimetype_to_class
     # please note that these filters are installed by flask-babel:
     # datetimeformat, dateformat, timeformat, timedeltaformat