From ae518e2c1f2e6cb7a519d44127deb2e4d255df72 Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Tue, 24 Jun 2008 09:21:36 +0545 Subject: [PATCH] Add support for external macros --- geekigeeki.py | 69 +++++++------------------------------------- macros/HttpGet.py | 6 ++++ macros/Include.py | 3 ++ macros/TitleIndex.py | 14 +++++++++ macros/WordIndex.py | 31 ++++++++++++++++++++ 5 files changed, 64 insertions(+), 59 deletions(-) create mode 100755 macros/HttpGet.py create mode 100755 macros/Include.py create mode 100755 macros/TitleIndex.py create mode 100755 macros/WordIndex.py diff --git a/geekigeeki.py b/geekigeeki.py index ca59dcc..b2e2895 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -264,61 +264,6 @@ def send_footer(name, mod_string=None): print '

last modified %s

' % mod_string print '' -# Macros ------------------------------------------------------------ -def _macro_HttpGet(argv): - if argv[1] in form: - return form[argv[1]].value - elif len(argv) > 2: - return argv[2] # default value - return '' - -def _macro_WordIndex(argv): - s = make_index_key() - pages = list(page_list()) - map = {} - word_re = re.compile('[A-Z][a-z]+') - for name in pages: - for word in word_re.findall(name): - try: - map[word].append(name) - except KeyError: - map[word] = [name] - - all_words = map.keys() - all_words.sort() - last_letter = None - # set title - for word in all_words: - letter = word[0].lower() - if letter != last_letter: - s = s + ';

%s

' % (letter, letter) - last_letter = letter - - s = s + '%s' - return s - -def _macro_TitleIndex(argv): - s = make_index_key() - pages = list(page_list()) - pages.sort() - current_letter = None - for name in pages: - letter = name[0].lower() - if letter != current_letter: - s += '

%s

' % (letter, letter) - current_letter = letter - else: - s += '
' - s += Page(name).link_to() - return s - class PageFormatter: """Object that turns Wiki markup into HTML. @@ -388,6 +333,9 @@ class PageFormatter: argv = map(str.strip, argv) macro = globals().get('_macro_' + name) + if not macro: + execfile("macros/" + name + ".py", globals()) + macro = globals().get('_macro_' + name) if macro: return macro(argv) else: @@ -653,6 +601,12 @@ class Page: def can_read(self): return self.can("read", True) + def send_naked(self): + if self.can_read(): + PageFormatter(self.get_raw_body()).print_html() + else: + send_guru("Read access denied by ACLs", "notice") + def send_page(self): page_name = None if self.can_write(): @@ -663,10 +617,7 @@ class Page: css_url = self.get_attr("css", "").split() + css_url send_title(page_name, self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type) - if self.can_read(): - PageFormatter(self.get_raw_body()).print_html() - else: - send_guru("Read access denied by ACLs", "notice") + self.send_naked() send_footer(page_name, self._last_modified()) def _last_modified(self): diff --git a/macros/HttpGet.py b/macros/HttpGet.py new file mode 100755 index 0000000..7a4b548 --- /dev/null +++ b/macros/HttpGet.py @@ -0,0 +1,6 @@ +def _macro_HttpGet(argv): + if argv[1] in form: + return form[argv[1]].value + elif len(argv) > 2: + return argv[2] # default value + return '' diff --git a/macros/Include.py b/macros/Include.py new file mode 100755 index 0000000..d46faf2 --- /dev/null +++ b/macros/Include.py @@ -0,0 +1,3 @@ +def _macro_Include(argv): + Page(argv[1]).send_naked() + return '' diff --git a/macros/TitleIndex.py b/macros/TitleIndex.py new file mode 100755 index 0000000..04d5019 --- /dev/null +++ b/macros/TitleIndex.py @@ -0,0 +1,14 @@ +def _macro_TitleIndex(argv): + s = make_index_key() + pages = list(page_list()) + pages.sort() + current_letter = None + for name in pages: + letter = name[0].lower() + if letter != current_letter: + s += '

%s

' % (letter, letter) + current_letter = letter + else: + s += '
' + s += Page(name).link_to() + return s diff --git a/macros/WordIndex.py b/macros/WordIndex.py new file mode 100755 index 0000000..81cd0f9 --- /dev/null +++ b/macros/WordIndex.py @@ -0,0 +1,31 @@ +def _macro_WordIndex(argv): + s = make_index_key() + pages = list(page_list()) + map = {} + word_re = re.compile('[A-Z][a-z]+') + for name in pages: + for word in word_re.findall(name): + try: + map[word].append(name) + except KeyError: + map[word] = [name] + + all_words = map.keys() + all_words.sort() + last_letter = None + # set title + for word in all_words: + letter = word[0].lower() + if letter != last_letter: + s = s + ';

%s

' % (letter, letter) + last_letter = letter + + s = s + '%s' + return s -- 2.25.1