changeset 2195:386caaa698d8

comments: moved the check for the user setting to the formatter, fixes caching issue
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 01 May 2007 19:01:20 +0200
parents 3ae6b91e4f72
children 45cf51902c61
files MoinMoin/formatter/text_html.py MoinMoin/formatter/text_python.py MoinMoin/parser/text_moin_wiki.py
diffstat 3 files changed, 36 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/text_html.py	Tue May 01 17:09:53 2007 +0200
+++ b/MoinMoin/formatter/text_html.py	Tue May 01 19:01:20 2007 +0200
@@ -1353,15 +1353,34 @@
         return self._close(tag)
 
     def div(self, on, **kw):
+        css_class = kw.get('css_class')
+        # the display of comment class divs depends on a user setting:
+        if css_class and 'comment' in css_class.split():
+            style = kw.get('style')
+            display = self.request.user.show_comments and "display:''" or "display:none"
+            if not style:
+                style = display
+            else:
+                style += "; %s" % display
+            kw['style'] = style
         tag = 'div'
         if on:
             return self._open(tag, **kw)
         return self._close(tag)
 
     def span(self, on, **kw):
+        css_class = kw.get('css_class')
+        # the display of comment class spans depends on a user setting:
+        if css_class and 'comment' in css_class.split():
+            style = kw.get('style')
+            display = self.request.user.show_comments and "display:''" or "display:none"
+            if not style:
+                style = display
+            else:
+                style += "; %s" % display
+            kw['style'] = style
         tag = 'span'
         if on:
             return self._open(tag, **kw)
         return self._close(tag)
 
-
--- a/MoinMoin/formatter/text_python.py	Tue May 01 17:09:53 2007 +0200
+++ b/MoinMoin/formatter/text_python.py	Tue May 01 19:01:20 2007 +0200
@@ -164,6 +164,20 @@
 
     smiley = icon
 
+    def span(self, on, **kw):
+        if on and 'comment' in kw.get('css_class', '').split():
+            return self.__insert_code('request.write(%s.span(%r, **%r))' %
+                                      (self.__formatter, on, kw))
+        else:
+            return self.formatter.span(on, **kw)
+
+    def div(self, on, **kw):
+        if on and 'comment' in kw.get('css_class', '').split():
+            return self.__insert_code('request.write(%s.div(%r, **%r))' %
+                                      (self.__formatter, on, kw))
+        else:
+            return self.formatter.div(on, **kw)
+
     def macro(self, macro_obj, name, args):
         if self.__is_static(macro_obj.get_dependencies(name)):
             return macro_obj.execute(name, args)
--- a/MoinMoin/parser/text_moin_wiki.py	Tue May 01 17:09:53 2007 +0200
+++ b/MoinMoin/parser/text_moin_wiki.py	Tue May 01 19:01:20 2007 +0200
@@ -258,11 +258,7 @@
         """Handle remarks."""
         # XXX we don't really enforce the correct sequence /* ... */ here
         self.is_remark = not self.is_remark
-        span_kw = {
-            'style': self.request.user.show_comments and "display:''" or "display:none",
-            'class': "comment",
-        }
-        return self.formatter.span(self.is_remark, **span_kw)
+        return self.formatter.span(self.is_remark, css_class='comment')
 
     def _small_repl(self, word):
         """Handle small."""
@@ -1008,11 +1004,7 @@
         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))
+            self.request.write(self.formatter.div(1, css_class=self.wrapping_div_class))
 
         # Main loop
         for line in self.lines: