Commits

Thomas Waldmann committed e885cf1 Merge

merged

Comments (0)

Files changed (8)

MoinMoin/static/js/common.js

 jQuery(document).ready(function() {
     new QuicklinksExpander();
 })
+
+function toggleSubtree(item) {
+    /* used to toggle subtrees in the subitem widget */
+    var subtree = $(item).siblings("ul");
+    subtree.toggle(200);
+}
+
+function guessContentType() {
+    /* Used in the modify_text template to guess the data content type client-side 
+     * This approach has the advantage of reacting to content type changes for the 
+     * link/transclude code without having to re-fetch the page */
+    var meta_text = $("#f_meta_text").val();
+    var ctype_regex = /["']contenttype["']\s*:\s*["']([\w-_+.]+\/[\w-_+.]+)(;|["'])/;
+    if (meta_text) {
+        var match = ctype_regex.exec(meta_text);
+        if (match) return match[1];
+    }
+    // text/plain is the default value
+    return "text/plain";
+}
+
+function transcludeSubitem(subitem_name, fullname) {
+    function moinwiki(subitem_name, fullname) {
+        return "{{/" + subitem_name.replace("{{", "\\}}") + "}} ";
+    }
+    function mediawiki(subitem_name, fullname) {
+        return "{{:" + fullname.replace("}}", "\\}}") + "}} ";
+    }
+    function rst(subitem_name, fullname) {
+        return "\n.. include:: " + subitem_name + "\n";
+    }
+    function docbook(subitem_name, fullname) {
+        return ""; //XXX: the docbook converter currently doesn't handle transclusion with <ref> tags
+    }
+    var transclude_formats = {
+        "text/x.moin.wiki" : moinwiki,
+        "text/x.moin.creole" : moinwiki,
+        "text/x-mediawiki" : mediawiki,
+        "text/x-rst" : rst,
+        "application/docbook+xml" : docbook,
+        "text/plain" : function(x){return x + " ";},
+    }
+    var ctype = guessContentType();
+    var input_element = $("#f_data_text");
+    var ctype_format = transclude_formats[ctype];
+    if (!ctype_format) ctype_format = transclude_formats["text/plain"];
+    input_element.val(input_element.val() + ctype_format(subitem_name, fullname));
+    input_element.focus();
+}
+
+function linkSubitem(subitem_name, fullname) {
+    function moinwiki(subitem_name, fullname) {
+        return "[[/" + subitem_name.replace("]", "\\]") + "]] ";
+    }
+    function mediawiki(subitem_name, fullname) {
+        return "[[" + fullname.replace("]", "\\]") + "|" + subitem_name.replace("]", "\\]") + "]] ";
+    }
+    function rst(subitem_name, fullname) {
+        return "`" + subitem_name.replace(">", "\\>").replace("`", "\\`") + " <" + fullname.replace(">", "\\>") + ">`_ ";
+    }
+    function docbook(subitem_name, fullname) {
+        return '<ulink url="/' + fullname.replace('"', '\\"') + '">' + subitem_name + "</ulink>";;
+    }
+    var link_formats = {
+        "text/x.moin.wiki" : moinwiki,
+        "text/x.moin.creole" : moinwiki,
+        "text/x-mediawiki" : mediawiki,
+        "text/x-rst" : rst,
+        "application/docbook+xml" : docbook,
+        "text/plain" : function(x){return x + " ";},
+    }
+    var ctype = guessContentType();
+    var input_element = $("#f_data_text");
+    var ctype_format = link_formats[ctype];
+    if (!ctype_format) ctype_format = link_formats["text/plain"];
+    input_element.val(input_element.val() + ctype_format(subitem_name, fullname));
+    input_element.focus();
+}

MoinMoin/templates/modify_text.html

 {% extends "modify_binary.html" %}
+{% import "utils.html" as utils %}
+
+{% block subitem_navigation %}
+        {% call(fullname, shortname, contenttype, has_children) utils.render_subitem_navigation(item_name, True) %}
+            {% set shortname = shortname|json_dumps %}
+            {% set fullname = fullname|json_dumps %}
+            <button class="link-action" onclick='linkSubitem({{ shortname }}, {{ fullname }})'
+                title="{{ _('Link to Subitem') }}">{{ _('Link') }}</button>
+            <button class="transclude-action" 
+                onclick='transcludeSubitem({{ shortname }}, {{ fullname }})'
+                title="{{ _('Transclude Subitem') }}">{{ _('Transclude') }}</button>
+        {% endcall %}
+{% endblock %}
+
 {% block data_editor %}
 {{ gen.textarea(form['data_text'], lang=lang, dir=direction, rows=rows_data, cols=cols) }}
 <br />

MoinMoin/templates/show.html

 {% endmacro %}
 
 {% block subitem_navigation %}
-    {% set subitems = theme_supp.subitem_index(item_name) %}
-    {% if subitems %}
-        <div class="moin-subitem-navigation">
-            <div class="list-header">
-                {{ _('Subitems') }} 
-            </div>
-            <ul>
-                {% for fullname, shortname, contenttype, has_children in subitems %}
-                    <li>
-                        <a href="{{ url_for('frontend.show_item', item_name=fullname) }}"
-                            title="{{ shortname }}">{{ shortname }}</a>
-                        {% if has_children %}<span class="sep">/</span>{% endif %}
-                    </li>
-                {% endfor %}
-            </ul>
-        </div>
-    {% endif %}
+    {{ utils.render_subitem_navigation(item_name, False) }}
 {% endblock %}
 
 {% block content %}

MoinMoin/templates/utils.html

 </table>
 {% endmacro %}
 
+{% macro _render_subitem_navigation_tree(subitems, newtab, parentcaller) %}
+    <ul>
+        {% for fullname, shortname, contenttype, has_children in subitems %}
+            <li>
+                {# call our parent's caller with all the data we have if they exist, used to implement
+                    transclude/link actions in the modify view #}
+                {% if parentcaller %}
+                    {{ parentcaller(fullname, shortname, contenttype, has_children) }}
+                {% endif %}
+                <a href="{{ url_for('frontend.show_item', item_name=fullname) }}"
+                    title="{{ shortname }}" class="subitem-link"
+                    {% if newtab %}target="_blank"{% endif %}>{{ shortname }}</a>
+                {% if has_children %}
+                    <button class="expander" title="{{ _('Expand Subitem') }}"
+                        onclick="toggleSubtree(this)">/</button>
+                    {{ _render_subitem_navigation_tree(theme_supp.subitem_index(fullname), newtab, parentcaller) }}
+                {% endif %}
+            </li>
+        {% endfor %}
+    </ul>
+{% endmacro %}
+
+{% macro render_subitem_navigation(itemname, newtab) %}
+    {% set subitems = theme_supp.subitem_index(itemname) %}
+    {% if caller %}
+        {% set mycaller = caller %}
+    {% endif %}
+    {% if subitems %}
+        <div class="moin-subitem-navigation">
+            <div class="list-header">
+                {{ _('Subitems') }} 
+            </div>
+            {{ _render_subitem_navigation_tree(subitems, newtab, mycaller) }}
+        </div>
+    {% endif %}
+{% endmacro %}

MoinMoin/themes/__init__.py

 
 import urllib
 
+from json import dumps
 from operator import itemgetter
 
 from flask import current_app as app
         result['email'] = email
     return result
 
-
 def shorten_item_name(name, length=25):
     """
     Shorten item names
     app.jinja_env.filters['shorten_item_name'] = shorten_item_name
     app.jinja_env.filters['shorten_id'] = shorten_id
     app.jinja_env.filters['contenttype_to_class'] = contenttype_to_class
+    app.jinja_env.filters['json_dumps'] = dumps
     # please note that these filters are installed by flask-babel:
     # datetimeformat, dateformat, timeformat, timedeltaformat
 

MoinMoin/themes/modernized/static/css/common.css

 .moin-subitem-navigation li:hover { background: #4D7DA9; }
 .moin-subitem-navigation a { color: #0044B3; }
 .moin-subitem-navigation a:hover { text-decoration: underline; }
+.moin-subitem-navigation li ul { border-left: 1px dotted gray; display: none; }
+.moin-subitem-navigation .expander { background: url(../img/moin-expand.png) no-repeat center center; cursor: pointer;
+                height: 16px; overflow: hidden; vertical-align: middle; width: 16px; border: hidden; text-indent: -9000%; }
+.link-action,
+.transclude-action { border: hidden; text-indent: -9000%; padding: 0; margin: 0 -2px; vertical-align: middle;
+                height: 16px; width: 16px; overflow: hidden; cursor: pointer; }
+.moin-subitem-navigation .link-action { background: url(../img/moin-link.png) no-repeat center center; }
+.moin-subitem-navigation .transclude-action { background: url(../img/moin-transclusion.png) no-repeat center center; }
 
 /* moin-page moin-footer */
 #moin-footer { clear: both; margin: 0 0; }

MoinMoin/themes/modernized/static/img/moin-link.png

Added
New image

MoinMoin/themes/modernized/static/img/moin-transclusion.png

Added
New image