Attachment 'text_x_frame-1.6.0-4.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - Frame Parser
   4 
   5     This parser is used to align enclosed wiki markup.
   6         
   7     Syntax:
   8         {{{#!frame align=align,thick=thick,style=style,color=color,
   9         background=background,background_image=background_image,
  10         position=position,width=width,padding=padding,
  11         margin=margin,text_align=text_align,text_font_size=text_font_size,
  12         text_color=text_color
  13         wiki markup
  14         }}}
  15     
  16     Parameters:
  17         align:      one of ['left', 'right', 'center', 'justify', 'float:left','float:right']
  18                     default: left
  19                     
  20         thick:      one of ['thin', 'medium','thick','1px','2px','5px','10px']
  21                     default: thin
  22                     
  23         style:      one of ['none','hidden', 'dotted', 'dashed', 'solid', 'double',
  24                             'groove', 'ridge', 'inset',  'outset']
  25                     default: solid
  26                     
  27         color:      each color which could be vrified by web.Color(str(name))
  28                     default: black
  29                        
  30         background: each color which could be vrified by web.Color(str(name))
  31                     default: transparent
  32                     
  33         background_image: the name of an attachment 
  34                           default: ''
  35                           
  36         background_repeat: one of ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']
  37                            default: no-repeat               
  38                                          
  39         position:   one of ['static','absolute','relative','fixed','inherit']
  40                     default: relative
  41                           
  42         width:      has to end with % is testet by str(float(number))
  43                     default: auto
  44                           
  45         padding:    has to end with em is testet by str(float(number))
  46                     default: 0em
  47                           
  48         margin:     has to end with em is testet by str(float(number))
  49                     default: 0em                 
  50         
  51         text_align: one of ['left', 'right', 'center', 'justify']                              
  52                     default: left
  53                     
  54         text_font_size: one of ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large',
  55                                 'smaller', 'larger']
  56                         default: ''        
  57         text_color: each which could be vrified by web.Color(str(name))
  58                     default: black
  59                           
  60         wiki markup: could any wiki markup 
  61 
  62     Procedure:
  63         Please remove the version number.
  64         
  65         The units are limited for numbers. And only one value for padding or margin 
  66 
  67     Examples:
  68         {{{
  69         #!frame align=float:right
  70         attachment:moinmoin.png
  71         ||A||B||
  72         ||C||D||
  73         ||C||D||
  74         }}}
  75     
  76         {{{ 
  77 #!frame align=float:left,position=relative,width=48%,margin=0em,thick=2px,color=blue,background=yellow
  78 A WikiName is a word that uses capitalized words. WikiNames automagically become hyperlinks to the WikiName's page. What exactly is an uppercase or lowercase letter is determined by the configuration, the default configuration should work for UTF-8 characters (digits are treated like lowercase characters). 
  79 
  80 
  81 When you click on the highlighted page title (i.e. WikiName on this page), you will see a list of all pages that link to the current page. This even works on pages that are not defined yet.
  82 }}}{{{
  83 #!frame align=float:right,position=relative,width=50%,margin=0em,thick=2px,color=blue
  84 When you click on the highlighted page title (i.e. WikiName on this page), you will see a list of all pages that link to the current page. This even works on pages that are not defined yet. 
  85 
  86 
  87 A question mark before a link or a different rendering in grey means that the page is not yet defined: you can click the question mark or page name to offer a definition (e.g., ?NoSuchPageForReal). If you click on such a link, you will see a default page that you can edit; only after you save the page will it be created for real. A list of all pages that are not yet created but referred on another page is on WantedPages. 
  88 
  89 
  90 To escape a WikiName, i.e. if you want to write the word WikiName without linking it, use an "empty" bold sequence (a sequence of six single quotes) like this: Wiki''''''Name. Alternatively, you can use the shorter sequence "``" (two backticks), i.e. Wiki``Name.
  91 }}}
  92 {{{ 
  93 #!frame align=clear
  94 }}}
  95         
  96 = Album =
  97 {{{
  98 #!Frame align=float:right,background=gray,width=20%
  99 #!Gallery2 album=1,front_image=100_1194.JPG,album_name=Bremen,front_image=100_1189.JPG,show_tools=0,show_text=0,show_date=0
 100 }}}
 101 Some images from the trip to Bremen in 2004
 102 
 103  * SpaceCenter 
 104  * ScienceCenter
 105 {{{
 106 #!Frame align=clear
 107 }}}
 108         
 109     Modification History:
 110         @copyright: 2006 by Reimar Bauer
 111         @license: GNU GPL, see COPYING for details.
 112         
 113        1.6.0-2 2006-08-14 removed frame_ from paramter names
 114                           column:left and column:right removed becuse they are only floating elements
 115                           background_image, background_repeat, text_color, text_font_size added
 116        1.6.0-3 2006-08-15 bug fixes: position of float element wrong used and thick command failed for float
 117        1.6.0-4 2006-08-22 extended to use it for parsers too 
 118        
 119 """
 120 import StringIO, os, mimetypes
 121 from random import randint
 122 from MoinMoin.parser import text_moin_wiki
 123 from MoinMoin import wikiutil
 124 from MoinMoin.action import AttachFile
 125 from MoinMoin.util import web
 126 
 127 Dependencies = []
 128 
 129 class Parser:
 130 
 131     extensions = ['*']
 132     Dependencies = Dependencies
 133 
 134     def __init__(self, raw, request, **kw):
 135         self.raw = raw
 136         self.request = request
 137 
 138         self.align = 'left'  # secured
 139 
 140         self.text_align = 'left' #secured
 141         self.text_font_size = '' #secured
 142         self.text_color = 'black' #secured but wrong color code name crashes
 143         self.thick = 'thin' #secured
 144         self.style = 'solid' #secured
 145         self.color = 'black' #secured but wrong color code name crashes
 146         self.background = 'transparent' #secured but wrong color code name crashes
 147         self.background_image = None # secured by mimetype check
 148         self.background_repeat = 'no-repeat'
 149         self.position = 'relative' #secured
 150         self.width = 'auto' #needs a better idea to get it secure at the moment only % is allowed
 151         self.padding = '0em' #needs a better idea to get it secure at the moment only em is allowed
 152         self.margin = '0em' #needs a better idea to get it secure at the moment only em is allowed
 153 
 154         for arg in kw.get('format_args', '').split(','):
 155             if arg.find('=') > -1:
 156                 key, value = arg.split('=')
 157                 setattr(self, key, wikiutil.escape(value.strip(), quote=1))
 158 
 159 
 160     def format(self, formatter):
 161         raw = self.raw
 162         
 163         import string
 164         raw = string.split(raw, '\n')
 165         parser_name = ''
 166         for line in raw:
 167             if line.strip().startswith("#!"):
 168                 parser_name = line.strip()[2:].split()[0]
 169                 
 170                 for arg in line.split(','):
 171                     if arg.find('=') > -1:
 172                         key, value = arg.split('=')
 173                         setattr(self, key, wikiutil.escape(value.strip(), quote=1))
 174         
 175         pagename = formatter.page.page_name
 176         
 177         out = StringIO.StringIO()
 178         self.request.redirect(out)
 179         if parser_name != '':
 180             self.request.write(formatter.parser(parser_name, raw))
 181         else:
 182             wikiizer = text_moin_wiki.Parser(self.raw, self.request)
 183             wikiizer.format(formatter)
 184         result = out.getvalue()
 185         self.request.redirect()
 186         del out
 187 
 188         if self.position in ['static', 'absolute', 'relative', 'fixed', 'inherit']:
 189             position = self.position
 190         else:
 191             position = 'relative'
 192 
 193         if self.thick in ['thin', 'medium', 'thick', '1px', '2px', '5px', '10px']:
 194             thick = self.thick
 195         else:
 196             thick = '0'
 197 
 198         if self.text_align in ['left', 'right', 'center', 'justify']:
 199             text_align = self.text_align
 200         else:
 201            text_align = 'left'
 202 
 203         if self.style in ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double',
 204                           'groove', 'ridge', 'inset', 'outset']:
 205             style = self.style
 206         else:
 207             style = 'solid'
 208 
 209         if self.color != 'transparent':
 210             color = web.Color(str(self.color))
 211         else:
 212             color = 'black'
 213 
 214         if self.background != 'transparent':
 215             background = web.Color(str(self.background))
 216         else:
 217             background = 'transparent'
 218 
 219         if self.width.endswith("%"):
 220             width = str(float(self.width[:-1]))+'%'
 221         else:
 222             width = 'auto'
 223 
 224         if self.padding.endswith("em"):
 225             padding = str(float(self.padding[:-2]))+'em'
 226         else:
 227             padding = '0em'
 228 
 229         if self.margin.endswith("em"):
 230             margin = str(float(self.margin[:-2]))+'em'
 231         else:
 232             margin = '0em'
 233 
 234         if self.text_font_size in ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large',
 235                                    'smaller', 'larger']:
 236             text_font_size = self.text_font_size
 237         else:
 238             text_font_size = ''
 239 
 240         if self.text_color != 'transparent':
 241             text_color = web.Color(str(self.text_color))
 242         else:
 243             text_color = 'black'
 244 
 245         url = ''
 246         if self.background_image != None:
 247             attachment_path = AttachFile.getAttachDir(self.request, pagename)
 248             file = os.path.join(attachment_path, self.background_image)
 249             if os.path.exists(file):
 250                 mime_type, enc = mimetypes.guess_type(file)
 251                 if mime_type.startswith('image'):
 252                     url = AttachFile.getAttachUrl(pagename, self.background_image, self.request)
 253 
 254         if self.background_repeat in ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']:
 255             background_repeat = self.background_repeat
 256         else:
 257             background_repeat = 'no-repeat'
 258 
 259         if self.align in ['left', 'right', 'center', 'justify']:
 260             div = '<div align="%(align)s" style="border-width:%(thick)s; border-color:%(color)s; border-style:%(style)s; position:%(position)s; padding:%(padding)s; margin:%(margin)s; background-color:%(background)s; font-size:%(text_font_size)s; color:%(text_color)s; background-image:url(%(background_image)s); background-repeat:%(background_repeat)s;" width="%(width)s">' % {
 261                     "thick": thick,
 262                     "style": style,
 263                     "color": color,
 264                     "position": position,
 265                     "padding": padding,
 266                     "margin": margin,
 267                     "background": background,
 268                     "width": width,
 269                     "text_align": text_align,
 270                     "text_font_size": text_font_size,
 271                     "text_color": text_color,
 272                     "background_image": url,
 273                     "background_repeat": background_repeat,
 274                     "align": self.align,
 275                     }
 276             self.request.write("%(div)s%(result)s</div>" % {
 277                  "div": div,
 278                  "result": result})
 279 
 280         if self.align in ['float:left', 'float:right']:
 281             tab = '<table style="%(align)s; font-size:%(text_font_size)s; color:%(text_color)s; text-align:%(text_align)s; background-image:url(%(background_image)s); background-repeat:%(background_repeat)s; position:%(position)s;"  width="%(width)s" border="%(thick)s" bgcolor="%(background)s"><tbody><tr><td style="border-style:none;">' % {
 282                     "align": self.align,
 283                     "text_font_size": text_font_size,
 284                     "text_align": text_align,
 285                     "text_color": text_color,
 286                     "position": position,
 287                     "width": width,
 288                     "thick": thick,
 289                     "background": background,
 290                     "background_image": url,
 291                     "background_repeat": background_repeat,
 292                 }
 293             self.request.write("%(tab)s%(result)s</td></tr></tbody></table>" % {
 294                                "tab": tab,
 295                                "result": result})
 296 
 297         if self.align == 'clear':
 298             self.request.write('<br clear="both">')

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-08-15 19:58:26, 11.9 KB) [[attachment:Frame-1.5.4-3.py]]
  • [get | view] (2006-08-22 20:38:27, 12.8 KB) [[attachment:Frame-1.5.4-4.py]]
  • [get | view] (2006-09-04 06:51:24, 15.7 KB) [[attachment:Frame-1.5.4-5.py]]
  • [get | view] (2006-08-13 21:29:52, 9.7 KB) [[attachment:text_x_frame-1.6.0-1.py]]
  • [get | view] (2006-08-14 18:38:28, 11.7 KB) [[attachment:text_x_frame-1.6.0-2.py]]
  • [get | view] (2006-08-15 20:45:50, 11.4 KB) [[attachment:text_x_frame-1.6.0-3.py]]
  • [get | view] (2006-08-22 20:23:17, 12.4 KB) [[attachment:text_x_frame-1.6.0-4.py]]
  • [get | view] (2006-09-03 14:18:49, 15.7 KB) [[attachment:text_x_frame-1.6.0-5.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.