# HG changeset patch # User Paul Boddie # Date 1224890253 -7200 # Node ID c4bb1bf2b9d7b60dd6428a0110d07137c2c0b1ed # Parent ea2b15c9eb9c71bca862f6318eabb4c610fbbac1 Made the RSS link in the theme module compatible with 1.5.x and 1.6.x through the use of a default parameter. Added the CategoryMenu macro and styles. diff -r ea2b15c9eb9c -r c4bb1bf2b9d7 macros/CategoryMenu.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/macros/CategoryMenu.py Sat Oct 25 01:17:33 2008 +0200 @@ -0,0 +1,163 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - CategoryMenu Macro + + @copyright: 2008 by Paul Boddie + @copyright: 2000-2004 Juergen Hermann , + 2005-2008 MoinMoin:ThomasWaldmann. + @license: GNU GPL (v2 or later), see COPYING.txt for details. +""" + +from MoinMoin.Page import Page +from MoinMoin import wikiutil, search, version +import re + +category_regexp = None + +Dependencies = ['pages'] + +def isMoin15(): + return version.release.startswith("1.5.") + +def getCategoryPattern(request): + global category_regexp + + try: + return request.cfg.cache.page_category_regexact + except AttributeError: + + # Use regular expression from MoinMoin 1.7.1 otherwise. + + if category_regexp is None: + category_regexp = re.compile(u'^%s$' % ur'(?PCategory(?P(?!Template)\S+))', re.UNICODE) + return category_regexp + +def getCategories(request): + + """ + From the AdvancedSearch macro, return a list of category page names using + the given 'request'. + """ + + # This will return all pages with "Category" in the title. + + cat_filter = getCategoryPattern(request).search + pagenames = request.rootpage.getPageList(filter=cat_filter) + pagenames.sort() + return pagenames + +def getCategoryMapping(category_pagenames, request): + + """ + For the given 'category_pagenames' return a list of tuples of the form + (category name, category page name) using the given 'request'. + """ + + cat_pattern = getCategoryPattern(request) + mapping = [] + for pagename in category_pagenames: + name = cat_pattern.match(pagename).group("key") + if name != "Category": + mapping.append((name, pagename)) + mapping.sort() + return mapping + +def getPages(pagename, request): + + "Return the links minus category links for 'pagename' using the 'request'." + + query = search.QueryParser().parse_query('"%s"' % pagename) + if isMoin15(): + results = search.searchPages(request, query) + results.sortByPagename() + else: + results = search.searchPages(request, query, "page_name") + + cat_pattern = getCategoryPattern(request) + pages = [] + for page in results.hits: + if not cat_pattern.match(page.page_name): + pages.append(page) + return pages + +def execute(macro, args): + request = macro.request + fmt = macro.formatter + page = fmt.page + + # Interpret the arguments. + + try: + selected_category_names = wikiutil.parse_quoted_separated(args, name_value=False) + except AttributeError: + selected_category_names = args.split(",") + + selected_category_names = [arg for arg in selected_category_names if arg] + + # Get the categories. + + categories = getCategoryMapping(getCategories(request), request) + + # Generate a menu with the categories, together with expanded submenus for + # the categories employed by the current page, the category represented by + # the current page, or for those categories specified in the macro + # arguments. + + output = [] + output.append(fmt.bullet_list(on=1, attr={"class" : "category-menu"})) + + for category in categories: + category_name, category_pagename = category + + pages_in_category = getPages(category_pagename, request) + pagenames_in_category = [p.page_name for p in pages_in_category] + page_is_category = page.page_name == category_pagename + + # Generate the submenu where appropriate. + + if selected_category_names and category_name in selected_category_names or \ + not selected_category_names and ( + page_is_category or page.page_name in pagenames_in_category): + + if page_is_category: + output.append(fmt.listitem(on=1, attr={"class" : "selected current"})) + output.append(fmt.text(category_name)) + else: + output.append(fmt.listitem(on=1, attr={"class" : "selected"})) + output.append(fmt.pagelink(on=1, pagename=category_pagename)) + output.append(fmt.text(category_name)) + output.append(fmt.pagelink(on=0, pagename=category_pagename)) + + output.append(fmt.bullet_list(on=1, attr={"class" : "category-submenu"})) + + # Visit each page in the category. + + for page_in_category in pages_in_category: + pagename = page_in_category.page_name + + if page.page_name == pagename: + output.append(fmt.listitem(on=1, attr={"class" : "selected"})) + else: + output.append(fmt.listitem(on=1)) + output.append(fmt.pagelink(on=1, pagename=pagename)) + output.append(fmt.text(pagename)) + output.append(fmt.pagelink(on=0, pagename=pagename)) + output.append(fmt.listitem(on=0)) + + output.append(fmt.bullet_list(on=0)) + output.append(fmt.listitem(on=0)) + + # Otherwise generate a simple link. + + else: + output.append(fmt.listitem(on=1)) + output.append(fmt.pagelink(on=1, pagename=category_pagename)) + output.append(fmt.text(category_name)) + output.append(fmt.pagelink(on=0, pagename=category_pagename)) + output.append(fmt.listitem(on=0)) + + output.append(fmt.bullet_list(on=0)) + + return ''.join(output) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r ea2b15c9eb9c -r c4bb1bf2b9d7 themes/ep2008/css/category.css --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/themes/ep2008/css/category.css Sat Oct 25 01:17:33 2008 +0200 @@ -0,0 +1,58 @@ +/* category.css - some additional styles for the CategoryMenu macro + which can be included in the screen.css using + @import "category.css"; + +Copyright (c) 2008 by Paul Boddie +Licensed under the GNU GPL (v2 or later), see COPYING.txt for details. +*/ + +/* Category menus... */ + +ul.category-menu { + list-style: none; + margin-left: 0; + padding-left: 0; + width: 20em; +} + +ul.category-submenu { + list-style: none; + margin-left: 0; + padding-left: 0; + padding-top: 0.25em; +} + +ul.category-menu li { + list-style: none; + padding: 0.25em; + background-color: #073683; + color: white; +} + +ul.category-menu a, +ul.category-menu a:visited, +ul.category-menu a:hover { + text-decoration: none; + color: white; +} + +ul.category-menu li.selected, +ul.category-menu li:hover { + background-color: #10adf7; +} + +ul.category-submenu li.selected { + background-color: #073683; +} + +ul.category-menu li.current, +ul.category-submenu li.selected { + font-weight: bold; +} + +ul.category-submenu li { + font-weight: normal; +} + +/* vim: tabstop=4 expandtab shiftwidth=4 + */ diff -r ea2b15c9eb9c -r c4bb1bf2b9d7 themes/ep2008/css/screen.css --- a/themes/ep2008/css/screen.css Sun Oct 19 00:40:20 2008 +0200 +++ b/themes/ep2008/css/screen.css Sat Oct 25 01:17:33 2008 +0200 @@ -1,9 +1,13 @@ /* screen.css - MoinMoin Default Styles Copyright (c) 2001, 2002, 2003 by Juergen Hermann -Copyright (c) 2007 by Paul Boddie +Copyright (c) 2007, 2008 by Paul Boddie */ +/* Category menus... */ + +@import "category.css"; + /* content styles */ /* debug diff -r ea2b15c9eb9c -r c4bb1bf2b9d7 themes/ep2008/ep2008.py --- a/themes/ep2008/ep2008.py Sun Oct 19 00:40:20 2008 +0200 +++ b/themes/ep2008/ep2008.py Sat Oct 25 01:17:33 2008 +0200 @@ -14,7 +14,7 @@ name = "ep2008" - def rsslink(self, d): + def rsslink(self, d=None): """ Create rss link in head, used by FireFox RSS link for FireFox. This shows an rss link in the bottom of @@ -25,7 +25,10 @@ """ extra_rss = self.cfg.extra_rss - return ThemeBase.rsslink(self, d) + u'\n' + extra_rss + if d is not None: + return ThemeBase.rsslink(self, d) + u'\n' + extra_rss + else: + return ThemeBase.rsslink(self) + u'\n' + extra_rss def header(self, d, **kw): """ Assemble wiki header