changeset 1755:ef3990098268

Refactor foobar templates for better code reusing. local.html is gone. The "local" block is renmaed into local_panel and is now rendered conditionally in layout.html; templates that need local panels no longer need to extend from local.html. As a result, foobar's index.html now extends from default index.html, avoiding code duplication. The default "local" block implementation is moved to show.html.
author Cheer Xiao <xiaqqaix@gmail.com>
date Thu, 30 Aug 2012 17:37:51 +0800
parents abbbace78848
children 6f5477cc0348
files MoinMoin/templates/index.html MoinMoin/themes/foobar/templates/blog/layout.html MoinMoin/themes/foobar/templates/index.html MoinMoin/themes/foobar/templates/layout.html MoinMoin/themes/foobar/templates/local.html MoinMoin/themes/foobar/templates/show.html MoinMoin/themes/foobar/templates/usersettings.html
diffstat 7 files changed, 117 insertions(+), 283 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/templates/index.html	Wed Aug 29 18:20:31 2012 +0800
+++ b/MoinMoin/templates/index.html	Thu Aug 30 17:37:51 2012 +0800
@@ -12,58 +12,66 @@
     <script src="{{ url_for('frontend.template', filename='index_action.js') }}"></script>
 {% endblock %}
 
+{% block action_bars_inner %}
+    <ul>
+        {% if index %}
+        <li class="action-bar">
+        <div class="moin-select-all">
+            <span class="moin-select-allitem allitem-toselect" title="{{ _("Select All") }}">{{ _("Select All") }}</span>
+        </div>
+        </li>
+        {% endif %}
+        <li class="action-bar">
+        <div class="moin-select-actions">
+            <div>
+                <span class="show-action">Actions</span>
+            </div>
+            <ul>
+                <li id="moin-create-newitem">{{ _("New item") }}</li>
+                {% if index %}
+                <li id="moin-download-trigger">{{ _("Download") }}</li>
+                <li class="moin-action-tab"
+                    id="moin-delete-trigger"
+                    data-actionurl="{{ url_for('frontend.ajaxdelete', item_name=item_name) }}">
+                    {{ _("Delete") }}
+                </li>
+                <li class="moin-action-tab"
+                    id="moin-destroy-trigger"
+                    data-actionurl="{{ url_for('frontend.ajaxdestroy', item_name=item_name) }}">
+                    {{ _("Destroy") }}
+                </li>
+                {% endif %}
+            </ul>
+        </div>
+        </li>
+        <li class="action-bar">
+        <div class="moin-contenttypes-wrapper">
+            <div class="ct-hide">{{ _("Filter by content type") }}</div>
+            {% set unknown_items_label = _("items having unknown mime types") %}
+            {{ gen.form.open(form, method="get", action=url_for('frontend.index', item_name=item_name)) }}
+            <ul>
+                <li>
+                    <a href="#" class="filter-toggle">&raquo; {{ _("Toggle") }}</a>
+                    <a href="#" class="filter-more">&raquo; {{ _("More") }}</a>
+                </li>
+                {{ forms.render(form['contenttype']) }}
+            </ul>
+            {{ forms.render(form['submit']) }}
+            {{ gen.form.close() }}
+        </div>
+        </li>
+    </ul>
+{% endblock %}
+
+{% block action_bars %}
+    <div class="moin-align-right">
+        {{ self.action_bars_inner() }}
+    </div>
+{% endblock %}
+
 {% block content %}
     <div class="moin-index-message"><span></span></div>
-    <div class="moin-align-right">
-        <ul>
-            {% if index %}
-            <li class="action-bar">
-            <div class="moin-select-all">
-                <span class="moin-select-allitem allitem-toselect" title="{{ _("Select All") }}">{{ _("Select All") }}</span>
-            </div>
-            </li>
-            {% endif %}
-            <li class="action-bar">
-            <div class="moin-select-actions">
-                <div>
-                    <span class="show-action">Actions</span>
-                </div>
-                <ul>
-                    <li id="moin-create-newitem">{{ _("New item") }}</li>
-                    {% if index %}
-                    <li id="moin-download-trigger">{{ _("Download") }}</li>
-                    <li class="moin-action-tab"
-                        id="moin-delete-trigger"
-                        data-actionurl="{{ url_for('frontend.ajaxdelete', item_name=item_name) }}">
-                        {{ _("Delete") }}
-                    </li>
-                    <li class="moin-action-tab"
-                        id="moin-destroy-trigger"
-                        data-actionurl="{{ url_for('frontend.ajaxdestroy', item_name=item_name) }}">
-                        {{ _("Destroy") }}
-                    </li>
-                    {% endif %}
-                </ul>
-            </div>
-            </li>
-            <li class="action-bar">
-            <div class="moin-contenttypes-wrapper">
-                <div class="ct-hide">{{ _("Filter by content type") }}</div>
-                {% set unknown_items_label = _("items having unknown mime types") %}
-                {{ gen.form.open(form, method="get", action=url_for('frontend.index', item_name=item_name)) }}
-                <ul>
-                    <li>
-                        <a href="#" class="filter-toggle">&raquo; {{ _("Toggle") }}</a>
-                        <a href="#" class="filter-more">&raquo; {{ _("More") }}</a>
-                    </li>
-                    {{ forms.render(form['contenttype']) }}
-                </ul>
-                {{ forms.render(form['submit']) }}
-                {{ gen.form.close() }}
-            </div>
-            </li>
-        </ul>
-    </div>
+    {{ self.action_bars() }}
     <div>
     {% if item_name: %}
         <h1>{{ title }}</h1>
@@ -132,7 +140,7 @@
     <div id="popup">
         <div id="popup-for-action" class="popup-container">
             <div class="popup-header">
-                <div class="popup-closer popup-cancel" title="{{ _("Close") }}">x</div>
+                <input type="button" class="popup-closer popup-cancel" value="{{ _("X") }}" title="{{ _("Close") }}"/>
                 <span>{{ _("Please provide comment for this action") }}</span>
             </div>
             <div class="popup-body">
@@ -145,7 +153,7 @@
         </div>
         <div id="popup-for-newitem" class="popup-container">
             <div class="popup-header">
-                <div class="popup-closer popup-cancel" title="{{ _("Close") }}">x</div>
+                <input type="button" class="popup-closer popup-cancel" value="{{ _("X") }}" title="{{ _("Close") }}"/>
                 <span>{{ _("Create new item") }}</span>
             </div>
             <div class="popup-body">
--- a/MoinMoin/themes/foobar/templates/blog/layout.html	Wed Aug 29 18:20:31 2012 +0800
+++ b/MoinMoin/themes/foobar/templates/blog/layout.html	Thu Aug 30 17:37:51 2012 +0800
@@ -1,4 +1,4 @@
-{% extends theme("local.html") %}
+{% extends theme("layout.html") %}
 {% import theme("blog/utils.html") as blog_utils %}
 
 {% if blog_item %}
@@ -29,7 +29,7 @@
     {% endblock %}
 {% endblock %}
 
-{% block local %}
+{% block local_panel  %}
     <ul>
         {% if blog_name and supertags %}
         <li>
--- a/MoinMoin/themes/foobar/templates/index.html	Wed Aug 29 18:20:31 2012 +0800
+++ b/MoinMoin/themes/foobar/templates/index.html	Thu Aug 30 17:37:51 2012 +0800
@@ -1,178 +1,8 @@
-{% extends theme("local.html") %}
-{% import "forms.html" as forms with context %}
-{% block head_scripts %}
-{{ super() }}
-    <script src="{{ url_for('frontend.template', filename='index_action.js') }}"></script>
-{% endblock %}
+{% extends "index.html" %}
 
-{% block local %}
-    <ul>
-        {% if index %}
-        <li class="action-bar">
-        <div class="moin-select-all">
-            <span class="moin-select-allitem allitem-toselect" title="{{ _("Select All") }}">{{ _("Select All") }}</span>
-        </div>
-        </li>
-        {% endif %}
-        <li class="action-bar">
-        <div class="moin-select-actions">
-            <div>
-                <span>Actions</span>
-            </div>
-            <ul>
-                <li id="moin-create-newitem">{{ _("New item") }}</li>
-                {% if index %}
-                <li id="moin-download-trigger">{{ _("Download") }}</li>
-                <li class="moin-action-tab"
-                    id="moin-delete-trigger"
-                    data-actionurl="{{ url_for('frontend.ajaxdelete', item_name=item_name) }}">
-                    {{ _("Delete") }}
-                </li>
-                <li class="moin-action-tab"
-                    id="moin-destroy-trigger"
-                    data-actionurl="{{ url_for('frontend.ajaxdestroy', item_name=item_name) }}">
-                    {{ _("Destroy") }}
-                </li>
-                {% endif %}
-            </ul>
-        </div>
-        </li>
-        {% if index %}
-        <li class="action-bar">
-        <div class="moin-contenttypes-wrapper">
-            <div class="ct-hide">{{ _("Filter by type") }}</div>
-            {% set unknown_items_label = _("items having unknown mime types") %}
-            {{ gen.form.open(form, method="post", action=url_for('frontend.index', item_name=item_name)) }}
-            <ul>
-                <li>
-                    <a href="#" class="filter-toggle">&raquo; {{ _("Toggle") }}</a>
-                    <a href="#" class="filter-more">&raquo; {{ _("More") }}</a>
-                </li>
-                {% for e in [
-                    'markup_text_items',
-                    'other_text_items',
-                    'image_items',
-                    'audio_items',
-                    'video_items',
-                    'other_items',
-                    'unknown_items',
-                    ] %}
-                    <li>{{ forms.render(form[e]) }}</li>
-                {% endfor %}
-            </ul>
-            {{ forms.render(form['submit']) }}
-            {{ gen.form.close() }}
-        </div>
-        </li>
-        {% endif %}
-    </ul>
+{% block action_bars %}
 {% endblock %}
 
-{% block content %}
-    <div class="moin-index-message"><span></span></div>
-    <div>
-    {% if item_name: %}
-        <h1>{{ _("Index of subitems of '%(item_name)s'", item_name=item_name) }}</h1>
-        <div class="moin-index-path">
-            <a href="{{ url_for('frontend.index') }}" title="{{ _("Global Index") }}">{{ ("..") }}</a>
-            <span class="moin-path-separator">{{ ("/") }}</span>
-            {% for i in range(0, item_names|count) %}
-                {% set fullname = item_names[:i+1]|join('/') %}
-                {% set relname = item_names[i] %}
-                <a href="{{ url_for('frontend.index', item_name=fullname) }}" title="{{ relname }}">{{ relname }}</a>
-                <span class="moin-path-separator">{{ ("/") }}</span>
-            {% endfor %}
-        </div>
-    {% else %}
-    {% endif %}
-    </div>
-    <div class='moin-clr'></div>
-    <div id="moin-new-index" class="moin-item-index">
-        <h3 style="display: none;">{{ _("Recently uploaded items") }}</h3>
-        <div class="file_download_template" style="display: none;">
-            <a></a>
-        </div>
-    </div>
-    <div class="moin-index-separator"></div>
-    {% if index %}
-    <div id="moin-initials">
-        {% if not startswith %}
-            <a class="selected" href="{{ url_for('frontend.index', item_name=item_name) }}">{{ _("All") }}</a>
-        {% else %}
-            <a href="{{ url_for('frontend.index', item_name=item_name) }}">{{ _("All") }}</a>
-        {% endif %}
-        {% for initial in initials %}
-            {% if startswith == initial %}
-                <a class="selected" href="{{ url_for('frontend.index', item_name=item_name, startswith=initial) }}">{{ initial }}</a>
-            {% else %}
-                <a href="{{ url_for('frontend.index', item_name=item_name, startswith=initial) }}">{{ initial }}</a>
-            {% endif %}
-        {% endfor %}
-    </div>
-    <div class="moin-item-index">
-        {% set maxchars = 20 %}
-        {% for fullname, relname, contenttype, hassubitem in index %}
-            <div>
-                <span class="moin-select-item">&nbsp;</span>
-                {% set mimetype = "application/x.moin.download" %}
-                <a href="{{ url_for('.download_item', item_name=fullname, mimetype=mimetype) }}" class="moin-download-link">
-                </a>
-                <a href="{{ url_for('.show_item', item_name=fullname) }}"
-                   class="{{ contenttype|contenttype_to_class }} moin-item"
-                   title="{{ relname }}">
-                   {{ relname|truncate(maxchars, true, '..') }}
-                </a>
-                {% if hassubitem %}
-                    <a href="{{ url_for('frontend.index', item_name=fullname) }}"
-                       title="{{ _("More") }}"
-                       class="moin-more-index">&nbsp;
-                </a>
-                {% endif %}
-            </div>
-        {% endfor %}
-    </div>
-    <div class="moin-clr"></div>
-    {% endif %}
-    <div id="popup">
-        <div id="popup-for-action" class="popup-container">
-            <div class="popup-header">
-                <input type="button" class="popup-closer popup-cancel" value="{{ _("X") }}" title="{{ _("Close") }}"/>
-                <span>{{ _("Please provide comment for this action") }}</span>
-            </div>
-            <div class="popup-body">
-                <input type="text" class="popup-comment" placeholder="{{ _("Enter your comment") }}"/>
-                <input type="hidden" class="popup-action" value=""/>
-                <br/>
-                <input type="button" class="popup-submit" value="{{ _("Submit") }}"/>
-                <input type="button" class="popup-cancel" value="{{ _("Cancel") }}"/>
-            </div>
-        </div>
-        <div id="popup-for-newitem" class="popup-container">
-            <div class="popup-header">
-                <input type="button" class="popup-closer popup-cancel" value="{{ _("X") }}" title="{{ _("Close") }}"/>
-                <span>{{ _("Create new item") }}</span>
-            </div>
-            <div class="popup-body">
-                <form action={{ url_for('.ajaxmodify') }} method="post">
-                    <label for="moin-newitem">{{ _("Item name") }}</label>
-                    {% if item_name %}
-                        <input type="text" id="moin-newitem" name="newitem" placeholder="{{ _("Enter item name here") }}" value="{{ item_name }}/" required="required"/>
-                    {% else %}
-                        <input type="text" id="moin-newitem" name="newitem" placeholder="{{ _("Enter item name here") }}" required="required"/>
-                    {% endif %}
-                    <br/>
-                    <input type="submit" value="{{ _("Create") }}"/>
-                    <input type="button" class="popup-cancel" value="{{ _("Cancel") }}"/>
-                </form>
-            </div>
-        </div>
-    </div>
-
-    <div id="moin-upload-cont">
-    {% set submit_url = url_for('.jfu_server', item_name=item_name) %}
-    {{ forms.render_file_uploader(submit_url) }}
-    </div>
-    <span class="moin-drag">{{ _("(Drag and drop multiple files to this white area to upload them.)") }}</span>
-    <script src="{{ url_for('static', filename='js/jfu.js') }}"></script>
-    <div id="lightbox">&nbsp;</div>
+{% block local_panel %}
+    {{ self.action_bars_inner() }}
 {% endblock %}
--- a/MoinMoin/themes/foobar/templates/layout.html	Wed Aug 29 18:20:31 2012 +0800
+++ b/MoinMoin/themes/foobar/templates/layout.html	Thu Aug 30 17:37:51 2012 +0800
@@ -1,7 +1,11 @@
-{% import "forms.html" as forms %}
+{# If you want itemviews in your template, extend from show.html, not from here. #}
 {% extends theme("base.html") %}
 
+{% import "forms.html" as forms %}
+{% import "utils.html" as utils %}
+{% import "itemviews.html" as itemviews with context %}
 {% import theme("snippets.html") as snippets with context %}
+
 {% set logo = snippets.logo() %}
 {% set footer_logos = snippets.creditlogos() %}
 {% set footer_items = '' %}
@@ -149,10 +153,18 @@
 </div>
 
 {% block content_container %}
-    <div id="moin-content-no-panel" lang="{{ theme_supp.content_lang }}" dir="{{ theme_supp.content_dir }}">
-    {% block content %}
-    {% endblock %}
+    {% set content_id = self.local_panel and 'moin-content' or 'moin-content-no-panel' %}
+    <div id="{{ content_id }}" lang="{{ theme_supp.content_lang }}" dir="{{ theme_supp.content_dir }}">
+        {% block content %}
+            {# All content templates should implement this block. #}
+        {% endblock %}
     </div>
+
+    {% if self.local_panel %}
+        <div id="moin-local-panel">
+            {{ self.local_panel() }}
+        </div>
+    {% endif %}
 {% endblock %}
 </div>
 
--- a/MoinMoin/themes/foobar/templates/local.html	Wed Aug 29 18:20:31 2012 +0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-{% extends theme("layout.html") %}
-{% import "utils.html" as utils %}
-{% import "itemviews.html" as itemviews with context %}
-
-{% block content_container %}
-<div id="moin-content" lang="{{ theme_supp.content_lang }}" dir="{{ theme_supp.content_dir }}">
-    {% block item -%}
-        {# If you want itemviews in your template, extend from show.html, not from here. #}
-        {% block content %}
-            {# All content templates should have implement this block. #}
-        {% endblock %}
-    {%- endblock %}
-</div>
-
-<div id="moin-local-panel">
-{% block local %}
-<ul>
-    <li class="panel">Views
-        {{ itemviews }}
-    </li>
-    {% if rev %}
-    <li id="moin-metadata">Metadata
-        <ul>
-            <li>{{ _("Revision:") }} {{rev.revid | shorten_id}}</li>
-            <li>({{ rev.meta['mtime']|datetimeformat }})</li>
-            <li>{{ _("By:") }} {{ utils.editor_info(rev.meta) }}</li>
-            <li>{{ _("Size:") }} {{ rev.meta['size'] }}</li>
-            <li>{{ _("Type:") }} {{ rev.meta['contenttype'] }}</li>
-            {% if rev.meta.tags %}
-            <li>
-            {{ _("Tags:") }}
-            {% for tag in rev.meta.tags -%}
-            <a href="{{ url_for('frontend.tagged_items', tag=tag) }}">{{ tag }}</a>{% if not loop.last %}, {% endif %}
-            {%- endfor -%}
-            </li>
-            {% endif %}
-        </ul>
-    </li>
-    {% endif %}
-    <li>
-        {% block subitem_navigation %}
-        {{ utils.render_subitem_navigation(item_name, False) }}
-        {% endblock %}
-    </li>
-</ul>
-{% endblock %}
-</div>
-{% endblock %}
--- a/MoinMoin/themes/foobar/templates/show.html	Wed Aug 29 18:20:31 2012 +0800
+++ b/MoinMoin/themes/foobar/templates/show.html	Thu Aug 30 17:37:51 2012 +0800
@@ -1,4 +1,4 @@
-{% extends theme("local.html") %}
+{% extends theme("layout.html") %}
 
 {% block head_links %}
     {{ super() }}
@@ -19,6 +19,38 @@
     {% endblock %}
 {% endblock %}
 
+{% block local_panel %}
+    <ul>
+        <li class="panel">Views
+            {{ itemviews }}
+        </li>
+        {% if rev %}
+        <li id="moin-metadata">Metadata
+            <ul>
+                <li>{{ _("Revision:") }} {{rev.revid | shorten_id}}</li>
+                <li>({{ rev.meta['mtime']|datetimeformat }})</li>
+                <li>{{ _("By:") }} {{ utils.editor_info(rev.meta) }}</li>
+                <li>{{ _("Size:") }} {{ rev.meta['size'] }}</li>
+                <li>{{ _("Type:") }} {{ rev.meta['contenttype'] }}</li>
+                {% if rev.meta.tags %}
+                <li>
+                {{ _("Tags:") }}
+                {% for tag in rev.meta.tags -%}
+                <a href="{{ url_for('frontend.tagged_items', tag=tag) }}">{{ tag }}</a>{% if not loop.last %}, {% endif %}
+                {%- endfor -%}
+                </li>
+                {% endif %}
+            </ul>
+        </li>
+        {% endif %}
+        <li>
+            {% block subitem_navigation %}
+            {{ utils.render_subitem_navigation(item_name, False) }}
+            {% endblock %}
+        </li>
+    </ul>
+{% endblock %}
+
 {% block options_for_javascript %}
 {%- if item_name and user.edit_on_doubleclick and user.may.write(item_name) -%}
     <br id="moin-edit-on-doubleclick" />
--- a/MoinMoin/themes/foobar/templates/usersettings.html	Wed Aug 29 18:20:31 2012 +0800
+++ b/MoinMoin/themes/foobar/templates/usersettings.html	Thu Aug 30 17:37:51 2012 +0800
@@ -1,7 +1,7 @@
-{% extends theme("local.html") %}
+{% extends theme("layout.html") %}
 {% import "usersettings_forms.html" as user_forms %}
 
-{% block local %}
+{% block local_panel %}
 <ul id="moin-usersetting-title">
 <li class="moin-tab-title"><a href="#moin-personal">{{ _("Personal Settings") }}</a></li>
 <li class="moin-tab-title"><a href="#moin-password">{{ _("Change Password") }}</a></li>