From 18eba7c0359c5bfceb6a8e0553b8368bf409c827 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Tue, 23 Apr 2019 23:50:45 -0700 Subject: [PATCH] Move prev/next to the end of articles with addenda --- lexipython/article.py | 45 +++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/lexipython/article.py b/lexipython/article.py index 3b645b8..2a6da84 100644 --- a/lexipython/article.py +++ b/lexipython/article.py @@ -221,8 +221,7 @@ class LexiconArticle: content += "

{}

{}
\n".format( self.title, main_body) # Build the main citation content block - main_citations = self.build_default_citeblock( - self.prev_article, self.next_article) + main_citations = self.build_default_citeblock() if main_citations: content += "
{}
\n".format( main_citations) @@ -230,10 +229,16 @@ class LexiconArticle: for addendum in self.addendums: add_body = addendum.build_default_article_body() content += "
{}
\n".format(add_body) - add_citations = addendum.build_default_citeblock(None, None) + add_citations = addendum.build_default_citeblock() if add_citations: content += "
{}
\n".format( add_citations) + # Build the prev/next block + prev_next = self.build_prev_next_block( + self.prev_article, self.next_article) + if prev_next: + content += "
{}
\n".format( + prev_next) return content def build_default_article_body(self): @@ -247,23 +252,12 @@ class LexiconArticle: } return self.content.format(**format_map) - def build_default_citeblock(self, prev_article, next_article): + def build_default_citeblock(self): """ - Builds the contents of a citation contentblock. For each defined target, - links the target page as Previous or Next. Prev/next and cites/citedby - elements are not included if they have no content. + Builds the contents of a citation contentblock. Skips sections with no + content. """ content = "" - # Prev/next links: - if next_article is not None or prev_article is not None: - prev_link = ("← Previous".format( - prev_article) - if prev_article is not None else "") - next_link = ("Next →".format( - next_article) - if next_article is not None else "") - content += "\n\n\n
{}{}
\n".format( - prev_link, next_link) # Citations cites_titles = set() cites_links = [] @@ -289,3 +283,20 @@ class LexiconArticle: content += "

Cited by: {}

\n".format(citedby_str) return content + + def build_prev_next_block(self, prev_article, next_article): + """ + For each defined target, links the target page as Previous or Next. + """ + content = "" + # Prev/next links: + if next_article is not None or prev_article is not None: + prev_link = ("← Previous".format( + prev_article) + if prev_article is not None else "") + next_link = ("Next →".format( + next_article) + if next_article is not None else "") + content += "\n\n\n
{}{}
\n".format( + prev_link, next_link) + return content