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

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.