diff --git a/src/resources/changes_resource.rs b/src/resources/changes_resource.rs index 18787da..847276c 100644 --- a/src/resources/changes_resource.rs +++ b/src/resources/changes_resource.rs @@ -234,11 +234,57 @@ impl Resource for ChangesResource { #[derive(BartDisplay)] #[template="templates/changes.html"] struct Template<'a> { + resource: &'a ChangesResource, + newer: Option, older: Option, changes: &'a [Row<'a>], } + impl<'a> Template<'a> { + fn subject_clause(&self) -> String { + match self.resource.article_id { + Some(x) => format!(" this article", x), + None => format!(" the wiki"), + } + } + + fn author_clause(&self) -> String { + #[derive(BartDisplay)] + #[template_string=" by {{author}}"] + struct AuthorClause<'a> { + link: &'a str, + author: &'a str, + } + + match self.resource.author { + Some(ref x) => AuthorClause { + link: &self.resource.query_args() + .author(Some(x.clone())) + .into_link(), + author: &x + }.to_string(), + None => "".to_owned(), + } + } + + fn all_articles_link(&self) -> Option { + self.resource.article_id.map(|_| { + self.resource.query_args() + .article_id(None) + .into_link() + }) + } + + fn all_authors_link(&self) -> Option { + self.resource.author.as_ref().map(|_| { + self.resource.query_args() + .author(None) + .into_link() + }) + } + } + let (before, article_id, author, limit) = (self.before.clone(), self.article_id.clone(), self.author.clone(), self.limit); let data = self.state.query_article_revision_stubs(move |query| { @@ -308,6 +354,7 @@ impl Resource for ChangesResource { base: None, // Hmm, should perhaps accept `base` as argument title: "Changes", body: &Template { + resource: &self, newer, older, changes diff --git a/templates/changes.html b/templates/changes.html index 1aebf1e..80b1117 100644 --- a/templates/changes.html +++ b/templates/changes.html @@ -4,6 +4,16 @@
+

+ These are the {{^newer}}most recent{{/newer}} changes that have been + made to{{{subject_clause()}}}{{{author_clause()}}}. +

+ + + {{#newer}}