changeset 2480:a17476268e7a

refined macro for hyperlink and local panel, the sidebar links are not red when the page doesn't exist
author sharky93 <rishabhr123@gmail.com>
date Sat, 14 Sep 2013 04:22:40 +0530
parents 2d84ec2d9de1
children 76098dbcb43c
files MoinMoin/themes/__init__.py MoinMoin/themes/basic/templates/layout.html
diffstat 2 files changed, 23 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/themes/__init__.py	Sat Sep 14 03:01:18 2013 +0530
+++ b/MoinMoin/themes/__init__.py	Sat Sep 14 04:22:40 2013 +0530
@@ -144,20 +144,20 @@
                             if endpoint == 'frontend.quicklink_item':
                                 if not flaskg.user.is_quicklinked_to([item_name]):
                                     label = _('Add Link')
-                                    user_actions.append((endpoint, href, iconcls, label, title))
+                                    user_actions.append((endpoint, href, iconcls, label, title, True))
                             elif endpoint == 'frontend.subscribe_item':
                                 if flaskg.user.is_subscribed_to([item_name]):
                                     label = _('Unsubscribe')
                                 else:
                                     label = _('Subscribe')
-                                user_actions.append((endpoint, href, iconcls, label, title))
+                                user_actions.append((endpoint, href, iconcls, label, title, True))
 
                     elif endpoint in item_actions_endpoints:
 
                         iconcls = icon[endpoint]
 
                         href = url_for(endpoint, item_name=item_name)
-                        item_actions.append((endpoint, href, iconcls, label, title))
+                        item_actions.append((endpoint, href, iconcls, label, title, True))
 
                     elif endpoint in item_navigation_endpoints:
 
@@ -169,14 +169,15 @@
                                 if current_sub not in app.cfg.supplementation_item_names:
                                     supp_name = '%s/%s' % (item_name, sub_item_name)
                                     if flaskg.storage.has_item(supp_name) or flaskg.user.may.write(supp_name):
+                                        exists = self.storage.has_item(supp_name)
                                         href = url_for('frontend.show_item', item_name=supp_name)
                                         label = _(sub_item_name)
                                         title = None
 
-                                        item_navigation.append((endpoint, href, iconcls, label, title))
+                                        item_navigation.append((endpoint, href, iconcls, label, title, exists))
                         else:
                             href = url_for(endpoint, item_name=item_name)   
-                            item_navigation.append((endpoint, href, iconcls, label, title))
+                            item_navigation.append((endpoint, href, iconcls, label, title, True))
 
         return user_actions, item_navigation, item_actions
 
@@ -191,7 +192,7 @@
                'frontend.similar_names' : "icon-search",
                'frontend.download_item' : "icon-download-alt",
                'frontend.copy_item' : "icon-comment",
-               'special.supplementation' : None,
+               'special.supplementation' : "icon-comments",
                'frontend.show_item' : "icon-eye-open",
                'frontend.modify_item' : "icon-pencil",
                'frontend.history' : "icon-time",
--- a/MoinMoin/themes/basic/templates/layout.html	Sat Sep 14 03:01:18 2013 +0530
+++ b/MoinMoin/themes/basic/templates/layout.html	Sat Sep 14 04:22:40 2013 +0530
@@ -15,21 +15,23 @@
 
 {# Helper macro to generate the local panel #}
 {% macro local_panel_main(panelname) -%}
-    {% for endpoint, href, iconcls, label, title in panelname %}
-        <a class="list-group-item{% if href == current_url %} active{% endif %}" href="{{ href }}" title="{{ title }}" rel="nofollow">
-            {% if iconcls %}
-                <i class="{{ iconcls }} icon-fixed-width"></i>
-            {% endif %}
-            {{ label }}
-        </a>
+    {% for endpoint, href, iconcls, label, title, exists in panelname %}
+        {# iconcls should be defined, defined for all local_panel_items, see themes/__init.py #}
+        {{ hyperlink(href, title, exists, label, iconcls + " icon-fixed-width", "list-group-item") }}
     {% endfor %}
 {% endmacro %}
 
 {# Helper macro to generate links #}
-{% macro hyperlink(href, title, exists, label, iconcls) -%}
+{% macro hyperlink(href, title, exists, label, iconcls, mainclass) -%}
     <a href="{{ href }}" 
-        {% if not exists %}class="moin-nonexistent"{% endif %}
-        {% if current_url == href %} class="active" {% endif %}
+        {% if not exists %} class="moin-nonexistent {% if mainclass %}{{ mainclass }} {% endif %}"
+        {% else %}
+        {% if mainclass %}
+            class="{{ mainclass }}{% if current_url == href %} active{% endif %}" 
+        {% elif current_url == href %}
+            class="active"
+        {% endif %}
+        {% endif %}
         rel="nofollow" 
         {% if title %} title="{{ title }}" {% endif %}>
         {% if iconcls %} <i class="{{ iconcls }}"> </i> {% endif %}
@@ -73,26 +75,26 @@
                                 {% if user.name -%}
                                     {% set wiki_href, aliasname, title, exists = theme_supp.userhome() %}
                                     <li>
-                                        {{ hyperlink(wiki_href, title, exists, aliasname, "icon-user icon-white") }}
+                                        {{ hyperlink(wiki_href, title, exists, aliasname, "icon-user icon-white", None) }}
                                     </li>
                                     {% if 'frontend.usersettings' not in cfg.endpoints_excluded -%}
                                         <li>
                                             {{ hyperlink(url_for('frontend.usersettings'), None, True,
-                                                _('Settings'), "icon-cog icon-white") }}
+                                                _('Settings'), "icon-cog icon-white", None) }}
                                         </li>
                                     {%- endif %}
                                 {%- endif %}
                                 {% if user.auth_method in cfg.auth_can_logout %}
                                     <li>
                                         {{ hyperlink(url_for('frontend.logout', logout_submit=1), None, True,
-                                                _('Logout'), "icon-off icon-white") }}
+                                                _('Logout'), "icon-off icon-white", None) }}
                                     </li>
                                 {% endif %}
                             {% else %}
                                 {% set login_url = theme_supp.login_url() %}
                                 {% if login_url %}
                                     <li>
-                                        {{ hyperlink(login_url, None, True, _('Login'), None) }}
+                                        {{ hyperlink(login_url, None, True, _('Login'), None, None) }}
                                     </li>
                                 {% endif %}
                             {%- endif %}