changeset 2395:e0a4950b9658

Refactored tab views code, major part on python side
author sharky93 <rishabhr123@gmail.com>
date Sun, 18 Aug 2013 03:04:16 +0530
parents 2e84d4574332
children 35b64d97bd9c
files MoinMoin/themes/__init__.py MoinMoin/themes/basic/templates/itemviews.html
diffstat 2 files changed, 39 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/themes/__init__.py	Sun Aug 18 02:18:13 2013 +0530
+++ b/MoinMoin/themes/__init__.py	Sun Aug 18 03:04:16 2013 +0530
@@ -79,12 +79,37 @@
         self.content_dir = 'ltr'  # XXX
         self.meta_items = []  # list of (name, content) for html head <meta>
 
-    def get_action_tabs(self, item_name):
-        navtabs = ['frontend.show_item', 'frontend.history',
-                'frontend.show_item_meta', 'frontend.highlight_item', 'frontend.backrefs',
-                'special.comments', 'special.transclusions',]
+    def get_action_tabs(self, item_name, current_endpoint):
+        navtabs_endpoints = ['frontend.show_item', 'frontend.history',
+                            'frontend.show_item_meta', 'frontend.highlight_item', 'frontend.backrefs',
+                            'special.comments', 'special.transclusions',]
         if self.user.may.write(item_name):
-            navtabs.append('frontend.modify_item')
+            navtabs_endpoints.append('frontend.modify_item')
+
+        icon = self.get_endpoint_iconmap()
+        exists = flaskg.storage.has_item(item_name)
+        navtabs = []
+
+        for endpoint, label, title, check_exists in app.cfg.item_views:
+            if endpoint not in app.cfg.endpoints_excluded:
+                if not check_exists or exists:
+                    if endpoint in navtabs_endpoints:
+
+                        iconcls = icon[endpoint]
+
+                        if endpoint == 'special.comments':
+                            maincls = "moin-toggle-comments-button"
+                            href = "#"
+                        elif endpoint == 'special.transclusions':
+                            maincls = "moin-transclusions-button"
+                            href = "#"
+                        else:
+                            maincls = None
+                            href = url_for(endpoint, item_name=item_name)
+                            if endpoint == current_endpoint:
+                                maincls = "active"
+
+                        navtabs.append((endpoint, href, maincls, iconcls, title, label))
         return navtabs
 
     def get_local_panel(self, item_name):
--- a/MoinMoin/themes/basic/templates/itemviews.html	Sun Aug 18 02:18:13 2013 +0530
+++ b/MoinMoin/themes/basic/templates/itemviews.html	Sun Aug 18 03:04:16 2013 +0530
@@ -3,41 +3,19 @@
 
 {% from theme("layout.html") import icon with context %}
 
-{% set navtabs = theme_supp.get_action_tabs(item_name) %}
+{% set navtabs = theme_supp.get_action_tabs(item_name, current_endpoint) %}
 
 {% block views %}
 
     <ul class="moin-nav nav-tabs moin-shadow">
-        {%- for endpoint, label, title, check_exists in cfg.item_views if not endpoint in cfg.endpoints_excluded %}
-            {%- if not check_exists or check_exists and exists %}
-
-                {%- if endpoint == 'special.comments' %}
-                    <li class="moin-toggle-comments-button">
-                        <a href="#" title="{{ title }}">
-                        <span class={{icon[endpoint]}}></span>
-                            {{ label }}
-                        </a>
-                    </li>
-
-                {% elif endpoint == 'special.transclusions' -%}
-                    <li class="moin-transclusions-button">
-                        <a href="#" title="{{ title }}">
-                        <span class={{icon[endpoint]}}></span>
-                            {{ label }}
-                        </a>
-                    </li>
-
-                {%- elif endpoint in navtabs %}
-                    <li {% if endpoint == current_endpoint %} class="active"{% endif %}>
-                        <a href="{{ url_for(endpoint, item_name=item_name) }}" title="{{ title }}" rel="nofollow">
-                        <span class={{icon[endpoint]}}></span>
-                            {{ label }}
-                        </a>
-                    </li>
-                {%- endif %}
-
-            {%- endif %}
-        {% endfor %}
+      {% for endpoint, href, maincls, iconcls, title, label in navtabs %}
+        <li class={% if maincls %} "{{ maincls }}" {% endif %}>
+            <a href="{{ href }}" title="{{ title }}" rel="nofollow">
+              <span class="{{ iconcls }}"></span>
+                {{ label }}
+            </a>
+        </li>
+      {% endfor %}
 
     </ul>
 {% endblock %}