From 1c9e07815476f4ba5b9781426ba09cd03c1c2b0e Mon Sep 17 00:00:00 2001
From: Vincent Prouillet
Date: Sat, 22 Apr 2017 12:35:11 +0900
Subject: [PATCH] Clippy run
---
src/markdown.rs | 28 +++++++++++++---------------
src/page.rs | 25 ++++++++++++-------------
tests/front_matter.rs | 6 +++---
3 files changed, 28 insertions(+), 31 deletions(-)
diff --git a/src/markdown.rs b/src/markdown.rs
index 5ba63bbc..75b8601c 100644
--- a/src/markdown.rs
+++ b/src/markdown.rs
@@ -37,7 +37,7 @@ lazy_static!{
};
}
-/// A ShortCode that has a body
+/// A shortcode that has a body
/// Called by having some content like {% ... %} body {% end %}
/// We need the struct to hold the data while we're processing the markdown
#[derive(Debug)]
@@ -62,7 +62,7 @@ impl ShortCode {
pub fn render(&self, tera: &Tera) -> Result {
let mut context = Context::new();
- for (key, value) in self.args.iter() {
+ for (key, value) in &self.args {
context.add(key, value);
}
context.add("body", &self.body);
@@ -132,7 +132,7 @@ pub fn markdown_to_html(content: &str, permalinks: &HashMap, ter
// for example an article could have several titles named Example
// We add a counter after the slug if the slug is already present, which
// means we will have example, example-1, example-2 etc
- fn find_anchor(anchors: &Vec, name: String, level: u8) -> String {
+ fn find_anchor(anchors: &[String], name: String, level: u8) -> String {
if level == 0 && !anchors.contains(&name) {
return name.to_string();
}
@@ -164,16 +164,14 @@ pub fn markdown_to_html(content: &str, permalinks: &HashMap, ter
}
// Shortcode without body
- if shortcode_block.is_none() && text.starts_with("{{") && text.ends_with("}}") {
- if SHORTCODE_RE.is_match(&text) {
- let (name, args) = parse_shortcode(&text);
- added_shortcode = true;
- match render_simple_shortcode(tera, &name, &args) {
- Ok(s) => return Event::Html(Owned(format!("
{}", s))),
- Err(e) => {
- error = Some(e);
- return Event::Html(Owned("".to_string()));
- }
+ if shortcode_block.is_none() && text.starts_with("{{") && text.ends_with("}}") && SHORTCODE_RE.is_match(&text) {
+ let (name, args) = parse_shortcode(&text);
+ added_shortcode = true;
+ match render_simple_shortcode(tera, &name, &args) {
+ Ok(s) => return Event::Html(Owned(format!("{}", s))),
+ Err(e) => {
+ error = Some(e);
+ return Event::Html(Owned("".to_string()));
}
}
// non-matching will be returned normally below
@@ -277,7 +275,7 @@ pub fn markdown_to_html(content: &str, permalinks: &HashMap, ter
};
}
- return Event::Start(Tag::Link(link.clone(), title.clone()));
+ Event::Start(Tag::Link(link.clone(), title.clone()))
},
// need to know when we are in a code block to disable shortcodes in them
Event::Start(Tag::Code) => {
@@ -291,7 +289,7 @@ pub fn markdown_to_html(content: &str, permalinks: &HashMap, ter
Event::Start(Tag::Header(num)) => {
in_header = true;
// ugly eh
- return Event::Html(Owned(format!(" {
in_header = false;
diff --git a/src/page.rs b/src/page.rs
index 94bc865f..e9a0312d 100644
--- a/src/page.rs
+++ b/src/page.rs
@@ -152,22 +152,21 @@ impl Page {
// Pages with custom urls exists outside of sections
if let Some(ref u) = page.meta.url {
page.path = u.trim().to_string();
- } else {
- if !page.components.is_empty() {
- // If we have a folder with an asset, don't consider it as a component
- if page.file_name == "index" {
- page.components.pop();
- // also set parent_path to grandparent instead
- page.parent_path = page.parent_path.parent().unwrap().to_path_buf();
- }
-
- // Don't add a trailing slash to sections
- page.path = format!("{}/{}", page.components.join("/"), page.slug);
- } else {
- page.path = page.slug.clone();
+ } else if !page.components.is_empty() {
+ // If we have a folder with an asset, don't consider it as a component
+ if page.file_name == "index" {
+ page.components.pop();
+ // also set parent_path to grandparent instead
+ page.parent_path = page.parent_path.parent().unwrap().to_path_buf();
}
+
+ // Don't add a trailing slash to sections
+ page.path = format!("{}/{}", page.components.join("/"), page.slug);
+ } else {
+ page.path = page.slug.clone();
}
+
page.permalink = config.make_permalink(&page.path);
Ok(page)
diff --git a/tests/front_matter.rs b/tests/front_matter.rs
index bea21cf5..5b5c833e 100644
--- a/tests/front_matter.rs
+++ b/tests/front_matter.rs
@@ -53,10 +53,10 @@ authors = ["Bob", "Alice"]"#;
assert_eq!(res.title, "Hello".to_string());
assert_eq!(res.slug.unwrap(), "hello-world".to_string());
let extra = res.extra.unwrap();
- assert_eq!(extra.get("language").unwrap(), &to_value("en").unwrap());
+ assert_eq!(extra["language"], to_value("en").unwrap());
assert_eq!(
- extra.get("authors").unwrap(),
- &to_value(["Bob".to_string(), "Alice".to_string()]).unwrap()
+ extra["authors"],
+ to_value(["Bob".to_string(), "Alice".to_string()]).unwrap()
);
}