Commits

Reimar Bauer committed 70c2406 Draft Merge

merged main

Comments (0)

Files changed (11)

MoinMoin/apps/frontend/views.py

File contents unchanged.

MoinMoin/constants/contenttypes.py

File contents unchanged.

MoinMoin/items/__init__.py

File contents unchanged.

MoinMoin/items/content.py

 
 
 @register
-class TWikiDraw(Draw):
-    """
-    drawings by TWikiDraw applet. It creates three files which are stored as tar file.
-    """
-    contenttype = 'application/x-twikidraw'
-    display_name = 'TDRAW'
-
-    class ModifyForm(Draw.ModifyForm):
-        template = "modify_twikidraw.html"
-        help = ""
-
-    def handle_post(self):
-        # called from modify UI/POST
-        file_upload = request.files.get('filepath')
-        filename = request.form['filename']
-        basepath, basename = os.path.split(filename)
-        basename, ext = os.path.splitext(basename)
-
-        filecontent = file_upload.stream
-        content_length = None
-        if ext == '.draw': # TWikiDraw POSTs this first
-            filecontent = filecontent.read() # read file completely into memory
-            filecontent = filecontent.replace("\r", "")
-        elif ext == '.map':
-            filecontent = filecontent.read() # read file completely into memory
-            filecontent = filecontent.strip()
-        elif ext == '.png':
-            #content_length = file_upload.content_length
-            # XXX gives -1 for wsgiref, gives 0 for werkzeug :(
-            # If this is fixed, we could use the file obj, without reading it into memory completely:
-            filecontent = filecontent.read()
-
-        self.put_member('drawing' + ext, filecontent, content_length,
-                        expected_members=set(['drawing.draw', 'drawing.map', 'drawing.png']))
-
-    def _render_data(self):
-        # TODO: this could be a converter -> dom, then transcluding this kind
-        # of items and also rendering them with the code in base class could work
-        item_name = self.name
-        drawing_url = url_for('frontend.get_item', item_name=item_name, member='drawing.draw', rev=self.rev.revid)
-        png_url = url_for('frontend.get_item', item_name=item_name, member='drawing.png', rev=self.rev.revid)
-        title = _('Edit drawing %(filename)s (opens in new window)', filename=item_name)
-
-        mapfile = self.get_member('drawing.map')
-        try:
-            image_map = mapfile.read()
-            mapfile.close()
-        except (IOError, OSError):
-            image_map = ''
-        if image_map:
-            # we have a image map. inline it and add a map ref to the img tag
-            mapid = 'ImageMapOf' + item_name
-            image_map = image_map.replace('%MAPNAME%', mapid)
-            # add alt and title tags to areas
-            image_map = re.sub(r'href\s*=\s*"((?!%TWIKIDRAW%).+?)"', r'href="\1" alt="\1" title="\1"', image_map)
-            image_map = image_map.replace('%TWIKIDRAW%"', '{0}" alt="{1}" title="{2}"'.format((drawing_url, title, title)))
-            title = _('Clickable drawing: %(filename)s', filename=item_name)
-
-            return Markup(image_map + u'<img src="{0}" alt="{1}" usemap="#{2}" />'.format(png_url, title, mapid))
-        else:
-            return Markup(u'<img src="{0}" alt="{1}" />'.format(png_url, title))
-
-
-@register
 class AnyWikiDraw(Draw):
     """
     drawings by AnyWikiDraw applet. It creates three files which are stored as tar file.

MoinMoin/templates/base.html

File contents unchanged.

MoinMoin/templates/modify_select_contenttype.html

File contents unchanged.

MoinMoin/templates/modify_twikidraw.html

-{% macro data_editor(form, item_name) %}
-<p>
-<applet code="CH.ifa.draw.twiki.TWikiDraw.class"
-        archive="{{ url_for('serve.files', name='twikidraw_moin', filename='twikidraw_moin.jar') }}"
-        width="800" height="620">
-        <param name="drawpath" value="{{ url_for('frontend.get_item', item_name=item_name, member='drawing.draw') }}" />
-        <param name="pngpath"  value="{{ url_for('frontend.get_item', item_name=item_name, member='drawing.png') }}" />
-<param name="savepath" value="{{ url_for('frontend.modify_item', item_name=item_name, contenttype='application/x-twikidraw') }}" />
-<param name="basename" value="drawing" />
-<param name="viewpath" value="{{ url_for('frontend.show_item', item_name=item_name) }}" />
-<param name="helppath" value="" />
-<strong>{{ _("NOTE:") }}</strong> {{ _("You need a Java enabled browser to edit the drawing.") }}
-</applet>
-</p>
-<br />
-{% endmacro %}

MoinMoin/templates/show.html

 {% extends theme("layout.html") %}
 {% import "utils.html" as utils %}
-
+{% block header %}
+    {{ super() }}
+    {{ JS_SCRIPTS["show.header"] }}
+{%- endblock %}
 {% block head_links %}
     {{ super() }}
     <link rel="alternate" title="{{ item_name }} changes" href="{{ url_for('feed.atom', item_name=item_name) }}" type="application/atom+xml" />

MoinMoin/themes/__init__.py

     app.jinja_env.filters['json_dumps'] = dumps
     # please note that these filters are installed by flask-babel:
     # datetimeformat, dateformat, timeformat, timedeltaformat
-
+    app.jinja_env.globals['JS_SCRIPTS'] = app.cfg.js_scripts
     app.jinja_env.globals.update({
                             # please note that flask-babel/jinja2.ext installs:
                             # _, gettext, ngettext
         'pdfminer', # pdf -> text/plain conversion
         'XStatic>=0.0.2', # support for static file pypi packages
         'XStatic-CKEditor>=3.6.1.2',
-        'XStatic-jQuery>=1.8.2',
         'XStatic-jQuery-File-Upload>=4.4.2',
         'XStatic-JSON-js',
         'XStatic-svgweb>=2011.2.3.2',
-        'XStatic-TWikiDraw-moin>=2004.10.23.2',
         'XStatic-AnyWikiDraw>=0.14.2',
         'XStatic-svg-edit-moin>=2011.07.07.2',
     ],
     # see https://bitbucket.org/thomaswaldmann/xstatic for infos about xstatic:
     from xstatic.main import XStatic
     # names below must be package names
-    mod_names = ['jquery', 'jquery_file_upload',
+    mod_names = ['jquery_file_upload',
                  'json_js',
                  'ckeditor',
                  'svgweb',
-                 'svgedit_moin', 'twikidraw_moin', 'anywikidraw',
+                 'svgedit_moin', 'anywikidraw',
                 ]
     pkg = __import__('xstatic.pkg', fromlist=mod_names)
     for mod_name in mod_names:
         mod = getattr(pkg, mod_name)
         xs = XStatic(mod, root_url='/static', provider='local', protocol='http')
         serve_files.update([(xs.name, xs.base_dir)])
-
+    # highly experimental
+    # if we do that we need for all of our xstatic mod_names a similar mplugin module
+    #  
+    import sys
+    try:
+        mplugins = sys.modules['moinplugin.pkg']
+    except KeyError:
+        mplugins = None
+    if mplugins:
+        plugin_packages = ["mathjax", "twikidraw", "jquery", ]
+        pkg = __import__('moinplugin.pkg', fromlist=plugin_packages)
+        template_dirs = []
+        js_scripts = {}
+        for mod_name in plugin_packages:
+            mod = getattr(pkg, mod_name)
+            # plugin can add a template dir
+            try:
+                template_dirs.append(mod.TEMPLATE_DIR)
+            except AttributeError:
+                pass
+            # plugin need to serve something
+            try:
+                serve_files.update([(mod.STATIC_NAME, mod.STATIC_PATH)])
+            except AttributeError:
+                pass
+            # mathjax plugin adds only js
+            try:
+                for key in mod.JS_SCRIPTS.keys():
+                    if key not in js_scripts:
+                        js_scripts[key] = ""
+                    js_scripts[key] += mod.JS_SCRIPTS[key]
+            except AttributeError:
+                pass
 
 MOINCFG = Config # Flask only likes uppercase stuff
 # Flask settings - see the flask documentation about their meaning