# Moin macro to produce a table indicating for which variant(s) of Ubuntu and # which version(s) the article is valid. # # Copyright (C) 2009 Roel Huybrechts # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Moin macro to produce a table indicating for which variant(s) of Ubuntu and which version(s) the article is valid. The first row can be a reference to the main article in case of a subpage. The following row indicates the valid variant(s) by showing the icons accordingly. Thirdly the valid versions are listed and the table ends with a TableOfContents. """ from MoinMoin import wikiutil from MoinMoin.wikiutil import required_arg def macro_GeschiktVoor(macro, variant=required_arg(unicode), version=required_arg(unicode), subpage=None): """ Arguments: macro: Macro instance, automatically filled in by Moin. variant: Combination of 'ubuntu', 'kubuntu', 'xubuntu', 'server' or 'all'. version: Version for which the article is valid. subpage: If not empty, link to the superpage (main article) of this page. """ variants = [[['ubuntu', 'gnome'], 'StartPagina/ubuntu.png', 'Ubuntu, GNOME'], [['kubuntu', 'kde'], 'StartPagina/kubuntu.png', 'Kubuntu, KDE'], [['xubuntu', 'xfce'], 'StartPagina/xubuntu.png', 'Xubuntu, XFCE'], [['server', 'commando'], 'StartPagina/ubuntuserver.png', 'Ubuntu Server, opdrachtregel']] result = [] #Start table result.append(macro.formatter.table(True, {'tablestyle': '"float:right; background-color: #F7F6F5;"'})) #Start row result.append(macro.formatter.table_row(True, {'rowstyle' : '"background-color: #DD4814;"'})) if subpage: #Start cell result.append(macro.formatter.table_cell(True, {'style': '"border-color: #ffffff; text-align: center;"'}, colspan=2)) #Cell contents result.append(macro.formatter.emphasis(True) + macro.formatter.text("Dit is een onderdeel van een groter ") + macro.formatter.pagelink(True, wikiutil.AbsPageName(macro.formatter.page.page_name, subpage)) + macro.formatter.text("artikel") + macro.formatter.pagelink(False) + macro.formatter.text(".") + macro.formatter.emphasis(False)) #Close cell and row result.append(macro.formatter.table_cell(False) + macro.formatter.table_row(False)) #Start row result.append(macro.formatter.table_row(True, {'rowstyle' : '"background-color: #DD4814;"'})) #Start cell result.append(macro.formatter.table_cell(True, {'style': '"border-color: #ffffff; border-right-width: 0px;"'})) #Cell contents result.append(macro.formatter.strong(True) + macro.formatter.text("Geschikt voor:") + macro.formatter.strong(False)) #Close cell result.append(macro.formatter.table_cell(False)) #Start cell result.append(macro.formatter.table_cell(True, {'style': '"border-color: #ffffff; border-left-width: 0px; ' + 'text-align: right;"'})) #Cell contents added = [] for item in variants: for var in variant.split(','): var = var.strip().lower() if ((var in item[0]) or (var == 'all')) and not item[0] in added: added.append(item[0]) result.append(macro.formatter.attachment_image(item[1], title=item[2])) result.append(macro.formatter.text(' ')) #Close cell and row result.append(macro.formatter.table_cell(False)) result.append(macro.formatter.table_row(False)) #Start row result.append(macro.formatter.table_row(True, {'rowstyle' : '"background-color: #DD4814;"'})) #Start cell result.append(macro.formatter.table_cell(True, {'style': '"border-color: #ffffff; border-right-width: 0px;"'})) #Cell contents result.append(macro.formatter.strong(True) + macro.formatter.text("Versie:") + macro.formatter.strong(False)) #Close cell result.append(macro.formatter.table_cell(False)) #Start cell result.append(macro.formatter.table_cell(True, {'style': '"border-color: #ffffff; border-left-width: 0px; ' + 'text-align: right;"'})) #Cell contents versions = [] for item in version.split(','): item = item.replace(' lts', ' LTS') versions.append(item.strip()) versions.sort(compare_versions) result.append(macro.formatter.text(', '.join(versions))) #Close cell and row result.append(macro.formatter.table_cell(False)) result.append(macro.formatter.table_row(False)) #Start row result.append(macro.formatter.table_row(True)) #Start cell result.append(macro.formatter.table_cell(True, {'style': '"border-color: #ffffff;'}, colspan=2)) #Cell contents result.append(macro.execute('TableOfContents', u'maxdepth=3')) #Close cell and row result.append(macro.formatter.table_cell(False)) result.append(macro.formatter.table_row(False)) #Close table result.append(macro.formatter.table(False)) return "".join(result) def compare_versions(x, y): return cmp(float(x.split()[0]), float(y.split()[0]))