changeset 1752:6f8360e1a4bb

wrapping div support for wiki parser, toggling display of comment divs, show_comments user prefs
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 28 Jan 2007 22:40:49 +0100
parents 3567062fc66f
children c0c1a4d9151d
files MoinMoin/config/multiconfig.py MoinMoin/parser/text_moin_wiki.py MoinMoin/theme/__init__.py docs/CHANGES wiki/htdocs/common/js/common.js wiki/htdocs/modern/css/common.css
diffstat 6 files changed, 67 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/config/multiconfig.py	Sun Jan 21 19:43:34 2007 +0100
+++ b/MoinMoin/config/multiconfig.py	Sun Jan 28 22:40:49 2007 +0100
@@ -235,7 +235,7 @@
     default_markup = 'wiki'
     docbook_html_dir = r"/usr/share/xml/docbook/stylesheet/nwalsh/html/" # correct for debian sarge
 
-    edit_bar = ['Edit', 'Discussion', 'Info', 'Subscribe', 'Quicklink', 'Attachments', 'ActionsMenu'] 
+    edit_bar = ['Edit', 'Comments', 'Discussion', 'Info', 'Subscribe', 'Quicklink', 'Attachments', 'ActionsMenu'] 
     editor_default = 'text' # which editor is called when nothing is specified
     editor_ui = 'freechoice' # which editor links are shown on user interface
     editor_force = False
@@ -449,6 +449,7 @@
         ('mailto_author', lambda _: _('Publish my email (not my wiki homepage) in author info')),
         ('edit_on_doubleclick', lambda _: _('Open editor on double click')),
         ('remember_last_visit', lambda _: _('After login, jump to last visited page')),
+        ('show_comments', lambda _: _('Show comment sections')),
         ('show_nonexist_qm', lambda _: _('Show question mark for non-existing pagelinks')),
         ('show_page_trail', lambda _: _('Show page trail')),
         ('show_toolbar', lambda _: _('Show icon toolbar')),
@@ -467,6 +468,7 @@
     user_checkbox_defaults = {'mailto_author':       0,
                               'edit_on_doubleclick': 0,
                               'remember_last_visit': 0,
+                              'show_comments': 0,
                               'show_nonexist_qm':    nonexist_qm,
                               'show_page_trail':     1,
                               'show_toolbar':        1,
--- a/MoinMoin/parser/text_moin_wiki.py	Sun Jan 21 19:43:34 2007 +0100
+++ b/MoinMoin/parser/text_moin_wiki.py	Sun Jan 28 22:40:49 2007 +0100
@@ -127,6 +127,11 @@
         self.macro = None
         self.start_line = kw.get('start_line', 0)
 
+        # currently, there is only a single, optional argument to this parser and
+        # (when given), it is used as class(es) for a div wrapping the formatter output
+        # either use a single class like "comment" or multiple like "comment/red/dotted"
+        self.wrapping_div_class = kw.get('format_args', '').strip().replace('/', ' ')
+
         self.is_em = 0 # must be int
         self.is_b = 0 # must be int
         self.is_u = False
@@ -956,6 +961,13 @@
 
         self.in_processing_instructions = 1
 
+        if self.wrapping_div_class:
+            div_kw = {'css_class': self.wrapping_div_class, }
+            if 'comment' in self.wrapping_div_class.split():
+                # show comment divs depending on user profile (and wiki configuration)
+                div_kw['style'] = self.request.user.show_comments and "display:''" or "display:none"
+            self.request.write(self.formatter.div(1, **div_kw))
+
         # Main loop
         for line in self.lines:
             self.lineno += 1
@@ -1110,6 +1122,9 @@
         if self.formatter.in_p: self.request.write(self.formatter.paragraph(0))
         if self.in_table: self.request.write(self.formatter.table(0))
 
+        if self.wrapping_div_class:
+            self.request.write(self.formatter.div(0))
+
     # Private helpers ------------------------------------------------------------
 
     def setParser(self, name):
--- a/MoinMoin/theme/__init__.py	Sun Jan 21 19:43:34 2007 +0100
+++ b/MoinMoin/theme/__init__.py	Sun Jan 28 22:40:49 2007 +0100
@@ -1053,6 +1053,7 @@
         This is separate method to make it easy to customize the
         edtibar in sub classes.
         """
+        _ = self.request.getText
         editbar_actions = []
         for editbar_item in self.request.cfg.edit_bar:
              if editbar_item == 'Discussion':
@@ -1060,16 +1061,19 @@
                      editbar_actions.append(self.supplementation_page_nameLink(page))
                  elif self.request.cfg.supplementation_page and not self.request.getPragma('supplementation-page', 1) in ('off', '0'):
                      editbar_actions.append(self.supplementation_page_nameLink(page))
+             elif editbar_item == 'Comments':
+                 # we just use <a> to get same style as other links: 
+                 editbar_actions.append('<a id="toggleCommentsButton" onClick="toggleComments();">%s</a>' % _('Comments'))
              elif editbar_item == 'Edit':
-                  editbar_actions.append(self.editorLink(page))
+                 editbar_actions.append(self.editorLink(page))
              elif editbar_item == 'Info':
-                  editbar_actions.append(self.infoLink(page))
+                 editbar_actions.append(self.infoLink(page))
              elif editbar_item == 'Subscribe':
-                  editbar_actions.append(self.subscribeLink(page))
+                 editbar_actions.append(self.subscribeLink(page))
              elif editbar_item == 'Quicklink':
-                  editbar_actions.append(self.quicklinkLink(page))
+                 editbar_actions.append(self.quicklinkLink(page))
              elif editbar_item == 'Attachments':
-                  editbar_actions.append(self.attachmentsLink(page))
+                 editbar_actions.append(self.attachmentsLink(page))
              elif editbar_item == 'ActionsMenu':
                  editbar_actions.append(self.actionsMenu(page))
         return editbar_actions
--- a/docs/CHANGES	Sun Jan 21 19:43:34 2007 +0100
+++ b/docs/CHANGES	Sun Jan 28 22:40:49 2007 +0100
@@ -296,6 +296,22 @@
     * we now have the possibility to add a Discussion page 
       (FeatureRequests/DiscussionAndOrCommentPages) 
     * Package Pages does now support attachments
+    * The wiki parser can be used with css classes now:
+      {{{#!wiki comment
+      This will render output within a div with class "comment".
+      You can use any wiki markup as usual.
+      }}}
+      You can also combine multiple css classes like this:
+      {{{#!wiki red/dotted/comment
+      This will render a red background, dotted border comment section.
+      }}}
+      The same thing will work for any other css classes you have.
+      If the css classes contain the word "comment", they will trigger some
+      special feature, see next item:
+    * There is a new item in the edit bar: "Comments". If you click it, the
+      visibility of the comment sections will be toggled. A comment section is
+      any div of class "comment". There is a user preferences item
+      "show_comments" to set if the default view shows them or not.
 
   Bugfixes:
     * on action "info" page, "revert" link will not be displayed for empty page
--- a/wiki/htdocs/common/js/common.js	Sun Jan 21 19:43:34 2007 +0100
+++ b/wiki/htdocs/common/js/common.js	Sun Jan 28 22:40:49 2007 +0100
@@ -168,6 +168,20 @@
     }
 }
 
+function toggleComments() {
+    // Toggle visibility of every div with class == *comment*
+    var all = document.getElementsByTagName('div');
+    for (i = 0; i < all.length; i++){
+        el = all[i];
+        if ( el.className.indexOf('comment') >= 0 ){
+            if ( el.style.display != 'none' ) {
+                el.style.display = 'none';
+            } else {
+                el.style.display = '';
+            }
+        }
+    }
+}
 
 function load() {
     // Do not name this "onload", it does not work with IE :-)
--- a/wiki/htdocs/modern/css/common.css	Sun Jan 21 19:43:34 2007 +0100
+++ b/wiki/htdocs/modern/css/common.css	Sun Jan 28 22:40:49 2007 +0100
@@ -91,6 +91,16 @@
 }
 
 
+.red { background-color: #FFCCCC; }
+.green { background-color: #CCFFCC; }
+.blue { background-color: #CCCCFF; }
+
+.solid { border: 2px solid #000000; padding: 2px; }
+.dashed { border: 2px dashed #000000; padding: 2px; }
+.dotted { border: 2px dotted #000000; padding: 2px; }
+
+.comment { color: #555555; }
+
 table
 {
 	margin: 0.5em 0 0 0.5em;