1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/macros/CategoryMenu.py Sat Oct 25 01:17:33 2008 +0200
1.3 @@ -0,0 +1,163 @@
1.4 +# -*- coding: iso-8859-1 -*-
1.5 +"""
1.6 + MoinMoin - CategoryMenu Macro
1.7 +
1.8 + @copyright: 2008 by Paul Boddie <paul@boddie.org.uk>
1.9 + @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
1.10 + 2005-2008 MoinMoin:ThomasWaldmann.
1.11 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.12 +"""
1.13 +
1.14 +from MoinMoin.Page import Page
1.15 +from MoinMoin import wikiutil, search, version
1.16 +import re
1.17 +
1.18 +category_regexp = None
1.19 +
1.20 +Dependencies = ['pages']
1.21 +
1.22 +def isMoin15():
1.23 + return version.release.startswith("1.5.")
1.24 +
1.25 +def getCategoryPattern(request):
1.26 + global category_regexp
1.27 +
1.28 + try:
1.29 + return request.cfg.cache.page_category_regexact
1.30 + except AttributeError:
1.31 +
1.32 + # Use regular expression from MoinMoin 1.7.1 otherwise.
1.33 +
1.34 + if category_regexp is None:
1.35 + category_regexp = re.compile(u'^%s$' % ur'(?P<all>Category(?P<key>(?!Template)\S+))', re.UNICODE)
1.36 + return category_regexp
1.37 +
1.38 +def getCategories(request):
1.39 +
1.40 + """
1.41 + From the AdvancedSearch macro, return a list of category page names using
1.42 + the given 'request'.
1.43 + """
1.44 +
1.45 + # This will return all pages with "Category" in the title.
1.46 +
1.47 + cat_filter = getCategoryPattern(request).search
1.48 + pagenames = request.rootpage.getPageList(filter=cat_filter)
1.49 + pagenames.sort()
1.50 + return pagenames
1.51 +
1.52 +def getCategoryMapping(category_pagenames, request):
1.53 +
1.54 + """
1.55 + For the given 'category_pagenames' return a list of tuples of the form
1.56 + (category name, category page name) using the given 'request'.
1.57 + """
1.58 +
1.59 + cat_pattern = getCategoryPattern(request)
1.60 + mapping = []
1.61 + for pagename in category_pagenames:
1.62 + name = cat_pattern.match(pagename).group("key")
1.63 + if name != "Category":
1.64 + mapping.append((name, pagename))
1.65 + mapping.sort()
1.66 + return mapping
1.67 +
1.68 +def getPages(pagename, request):
1.69 +
1.70 + "Return the links minus category links for 'pagename' using the 'request'."
1.71 +
1.72 + query = search.QueryParser().parse_query('"%s"' % pagename)
1.73 + if isMoin15():
1.74 + results = search.searchPages(request, query)
1.75 + results.sortByPagename()
1.76 + else:
1.77 + results = search.searchPages(request, query, "page_name")
1.78 +
1.79 + cat_pattern = getCategoryPattern(request)
1.80 + pages = []
1.81 + for page in results.hits:
1.82 + if not cat_pattern.match(page.page_name):
1.83 + pages.append(page)
1.84 + return pages
1.85 +
1.86 +def execute(macro, args):
1.87 + request = macro.request
1.88 + fmt = macro.formatter
1.89 + page = fmt.page
1.90 +
1.91 + # Interpret the arguments.
1.92 +
1.93 + try:
1.94 + selected_category_names = wikiutil.parse_quoted_separated(args, name_value=False)
1.95 + except AttributeError:
1.96 + selected_category_names = args.split(",")
1.97 +
1.98 + selected_category_names = [arg for arg in selected_category_names if arg]
1.99 +
1.100 + # Get the categories.
1.101 +
1.102 + categories = getCategoryMapping(getCategories(request), request)
1.103 +
1.104 + # Generate a menu with the categories, together with expanded submenus for
1.105 + # the categories employed by the current page, the category represented by
1.106 + # the current page, or for those categories specified in the macro
1.107 + # arguments.
1.108 +
1.109 + output = []
1.110 + output.append(fmt.bullet_list(on=1, attr={"class" : "category-menu"}))
1.111 +
1.112 + for category in categories:
1.113 + category_name, category_pagename = category
1.114 +
1.115 + pages_in_category = getPages(category_pagename, request)
1.116 + pagenames_in_category = [p.page_name for p in pages_in_category]
1.117 + page_is_category = page.page_name == category_pagename
1.118 +
1.119 + # Generate the submenu where appropriate.
1.120 +
1.121 + if selected_category_names and category_name in selected_category_names or \
1.122 + not selected_category_names and (
1.123 + page_is_category or page.page_name in pagenames_in_category):
1.124 +
1.125 + if page_is_category:
1.126 + output.append(fmt.listitem(on=1, attr={"class" : "selected current"}))
1.127 + output.append(fmt.text(category_name))
1.128 + else:
1.129 + output.append(fmt.listitem(on=1, attr={"class" : "selected"}))
1.130 + output.append(fmt.pagelink(on=1, pagename=category_pagename))
1.131 + output.append(fmt.text(category_name))
1.132 + output.append(fmt.pagelink(on=0, pagename=category_pagename))
1.133 +
1.134 + output.append(fmt.bullet_list(on=1, attr={"class" : "category-submenu"}))
1.135 +
1.136 + # Visit each page in the category.
1.137 +
1.138 + for page_in_category in pages_in_category:
1.139 + pagename = page_in_category.page_name
1.140 +
1.141 + if page.page_name == pagename:
1.142 + output.append(fmt.listitem(on=1, attr={"class" : "selected"}))
1.143 + else:
1.144 + output.append(fmt.listitem(on=1))
1.145 + output.append(fmt.pagelink(on=1, pagename=pagename))
1.146 + output.append(fmt.text(pagename))
1.147 + output.append(fmt.pagelink(on=0, pagename=pagename))
1.148 + output.append(fmt.listitem(on=0))
1.149 +
1.150 + output.append(fmt.bullet_list(on=0))
1.151 + output.append(fmt.listitem(on=0))
1.152 +
1.153 + # Otherwise generate a simple link.
1.154 +
1.155 + else:
1.156 + output.append(fmt.listitem(on=1))
1.157 + output.append(fmt.pagelink(on=1, pagename=category_pagename))
1.158 + output.append(fmt.text(category_name))
1.159 + output.append(fmt.pagelink(on=0, pagename=category_pagename))
1.160 + output.append(fmt.listitem(on=0))
1.161 +
1.162 + output.append(fmt.bullet_list(on=0))
1.163 +
1.164 + return ''.join(output)
1.165 +
1.166 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/themes/ep2008/css/category.css Sat Oct 25 01:17:33 2008 +0200
2.3 @@ -0,0 +1,58 @@
2.4 +/* category.css - some additional styles for the CategoryMenu macro
2.5 + which can be included in the screen.css using
2.6 + @import "category.css";
2.7 +
2.8 +Copyright (c) 2008 by Paul Boddie
2.9 +Licensed under the GNU GPL (v2 or later), see COPYING.txt for details.
2.10 +*/
2.11 +
2.12 +/* Category menus... */
2.13 +
2.14 +ul.category-menu {
2.15 + list-style: none;
2.16 + margin-left: 0;
2.17 + padding-left: 0;
2.18 + width: 20em;
2.19 +}
2.20 +
2.21 +ul.category-submenu {
2.22 + list-style: none;
2.23 + margin-left: 0;
2.24 + padding-left: 0;
2.25 + padding-top: 0.25em;
2.26 +}
2.27 +
2.28 +ul.category-menu li {
2.29 + list-style: none;
2.30 + padding: 0.25em;
2.31 + background-color: #073683;
2.32 + color: white;
2.33 +}
2.34 +
2.35 +ul.category-menu a,
2.36 +ul.category-menu a:visited,
2.37 +ul.category-menu a:hover {
2.38 + text-decoration: none;
2.39 + color: white;
2.40 +}
2.41 +
2.42 +ul.category-menu li.selected,
2.43 +ul.category-menu li:hover {
2.44 + background-color: #10adf7;
2.45 +}
2.46 +
2.47 +ul.category-submenu li.selected {
2.48 + background-color: #073683;
2.49 +}
2.50 +
2.51 +ul.category-menu li.current,
2.52 +ul.category-submenu li.selected {
2.53 + font-weight: bold;
2.54 +}
2.55 +
2.56 +ul.category-submenu li {
2.57 + font-weight: normal;
2.58 +}
2.59 +
2.60 +/* vim: tabstop=4 expandtab shiftwidth=4
2.61 + */
3.1 --- a/themes/ep2008/css/screen.css Sun Oct 19 00:40:20 2008 +0200
3.2 +++ b/themes/ep2008/css/screen.css Sat Oct 25 01:17:33 2008 +0200
3.3 @@ -1,9 +1,13 @@
3.4 /* screen.css - MoinMoin Default Styles
3.5
3.6 Copyright (c) 2001, 2002, 2003 by Juergen Hermann
3.7 -Copyright (c) 2007 by Paul Boddie
3.8 +Copyright (c) 2007, 2008 by Paul Boddie
3.9 */
3.10
3.11 +/* Category menus... */
3.12 +
3.13 +@import "category.css";
3.14 +
3.15 /* content styles */
3.16
3.17 /* debug
4.1 --- a/themes/ep2008/ep2008.py Sun Oct 19 00:40:20 2008 +0200
4.2 +++ b/themes/ep2008/ep2008.py Sat Oct 25 01:17:33 2008 +0200
4.3 @@ -14,7 +14,7 @@
4.4
4.5 name = "ep2008"
4.6
4.7 - def rsslink(self, d):
4.8 + def rsslink(self, d=None):
4.9 """ Create rss link in head, used by FireFox
4.10
4.11 RSS link for FireFox. This shows an rss link in the bottom of
4.12 @@ -25,7 +25,10 @@
4.13 """
4.14
4.15 extra_rss = self.cfg.extra_rss
4.16 - return ThemeBase.rsslink(self, d) + u'\n' + extra_rss
4.17 + if d is not None:
4.18 + return ThemeBase.rsslink(self, d) + u'\n' + extra_rss
4.19 + else:
4.20 + return ThemeBase.rsslink(self) + u'\n' + extra_rss
4.21
4.22 def header(self, d, **kw):
4.23 """ Assemble wiki header