Attachment 'Columns-1.6.py'

Download

   1 # -*- coding: utf-8 -*-
   2 """
   3     MoinMoin - macro to specify columns
   4 
   5     As far as the author is concerned, this code is released to the public
   6     domain, but some restrictions in the MoinMoin COPYING file may apply. Ask a
   7     lawyer.
   8     ***********
   9     This code has not been tested exhaustively. Use at your own risk.
  10     ***********
  11 
  12     This macro generates containers, that can be used with CSS to create
  13     columns.
  14 
  15     Usage:
  16         <<Columns(mode,name,keywordargs)>>
  17 
  18         mode            start, next or end.
  19 
  20         name            Name of the div id. <div id="name">
  21 
  22         keywordargs     Zero or more key="value" arguments for the HTML div
  23                         tag.
  24 
  25     Examples:
  26 
  27         <<Columns(start, leftcolumn)>>
  28                 This text is in the left column.
  29         <<Columns(next, rightcolumn)>>
  30                 This text is in the right column.
  31         <<Columns(end)>>
  32 
  33     requires class definitions in CSS for the used column names, eg
  34 
  35     #leftcolumn {
  36         position: relative;
  37         background: transparent;
  38         float: left;
  39         width: 45%;
  40         border-right: 1px solid gray;
  41         padding-left: 5%;
  42         padding-right: 1%;
  43         margin: 0px;
  44     }
  45 
  46     #rightcolumn {
  47         position: relative;
  48         background: transparent;
  49         float: right;
  50         width: 42%;
  51         padding-right: 1%;
  52         margin: 0px;
  53     }
  54 
  55     Demo. Try pasting the above examples into a MoinMoin sandbox page and the
  56     current CSS.
  57 
  58     @copyright: Antti Kuntsi <antti@kuntsi.com>
  59     @license: GNU GPL, see COPYING for details.
  60 
  61     changes:
  62         12.2007 - conversion to new syntax by Bolesław Kulbabiński
  63 """
  64 
  65 from MoinMoin import wikiutil, config
  66 
  67 DEFAULT_KEYWORD_ARGS = {}
  68 
  69 def macro_Columns(macro, mode=('start', 'next', 'end'), name=unicode, _kwargs=None):
  70     # handle the Columns Macro. return the generated display HTML
  71 
  72     if mode != 'end':
  73         classname = name.strip()
  74     else:
  75         classname = ''
  76 
  77     # update keyword arguments
  78     kwargs = DEFAULT_KEYWORD_ARGS
  79     if _kwargs is not None:
  80         kwargs.update(_kwargs)
  81 
  82     # generate a string containing the keyword arguments
  83     kwstring = ''
  84     for key in kwargs.keys():
  85         kwstring = '%s %s="%s"' % (kwstring, key, kwargs[key])
  86 
  87     # generate a string specifying the location of the image
  88     divtag = ''
  89     if mode in ('end', 'next'):
  90             divtag += '</div>'
  91             if mode == 'end':
  92                 divtag += '<br clear="both">'
  93     if mode in ('start', 'next'):
  94             divtag += '<div id="%s"%s>' % (classname, kwstring)
  95 
  96     # combine target location, image location, and keyword arguments into HTML IMG tag
  97     result = [macro.formatter.paragraph(0),
  98               macro.formatter.rawHTML(divtag),
  99               macro.formatter.paragraph(1)]
 100 
 101     return "".join(result)
 102 
 103 
 104 def execute(macro, args):
 105     try:
 106         return wikiutil.invoke_extension_function(
 107                    macro.request, macro_Columns, args, [macro])
 108     except ValueError, err:
 109         return macro.request.formatter.text(
 110                    "<<Columns: %s>>" % err.args[0])

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] (2007-12-22 18:49:23, 3.0 KB) [[attachment:Columns-1.6.py]]
  • [get | view] (2010-03-07 17:08:44, 2.9 KB) [[attachment:Columns-1.8.4.py]]
  • [get | view] (2011-03-07 09:02:25, 2.9 KB) [[attachment:Columns-1.9.x.py]]
  • [get | view] (2004-06-14 13:14:13, 4.8 KB) [[attachment:Columns.py]]
  • [get | view] (2006-03-22 21:53:27, 0.4 KB) [[attachment:columns-macro.diff]]
  • [get | view] (2011-09-30 16:51:02, 2.3 KB) [[attachment:variable-columns.patch]]
 All files | Selected Files: delete move to page copy to page

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