Attachment 'Frame-1.5.4-3.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         
  97     Modification History:
  98         @copyright: 2006 by Reimar Bauer
  99         @license: GNU GPL, see COPYING for details.
 100         
 101        1.6.0-2 2006-08-14 removed frame_ from paramter names
 102                           column:left and column:right removed becuse they are only floating elements
 103                           background_image, background_repeat, text_color, text_font_size added
 104        1.5.4-3 2006-08-15 ported to 1.5.4 and some bug fixes: position of float element wrong used and thick command failed for float
 105        
 106 """
 107 import StringIO, os, mimetypes
 108 from random import randint
 109 from MoinMoin.parser import wiki
 110 from MoinMoin import wikiutil
 111 from MoinMoin.action import AttachFile
 112 from MoinMoin.webapi.color import Color
 113 
 114 Dependencies = []
 115 
 116 class Parser:
 117 
 118     extensions = ['*']
 119     Dependencies = Dependencies
 120 
 121     def __init__(self, raw, request, **kw):
 122         self.raw = raw
 123         self.request = request
 124         
 125         self.align = 'left'  # secured
 126         
 127         self.text_align = 'left' #secured
 128         self.text_font_size = '' #secured
 129         self.text_color = 'black' #secured but wrong color code name crashes
 130         self.thick = 'thin' #secured
 131         self.style = 'solid' #secured
 132         self.color = 'black' #secured but wrong color code name crashes
 133         self.background = 'transparent' #secured but wrong color code name crashes
 134         self.background_image = None # secured by mimetype check
 135         self.background_repeat = 'no-repeat'
 136         self.position = 'relative' #secured
 137         self.width = 'auto' #needs a better idea to get it secure at the moment only % is allowed
 138         self.padding = '0em' #needs a better idea to get it secure at the moment only em is allowed
 139         self.margin = '0em' #needs a better idea to get it secure at the moment only em is allowed
 140         
 141         
 142         
 143         for arg in kw.get('format_args', '').split(','):
 144             if arg.find('=') > -1:
 145                 key, value = arg.split('=')
 146                 setattr(self, key, wikiutil.escape(value.strip(), quote=1)) 
 147                 
 148     
 149 
 150     def format(self, formatter):
 151         raw = self.raw
 152         pagename = formatter.page.page_name
 153 
 154         out = StringIO.StringIO()
 155         self.request.redirect(out)
 156         wikiizer = wiki.Parser(raw, self.request)
 157         wikiizer.format(formatter)
 158         result = out.getvalue()
 159         self.request.redirect()
 160         del out
 161         
 162         if self.position in ['static', 'absolute', 'relative', 'fixed', 'inherit']:
 163            position =  self.position
 164         else:
 165            position = 'relative'
 166            
 167         if self.thick in ['thin', 'medium',' thick', '1px', '2px', '5px', '10px']:
 168            thick = self.thick
 169         else: 
 170            thick = '0'
 171            
 172         if self.text_align in ['left', 'right', 'center', 'justify']:
 173            text_align = self.text_align
 174         else:
 175            text_align = 'left'   
 176            
 177         if self.style in ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double',
 178                           'groove', 'ridge', 'inset', 'outset']:
 179            style = self.style    
 180         else:
 181            style = 'solid'   
 182                          
 183         if self.color != 'transparent':
 184             color = Color(str(self.color))
 185         else:
 186             color = 'black'
 187             
 188         if self.background != 'transparent':
 189            background = Color(str(self.background))
 190         else:
 191            background = 'transparent'
 192            
 193         if self.width.endswith("%"):
 194             width = str(float(self.width[:-1]))+'%'
 195         else:
 196             width = 'auto'   
 197             
 198         if self.padding.endswith("em"):
 199             padding = str(float(self.padding[:-2]))+'em'
 200         else:
 201             padding = '0em'       
 202             
 203         if self.margin.endswith("em"):
 204             margin = str(float(self.margin[:-2]))+'em'
 205         else:
 206             margin = '0em'         
 207             
 208         if self.text_font_size in ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large',
 209                                    'smaller', 'larger']:
 210             text_font_size = self.text_font_size
 211         else:
 212             text_font_size = ''
 213             
 214         if self.text_color != 'transparent':
 215             text_color = Color(str(self.text_color))
 216         else:
 217             text_color = 'black'    
 218             
 219         url = ''    
 220         if self.background_image != None: 
 221             attachment_path = AttachFile.getAttachDir(self.request, pagename)  
 222             file = os.path.join(attachment_path,self.background_image)
 223             if os.path.exists(file):
 224                 mime_type, enc = mimetypes.guess_type(file)
 225                 if mime_type.startswith('image'):
 226                     url = AttachFile.getAttachUrl(pagename, self.background_image, self.request)
 227         
 228         if self.background_repeat in ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']:
 229             background_repeat = self.background_repeat
 230         else:
 231             background_repeat = 'no-repeat'    
 232             
 233         if self.align in ['left', 'right', 'center', 'justify']:
 234             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">' % { 
 235                     "thick": thick,
 236                     "style": style,
 237                     "color": color,
 238                     "position": position,
 239                     "padding": padding,
 240                     "margin": margin,
 241                     "background": background,
 242                     "width": width,
 243                     "text_align": text_align,
 244                     "text_font_size": text_font_size,
 245                     "text_color": text_color,
 246                     "background_image": url,
 247                     "background_repeat": background_repeat,
 248                     "align": self.align,
 249                     }
 250             self.request.write("%(div)s%(result)s</div>" % {
 251                  "div": div,
 252                  "result": result}) 
 253         
 254         if self.align in ['float:left','float:right']:         
 255             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;">' % {
 256                     "align": self.align,
 257                     "text_font_size": text_font_size,
 258                     "text_align": text_align,
 259                     "text_color": text_color,
 260                     "position": position,
 261                     "width": width,
 262                     "thick": thick,
 263                     "background": background,
 264                     "background_image": url,
 265                     "background_repeat": background_repeat,
 266                 } 
 267             self.request.write("%(tab)s%(result)s</td></tr></tbody></table>" % {
 268                                "tab": tab,
 269                                "result": result})  
 270             
 271         if self.align == 'clear':
 272             self.request.write('<br clear="both">')                        
 273             
 274                  
 275             
 276             
 277         
 278         
 279         
 280         
 281         

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.