Mercurial > wikked
changeset 27:a42bd59bbe6f
More generic meta properties for wiki pages:
- The page formatter collects all properties.
- Ability to define "flag" properties (properties with no values).
- Support for `notitle` property.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 05 Jan 2013 11:54:03 -0800 |
parents | 8535d63dc1c1 |
children | 1b72f32b19a7 |
files | wikked/static/js/wikked/client.js wikked/static/tpl/read-page.html wikked/wiki.py |
diffstat | 3 files changed, 32 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/wikked/static/js/wikked/client.js Sat Jan 05 11:52:34 2013 -0800 +++ b/wikked/static/js/wikked/client.js Sat Jan 05 11:54:03 2013 -0800 @@ -9,10 +9,13 @@ }, formatText: function(text) { var $f = this; - text = text.replace(/^\[\[([a-z]+)\:\s*(.+)\]\]\s*$/gm, function(m, a, b) { + text = text.replace(/^\[\[((__|\+)?[a-zA-Z][a-zA-Z0-9_\-]+)\:\s*(.*)\]\]\s*$/gm, function(m, a, b, c) { + if (!c) { + c = 'true'; + } var p = "<p><span class=\"preview-wiki-meta\">\n"; p += "<span class=\"meta-name\">" + a + "</span>"; - p += "<span class=\"meta-value\">" + b + "</span>\n"; + p += "<span class=\"meta-value\">" + c + "</span>\n"; p += "</span></p>\n\n"; return p; });
--- a/wikked/static/tpl/read-page.html Sat Jan 05 11:52:34 2013 -0800 +++ b/wikked/static/tpl/read-page.html Sat Jan 05 11:54:03 2013 -0800 @@ -1,6 +1,8 @@ <article class="row"> <div class="page span12"> + {{#ifnot meta.notitle}} <h1>{{meta.title}}</h1> + {{/ifnot}} {{content}} </div> </article>
--- a/wikked/wiki.py Sat Jan 05 11:52:34 2013 -0800 +++ b/wikked/wiki.py Sat Jan 05 11:54:03 2013 -0800 @@ -22,7 +22,11 @@ self.url = url self.ext = ext self.out_links = [] - self.title = None + self.meta = {} + + @property + def urldir(self): + return os.path.dirname(self.url) class PageFormatter(object): @@ -53,9 +57,9 @@ def _processWikiMeta(self, ctx, text): def repl1(m): - ctx.title = m.group(1) + ctx.meta[str(m.group(1))] = str(m.group(3)) if m.group(3) is not None else True return '' - text = re.sub(r'^\[\[title:\s*(.+)\]\]\s*$', repl1, text, flags=re.MULTILINE) + text = re.sub(r'^\[\[((__|\+)?[a-zA-Z][a-zA-Z0-9_\-]+):\s*(.*)\]\]\s*$', repl1, text, flags=re.MULTILINE) return text def _processWikiLinks(self, ctx, text): @@ -76,7 +80,7 @@ return text def _formatWikiLink(self, ctx, display, url): - slug = Page.title_to_url(url) + slug = Page.title_to_url(os.path.join(ctx.urldir, url)) ctx.out_links.append(slug) css_class = 'wiki-link' @@ -128,11 +132,16 @@ @property def all_meta(self): self._ensureMeta() - return { + meta = { 'url': self._meta['url'], 'name': self._meta['name'], - 'title': self._meta['title'] + 'title': self._meta['title'], + 'user': self._meta['user'] } + for name in self._promoted_meta: + if name in self._meta['user']: + meta[name] = self._meta['user'] + return meta def getHistory(self): self._ensureMeta() @@ -168,10 +177,12 @@ ctx = PageFormattingContext(self.url, ext) f = PageFormatter(self.wiki) self._meta['formatted'] = f.formatText(ctx, self._meta['content']) + self._meta['user'] = ctx.meta self._meta['title'] = re.sub(r'\-', ' ', self._meta['name']) - if ctx.title is not None: - self._meta['title'] = ctx.title + for name in self._promoted_meta: + if name in ctx.meta: + self._meta[name] = ctx.meta[name] self._meta['out_links'] = [] for l in ctx.out_links: @@ -191,6 +202,12 @@ self.wiki.logger.debug("Updated cached %s for page '%s'." % (cache_key, self.url)) self.wiki.cache.write(cache_key, data) + _promoted_meta = [ + 'title', + 'redirect', + 'notitle' + ] + @staticmethod def title_to_url(title): return re.sub(r'[^A-Za-z0-9_\.\-\(\)/]+', '-', title.lower())