Remove paginator.pagers

This commit is contained in:
Vincent Prouillet 2018-09-30 23:49:32 +02:00
parent e9acd3bda5
commit e1aaed3c04
5 changed files with 16 additions and 26 deletions

View file

@ -2,7 +2,12 @@
## 0.5.0 (unreleased) ## 0.5.0 (unreleased)
### Breaking
- Gutenberg has changed name to REPLACE_ME! - 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 - Update dependencies, fixing a few bugs with templates
- Load only .html files in themes from the templates folder - Load only .html files in themes from the templates folder
- Background colour is set fewer times when highlighting syntaxes - Background colour is set fewer times when highlighting syntaxes

View file

@ -51,17 +51,6 @@ impl<'a> Pager<'a> {
pages, 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)] #[derive(Clone, Debug, PartialEq)]
@ -183,27 +172,23 @@ impl<'a> Paginator<'a> {
paginator.insert("first", to_value(&self.permalink).unwrap()); paginator.insert("first", to_value(&self.permalink).unwrap());
let last_pager = &self.pagers[self.pagers.len() - 1]; let last_pager = &self.pagers[self.pagers.len() - 1];
paginator.insert("last", to_value(&last_pager.permalink).unwrap()); paginator.insert("last", to_value(&last_pager.permalink).unwrap());
paginator.insert(
"pagers",
to_value(
&self.pagers.iter().map(|p| p.clone_without_pages()).collect::<Vec<_>>()
).unwrap(),
);
// Variables for this specific page // Variables for this specific page
if pager_index > 0 { if pager_index > 0 {
let prev_pager = &self.pagers[pager_index - 1]; let prev_pager = &self.pagers[pager_index - 1];
paginator.insert("previous", to_value(&prev_pager.permalink).unwrap()); paginator.insert("previous", to_value(&prev_pager.permalink).unwrap());
} else { } else {
paginator.insert("previous", to_value::<Option<()>>(None).unwrap()); paginator.insert("previous", Value::Null);
} }
if pager_index < self.pagers.len() - 1 { if pager_index < self.pagers.len() - 1 {
let next_pager = &self.pagers[pager_index + 1]; let next_pager = &self.pagers[pager_index + 1];
paginator.insert("next", to_value(&next_pager.permalink).unwrap()); paginator.insert("next", to_value(&next_pager.permalink).unwrap());
} else { } else {
paginator.insert("next", to_value::<Option<()>>(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(&current_pager.pages).unwrap()); paginator.insert("pages", to_value(&current_pager.pages).unwrap());
paginator.insert("current_index", to_value(current_pager.index).unwrap()); paginator.insert("current_index", to_value(current_pager.index).unwrap());

View file

@ -15,6 +15,11 @@ In addition, a paginated page gets a `paginator` variable of the `Pager` type:
```ts ```ts
// How many items per page // How many items per page
paginate_by: Number; 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 // Permalink to the first page
first: String; first: String;
// Permalink to the last page // Permalink to the last page
@ -25,8 +30,6 @@ previous: String?;
next: String?; next: String?;
// All pages for the current page // All pages for the current page
pages: Array<Page>; pages: Array<Page>;
// All pagers for this section, but with their `pages` attribute set to an empty array
pagers: Array<Pagers>;
// Which page are we on // Which page are we on
current_index: Number; current_index: Number;
``` ```

View file

@ -22,7 +22,7 @@
{% endfor %} {% endfor %}
{% if paginator.previous %}has_prev{% endif %} {% if paginator.previous %}has_prev{% endif %}
{% if paginator.next %}has_next{% endif %} {% if paginator.next %}has_next{% endif %}
Num pages: {{ paginator.pagers | length }} Num pages: {{ paginator.number_pagers }}
Current index: {{ paginator.current_index }} Current index: {{ paginator.current_index }}
First: {{ paginator.first | safe }} First: {{ paginator.first | safe }}
Last: {{ paginator.last | safe }} Last: {{ paginator.last | safe }}

View file

@ -4,10 +4,7 @@
{% for page in paginator.pages %} {% for page in paginator.pages %}
{{page.title}} {{page.title}}
{% endfor %} {% endfor %}
{% for pager in paginator.pagers %} Num pagers: {{ paginator.number_pagers }}
{{pager.index}}: {{pager.path | safe }}
{% endfor %}
Num pagers: {{ paginator.pagers | length }}
Page size: {{ paginator.paginate_by }} Page size: {{ paginator.paginate_by }}
Current index: {{ paginator.current_index }} Current index: {{ paginator.current_index }}
First: {{ paginator.first | safe }} First: {{ paginator.first | safe }}