Attachment 'text_x_frame-1.6.0-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.6.0-3 2006-08-15 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 text_moin_wiki
 110 from MoinMoin import wikiutil
 111 from MoinMoin.action import AttachFile
 112 from MoinMoin.util import web
 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         for arg in kw.get('format_args', '').split(','):
 142             if arg.find('=') > -1:
 143                 key, value = arg.split('=')
 144                 setattr(self, key, wikiutil.escape(value.strip(), quote=1))
 145 
 146 
 147     def format(self, formatter):
 148         raw = self.raw
 149         pagename = formatter.page.page_name
 150 
 151         out = StringIO.StringIO()
 152         self.request.redirect(out)
 153         wikiizer = text_moin_wiki.Parser(raw, self.request)
 154         wikiizer.format(formatter)
 155         result = out.getvalue()
 156         self.request.redirect()
 157         del out
 158 
 159         if self.position in ['static', 'absolute', 'relative', 'fixed', 'inherit']:
 160             position = self.position
 161         else:
 162             position = 'relative'
 163 
 164         if self.thick in ['thin', 'medium', 'thick', '1px', '2px', '5px', '10px']:
 165             thick = self.thick
 166         else:
 167             thick = '0'
 168 
 169         if self.text_align in ['left', 'right', 'center', 'justify']:
 170             text_align = self.text_align
 171         else:
 172            text_align = 'left'
 173 
 174         if self.style in ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double',
 175                           'groove', 'ridge', 'inset', 'outset']:
 176             style = self.style
 177         else:
 178             style = 'solid'
 179 
 180         if self.color != 'transparent':
 181             color = web.Color(str(self.color))
 182         else:
 183             color = 'black'
 184 
 185         if self.background != 'transparent':
 186             background = web.Color(str(self.background))
 187         else:
 188             background = 'transparent'
 189 
 190         if self.width.endswith("%"):
 191             width = str(float(self.width[:-1]))+'%'
 192         else:
 193             width = 'auto'
 194 
 195         if self.padding.endswith("em"):
 196             padding = str(float(self.padding[:-2]))+'em'
 197         else:
 198             padding = '0em'
 199 
 200         if self.margin.endswith("em"):
 201             margin = str(float(self.margin[:-2]))+'em'
 202         else:
 203             margin = '0em'
 204 
 205         if self.text_font_size in ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large',
 206                                    'smaller', 'larger']:
 207             text_font_size = self.text_font_size
 208         else:
 209             text_font_size = ''
 210 
 211         if self.text_color != 'transparent':
 212             text_color = web.Color(str(self.text_color))
 213         else:
 214             text_color = 'black'
 215 
 216         url = ''
 217         if self.background_image != None:
 218             attachment_path = AttachFile.getAttachDir(self.request, pagename)
 219             file = os.path.join(attachment_path, self.background_image)
 220             if os.path.exists(file):
 221                 mime_type, enc = mimetypes.guess_type(file)
 222                 if mime_type.startswith('image'):
 223                     url = AttachFile.getAttachUrl(pagename, self.background_image, self.request)
 224 
 225         if self.background_repeat in ['repeat', 'repeat-x', 'repeat-y', 'no-repeat']:
 226             background_repeat = self.background_repeat
 227         else:
 228             background_repeat = 'no-repeat'
 229 
 230         if self.align in ['left', 'right', 'center', 'justify']:
 231             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">' % {
 232                     "thick": thick,
 233                     "style": style,
 234                     "color": color,
 235                     "position": position,
 236                     "padding": padding,
 237                     "margin": margin,
 238                     "background": background,
 239                     "width": width,
 240                     "text_align": text_align,
 241                     "text_font_size": text_font_size,
 242                     "text_color": text_color,
 243                     "background_image": url,
 244                     "background_repeat": background_repeat,
 245                     "align": self.align,
 246                     }
 247             self.request.write("%(div)s%(result)s</div>" % {
 248                  "div": div,
 249                  "result": result})
 250 
 251         if self.align in ['float:left', 'float:right']:
 252             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;">' % {
 253                     "align": self.align,
 254                     "text_font_size": text_font_size,
 255                     "text_align": text_align,
 256                     "text_color": text_color,
 257                     "position": position,
 258                     "width": width,
 259                     "thick": thick,
 260                     "background": background,
 261                     "background_image": url,
 262                     "background_repeat": background_repeat,
 263                 }
 264             self.request.write("%(tab)s%(result)s</td></tr></tbody></table>" % {
 265                                "tab": tab,
 266                                "result": result})
 267 
 268         if self.align == 'clear':
 269             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.