Attachment 'Columns-1.9.x.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(columnCount, [start|end])>>
  17 
  18         columnCount    2-10 total number of columns (used primarily to calculate column width)
  19 
  20         start          pass "start" as the second argument to define the first column
  21         
  22         end            pass "end" as the second argument to define the last column
  23 
  24     Examples:
  25 
  26         <<Columns(3, start)>>
  27                 This text is in the left column.
  28         <<Columns(3)>>
  29                 This text is in the middle column.
  30         <<Columns(3)>>
  31                 This text is in the right column.
  32         <<Columns(3, end)>>
  33 
  34 
  35     Demo. Try pasting the above examples into a MoinMoin sandbox page.
  36 
  37     @copyright: Antti Kuntsi <antti@kuntsi.com>
  38     @license: GNU GPL, see COPYING for details.
  39 
  40     changes:
  41         12.2007 - conversion to new syntax by Bolesław Kulbabiński
  42         03.2010 - Moved CSS to inline for easier installation. Autocompute styles and widths to handle arbirtary numbers of columns without manual CSS editing. Updates by Peter Lyons
  43         03.2011 - some small PEP8 fixes, dependency to string object removed, not needed modules removed. Updates by MoinMoin:ReimarBauer
  44 """
  45 import sys
  46 
  47 from MoinMoin.wikiutil import required_arg
  48 
  49 #Feel free to increase this if you really can use more than 10 columns.
  50 #It's just an arbitrary reasonable limit
  51 MAX_COLUMNS = 10
  52 rangeStrings = [unicode(x) for x in range(1, MAX_COLUMNS + 1)]
  53 
  54 #Feel free to adjust this if needed. Could be added as a wiki markup parameter
  55 MARGIN_WIDTH = 1
  56 COLUMN_TEMPLATE = """
  57 <!-- output generated by the Columns macro Version -->
  58 <style>
  59 div.column_%(columnCount)s {
  60     float: left;
  61     width: %(columnWidth)s%%;
  62     margin-left: %(marginWidth)s%%;
  63 }
  64 </style>
  65 <div class="column_%(columnCount)s">
  66 """
  67 
  68 def macro_Columns(macro, columnCount=required_arg(rangeStrings),
  69         startOrEnd=("", "start", "end")):
  70     tags = []
  71     if startOrEnd != "start":
  72         tags.append("\n</div><!--end column -->\n")
  73     if startOrEnd != "end":
  74         columnWidth = int(100 / int(columnCount)) - MARGIN_WIDTH
  75         tags.append(COLUMN_TEMPLATE % {
  76             "columnWidth": columnWidth,
  77             "columnCount": columnCount,
  78             "marginWidth": MARGIN_WIDTH
  79             })
  80     if startOrEnd == "end":
  81         tags.append('\n<br clear="left"/>')
  82     if macro:
  83         result = [macro.formatter.rawHTML("".join(tags))]
  84     else:
  85         result = tags
  86     return "".join(result)
  87 
  88 #Facilititates quick testing on the command line        
  89 if __name__ == "__main__":
  90     print macro_Columns(None, *sys.argv[1:])

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.