Attachment 'variable-columns.patch'

Download

   1 --- Columns-1.9.x.py	2011-09-30 11:38:46.605559472 -0500
   2 +++ Columns-variable.py	2011-09-30 11:43:50.731067569 -0500
   3 @@ -13,7 +13,7 @@
   4      columns.
   5  
   6      Usage:
   7 -        <<Columns(columnCount, [start|end])>>
   8 +        <<Columns(columnCount, [start|end], [width%])>>
   9  
  10          columnCount    2-10 total number of columns (used primarily to calculate column width)
  11  
  12 @@ -21,7 +21,9 @@
  13          
  14          end            pass "end" as the second argument to define the last column
  15  
  16 -    Examples:
  17 +        width%         columns can be done with variable widths
  18 +
  19 +    Example 1:
  20  
  21          <<Columns(3, start)>>
  22                  This text is in the left column.
  23 @@ -31,6 +33,14 @@
  24                  This text is in the right column.
  25          <<Columns(3, end)>>
  26  
  27 +    Example 2:
  28 +        <<Columns(3, start, 60)>>
  29 +        This is a wide column
  30 +        <<Columns(3, "", 5)>>
  31 +          
  32 +        <<Columns(3, "", 30)>> 
  33 +        this is a narrow column with column 2 giving some spacing
  34 +        <<Columns(3, end)>>
  35  
  36      Demo. Try pasting the above examples into a MoinMoin sandbox page.
  37  
  38 @@ -56,25 +66,25 @@
  39  COLUMN_TEMPLATE = """
  40  <!-- output generated by the Columns macro Version -->
  41  <style>
  42 -div.column_%(columnCount)s {
  43 +div.column_%(columnWidth)s {
  44      float: left;
  45      width: %(columnWidth)s%%;
  46 -    margin-left: %(marginWidth)s%%;
  47 +    margin-right: %(marginWidth)s%%;
  48  }
  49  </style>
  50 -<div class="column_%(columnCount)s">
  51 +<div class="column_%(columnWidth)s">
  52  """
  53  
  54  def macro_Columns(macro, columnCount=required_arg(rangeStrings),
  55 -        startOrEnd=("", "start", "end")):
  56 +        startOrEnd=("", "start", "end"), columnWidth=0):
  57      tags = []
  58      if startOrEnd != "start":
  59          tags.append("\n</div><!--end column -->\n")
  60      if startOrEnd != "end":
  61 -        columnWidth = int(100 / int(columnCount)) - MARGIN_WIDTH
  62 +        if columnWidth is 0:
  63 +            columnWidth = int(100 / int(columnCount)) - MARGIN_WIDTH
  64          tags.append(COLUMN_TEMPLATE % {
  65              "columnWidth": columnWidth,
  66 -            "columnCount": columnCount,
  67              "marginWidth": MARGIN_WIDTH
  68              })
  69      if startOrEnd == "end":
  70 @@ -85,6 +95,6 @@
  71          result = tags
  72      return "".join(result)
  73  
  74 -#Facilititates quick testing on the command line        
  75 +#Facilititates quick testing on the command line
  76  if __name__ == "__main__":
  77      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.