changeset 269:1e3e876e38fb

moved readout of description from text_x_arnica to Image
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 14 Sep 2008 18:56:15 +0200
parents bb780f830e66
children 4e0a4ce23497
files data/plugin/macro/Image.py data/plugin/parser/text_x_arnica.py
diffstat 2 files changed, 26 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/macro/Image.py	Sun Sep 14 16:49:18 2008 +0200
+++ b/data/plugin/macro/Image.py	Sun Sep 14 18:56:15 2008 +0200
@@ -48,9 +48,11 @@
                  item_name, # PageName/AttachName for now, later this is just the item name
                  headline=None,
                  caption=None,
+                 raw=None,
         ):
         self.request = request
         self.pagename, self.attachname = item_name.rsplit('/', 1)
+        self.raw = raw
 
         # cached property values:
         self.__filename = None
@@ -61,6 +63,21 @@
         self.__ctime = None
         self.__headline = headline
         self.__caption = caption
+        self.__description = self.attachname
+
+    def _get_description(self):
+        quotes = self.raw.split('\n')
+        quotes = [quote.strip() for quote in quotes]
+        quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
+        image_alias = self.attachname
+        for line in quotes:
+            if line.startswith('[[') and line.endswith(']]'):
+                img, alias = line[2:-2].split('|', 1)
+                if img == self.attachname:
+                    self.__description = alias.strip()
+                    break
+        return self.__description
+    description = property(_get_description)
 
     def _get_filename(self):
         if self.__filename is None:
--- a/data/plugin/parser/text_x_arnica.py	Sun Sep 14 16:49:18 2008 +0200
+++ b/data/plugin/parser/text_x_arnica.py	Sun Sep 14 18:56:15 2008 +0200
@@ -301,21 +301,6 @@
         from MoinMoin.parser.text_moin_wiki import Parser as WikiParser
         return wikiutil.renderText(self.request, WikiParser, text)
 
-    def get_image_alias(self):
-        """  gets the quotes from the item list and returns a dictionary of image and alias """
-        # ToDo keep the order of the given quotes
-        quotes = self.raw.split('\n')
-        quotes = [quote.strip() for quote in quotes]
-        quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
-        image_alias = {}
-        counter = 0
-        for line in quotes:
-            if line.startswith('[[') and line.endswith(']]'):
-                img, alias = line[2:-2].split('|', 1)
-                image_alias[img.strip()] = (self.formatter.text(alias.strip()), counter)
-                counter += 1
-        return image_alias
-
     def select_files(self, formatter):
         """ select files """
         # we need to take the page_name from the formatter.page otherwise
@@ -325,7 +310,15 @@
             self.pagename = self.target_page
         path = AttachFile.getAttachDir(self.request, self.pagename, create=1)
         image_dict = {}
-        image_alias = self.get_image_alias()
+        image_alias = {}
+        counter = 0
+        for attfile in _get_files(self.request, self.pagename):
+            itemname = formatter.page.page_name + '/' + attfile
+            img = self.Image(self.request, itemname, raw=self.raw)
+            if img.description != attfile:
+                image_alias[attfile] = (formatter.text(img.description), counter)
+                counter += 1
+        
         if self.only_items:
             # get the same order of files and aliastext as on the page written
             files = image_alias.keys()