Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Commit

Permalink
Allow multiple authors. Closes #40
Browse files Browse the repository at this point in the history
Uses either CSV, or a YAML list, as mentioned in #42.
  • Loading branch information
mythmon committed Sep 11, 2011
1 parent 2505e3f commit 0fa3fbc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion sample/content/tests/markdown.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ title: Markdown Test Page
slug: markdown
category: tests
tags: markdown, sample
author: Not Default
author: [Me, Myself, I]
---
This is the markdown test page
------------------------------
Expand Down
4 changes: 3 additions & 1 deletion sample/templates/default.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% extends "base.html" %}
{% block body %}
<h1>{{ page.title }}</h1>
<h2>by: {{page.author.name}}</h2>
<h2>by: {% for author in page.authors %}
{{author.name}}{% if not loop.last %}, {% endif %}
{% endfor %}</h2>
<h3>Tags:</h3>
<ul>
{% for tag in page.tags %}
Expand Down
7 changes: 5 additions & 2 deletions wok/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ def read_options(self):
if yaml_config:
self.options.update(yaml_config)

if 'author' in self.options:
self.options['author'] = page.Author.parse(self.options['author'])
authors = self.options.get('authors', self.options.get('author', None))
if isinstance(authors, list):
self.options['authors'] = [page.Author.parse(a) for a in authors]
elif isinstance(authors, str):
self.options['authors'] = [page.Author.parse(a) for a in authors.split(',')]

def sanity_check(self):
"""Basic sanity checks."""
Expand Down
35 changes: 23 additions & 12 deletions wok/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ def build_meta(self):
"""
Ensures the guarantees about metadata for documents are valid.
`page.title` - Will exist and will be a string.
`page.slug` - Will exist and will be a string.
`page.author` - Will exist, and contain fields `name` and `email`.
`page.title` - Will be a string.
`page.slug` - Will be a string.
`page.author` - Will have fields `name` and `email`.
`page.authors` - Will be a list of Authors.
`page.category` - Will be a list.
`page.published` - Will exist.
`page.datetime` - Will be a datetime.
Expand Down Expand Up @@ -97,11 +98,25 @@ def build_meta(self):
logging.warning('Your slug should probably be all lower case, and '
'match "[a-z0-9-]*"')

# author
if 'author' in self.meta:
self.meta['author'] = Author.parse(self.meta['author'])
elif 'author' in self.options:
self.meta['author'] = self.options['author']
# authors and author
authors = self.meta.get('authors', self.meta.get('author', None))
if isinstance(authors, list):
self.meta['authors'] = [Author.parse(a) for a in authors]
elif isinstance(authors, str):
self.meta['authors'] = [Author.parse(a) for a in authors.split(',')]
elif authors is None:
if 'authors' in self.options:
self.meta['authors'] = self.options['authors']
else:
self.meta['authors'] = []
else:
# wait, what?
self.meta['authors'] = []
logging.error(('Authors in {0} is an unknown type. Valid types '
'are string or list.').format(self.path))

if self.meta['authors']:
self.meta['author'] = self.meta['authors']
else:
self.meta['author'] = Author()

Expand Down Expand Up @@ -267,12 +282,8 @@ def paginate(self):
'cur_page': 1,
})
if len(extra_pages) > 1:
print 'doing next_page'
self.meta['pagination']['next_page'] = extra_pages[0].meta
else:
print 'skipping next_page'

print self.meta['pagination'].keys()
return extra_pages

def write(self):
Expand Down

0 comments on commit 0fa3fbc

Please sign in to comment.