From e1aaed3c046e72fee7060859c3475404537b1b43 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Sun, 30 Sep 2018 23:49:32 +0200 Subject: [PATCH] Remove paginator.pagers --- CHANGELOG.md | 5 ++++ components/pagination/src/lib.rs | 23 ++++--------------- .../documentation/templates/pagination.md | 7 ++++-- test_site/templates/index_paginated.html | 2 +- test_site/templates/section_paginated.html | 5 +--- 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2e189f7..88e7a478 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,12 @@ ## 0.5.0 (unreleased) +### Breaking + - Gutenberg has changed name to REPLACE_ME! +- The `pagers` variable of Paginator objects has been removed + +### Others - Update dependencies, fixing a few bugs with templates - Load only .html files in themes from the templates folder - Background colour is set fewer times when highlighting syntaxes diff --git a/components/pagination/src/lib.rs b/components/pagination/src/lib.rs index ff9347fc..ee3b4683 100644 --- a/components/pagination/src/lib.rs +++ b/components/pagination/src/lib.rs @@ -51,17 +51,6 @@ impl<'a> Pager<'a> { pages, } } - - /// Returns a manually cloned Pager with the pages removed - /// for use as template context - fn clone_without_pages(&self) -> Pager<'a> { - Pager { - index: self.index, - permalink: self.permalink.clone(), - path: self.path.clone(), - pages: vec![], - } - } } #[derive(Clone, Debug, PartialEq)] @@ -183,27 +172,23 @@ impl<'a> Paginator<'a> { paginator.insert("first", to_value(&self.permalink).unwrap()); let last_pager = &self.pagers[self.pagers.len() - 1]; paginator.insert("last", to_value(&last_pager.permalink).unwrap()); - paginator.insert( - "pagers", - to_value( - &self.pagers.iter().map(|p| p.clone_without_pages()).collect::>() - ).unwrap(), - ); // Variables for this specific page if pager_index > 0 { let prev_pager = &self.pagers[pager_index - 1]; paginator.insert("previous", to_value(&prev_pager.permalink).unwrap()); } else { - paginator.insert("previous", to_value::>(None).unwrap()); + paginator.insert("previous", Value::Null); } if pager_index < self.pagers.len() - 1 { let next_pager = &self.pagers[pager_index + 1]; paginator.insert("next", to_value(&next_pager.permalink).unwrap()); } else { - paginator.insert("next", to_value::>(None).unwrap()); + paginator.insert("next", Value::Null); } + paginator.insert("number_pagers", to_value(&self.pagers.len()).unwrap()); + paginator.insert("base_url", to_value(&format!("{}{}/", self.permalink, self.paginate_path)).unwrap()); paginator.insert("pages", to_value(¤t_pager.pages).unwrap()); paginator.insert("current_index", to_value(current_pager.index).unwrap()); diff --git a/docs/content/documentation/templates/pagination.md b/docs/content/documentation/templates/pagination.md index 902e9fa5..b4fcddd4 100644 --- a/docs/content/documentation/templates/pagination.md +++ b/docs/content/documentation/templates/pagination.md @@ -15,6 +15,11 @@ In addition, a paginated page gets a `paginator` variable of the `Pager` type: ```ts // How many items per page paginate_by: Number; +// The base URL for the pagination: section permalink + pagination path +// You can concatenate an integer with that to get a link to a given pagination page. +base_url: String; +// How many pagers in this paginator +number_pagers: Number; // Permalink to the first page first: String; // Permalink to the last page @@ -25,8 +30,6 @@ previous: String?; next: String?; // All pages for the current page pages: Array; -// All pagers for this section, but with their `pages` attribute set to an empty array -pagers: Array; // Which page are we on current_index: Number; ``` diff --git a/test_site/templates/index_paginated.html b/test_site/templates/index_paginated.html index 096aaf52..851ddb38 100644 --- a/test_site/templates/index_paginated.html +++ b/test_site/templates/index_paginated.html @@ -22,7 +22,7 @@ {% endfor %} {% if paginator.previous %}has_prev{% endif %} {% if paginator.next %}has_next{% endif %} - Num pages: {{ paginator.pagers | length }} + Num pages: {{ paginator.number_pagers }} Current index: {{ paginator.current_index }} First: {{ paginator.first | safe }} Last: {{ paginator.last | safe }} diff --git a/test_site/templates/section_paginated.html b/test_site/templates/section_paginated.html index 820e4244..0570e6f5 100644 --- a/test_site/templates/section_paginated.html +++ b/test_site/templates/section_paginated.html @@ -4,10 +4,7 @@ {% for page in paginator.pages %} {{page.title}} {% endfor %} - {% for pager in paginator.pagers %} - {{pager.index}}: {{pager.path | safe }} - {% endfor %} - Num pagers: {{ paginator.pagers | length }} + Num pagers: {{ paginator.number_pagers }} Page size: {{ paginator.paginate_by }} Current index: {{ paginator.current_index }} First: {{ paginator.first | safe }}