From 0aa3a9045a90ce112404f2cc81e821d4ef48822e Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 5 May 2019 21:57:43 +0700 Subject: [PATCH] cargo fmt --- src/book/book.rs | 3 +- src/book/init.rs | 2 +- src/book/mod.rs | 2 +- src/book/summary.rs | 3 +- src/cmd/build.rs | 6 +- src/cmd/clean.rs | 3 +- src/cmd/init.rs | 3 +- src/cmd/serve.rs | 3 +- src/cmd/watch.rs | 2 +- src/lib.rs | 2 +- src/preprocess/links.rs | 27 ++--- src/renderer/html_handlebars/hbs_renderer.rs | 15 ++- .../html_handlebars/helpers/navigation.rs | 102 +++++++++--------- src/utils/mod.rs | 6 +- tests/rendered_output.rs | 8 +- 15 files changed, 105 insertions(+), 82 deletions(-) diff --git a/src/book/book.rs b/src/book/book.rs index a14d31b9..62af2d92 100644 --- a/src/book/book.rs +++ b/src/book/book.rs @@ -481,7 +481,8 @@ And here is some \ .filter_map(|i| match *i { BookItem::Chapter(ref ch) => Some(ch.name.clone()), _ => None, - }).collect(); + }) + .collect(); let should_be: Vec<_> = vec![ String::from("Chapter 1"), String::from("Hello World"), diff --git a/src/book/init.rs b/src/book/init.rs index 4726d570..740eb27b 100644 --- a/src/book/init.rs +++ b/src/book/init.rs @@ -136,7 +136,7 @@ impl BookBuilder { let mut book_css = File::create(cssdir.join("book.css"))?; book_css.write_all(theme::BOOK_CSS)?; - + let mut chrome_css = File::create(cssdir.join("chrome.css"))?; chrome_css.write_all(theme::CHROME_CSS)?; diff --git a/src/book/mod.rs b/src/book/mod.rs index 9a413759..5002c353 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -99,7 +99,7 @@ impl MDBook { pub fn load_with_config_and_summary>( book_root: P, config: Config, - summary: Summary + summary: Summary, ) -> Result { let root = book_root.into(); diff --git a/src/book/summary.rs b/src/book/summary.rs index 31bf0b9b..d236d8a1 100644 --- a/src/book/summary.rs +++ b/src/book/summary.rs @@ -477,7 +477,8 @@ fn stringify_events(events: Vec) -> String { .filter_map(|t| match t { Event::Text(text) => Some(text.into_owned()), _ => None, - }).collect() + }) + .collect() } /// A section number like "1.2.3", basically just a newtype'd `Vec` with diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 4a5abbc0..da42015e 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -11,10 +11,12 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> { "-d, --dest-dir=[dest-dir] 'Output directory for the book{n}\ Relative paths are interpreted relative to the book's root directory.{n}\ If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'", - ).arg_from_usage( + ) + .arg_from_usage( "[dir] 'Root directory for the book{n}\ (Defaults to the Current Directory when omitted)'", - ).arg_from_usage("-o, --open 'Opens the compiled book in a web browser'") + ) + .arg_from_usage("-o, --open 'Opens the compiled book in a web browser'") } // Build command implementation diff --git a/src/cmd/clean.rs b/src/cmd/clean.rs index fba49be8..5045dc74 100644 --- a/src/cmd/clean.rs +++ b/src/cmd/clean.rs @@ -13,7 +13,8 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> { Relative paths are interpreted relative to the book's root directory.{n}\ Running this command deletes this directory.{n}\ If omitted, mdBook uses build.build-dir from book.toml or defaults to `./book`.'", - ).arg_from_usage( + ) + .arg_from_usage( "[dir] 'Root directory for the book{n}\ (Defaults to the Current Directory when omitted)'", ) diff --git a/src/cmd/init.rs b/src/cmd/init.rs index c6bba9d5..2bea7a38 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -15,7 +15,8 @@ pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> { .arg_from_usage( "[dir] 'Directory to create the book in{n}\ (Defaults to the Current Directory when omitted)'", - ).arg_from_usage("--theme 'Copies the default theme into your source folder'") + ) + .arg_from_usage("--theme 'Copies the default theme into your source folder'") .arg_from_usage("--force 'Skips confirmation prompts'") } diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index ac6acbdd..ce194da6 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -126,7 +126,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> { b.config .set("output.html.livereload-url", &livereload_url)?; Ok(b) - }).and_then(|b| b.build()); + }) + .and_then(|b| b.build()); if let Err(e) = result { error!("Unable to load the book"); diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs index e19a5581..fc4d5c91 100644 --- a/src/cmd/watch.rs +++ b/src/cmd/watch.rs @@ -7,8 +7,8 @@ use mdbook::utils; use mdbook::MDBook; use std::path::{Path, PathBuf}; use std::sync::mpsc::channel; -use std::time::Duration; use std::thread::sleep; +use std::time::Duration; use {get_book_dir, open}; // Create clap subcommand arguments diff --git a/src/lib.rs b/src/lib.rs index 028a2ba8..7e350650 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -129,7 +129,7 @@ pub use renderer::Renderer; pub mod errors { use std::path::PathBuf; - error_chain!{ + error_chain! { foreign_links { Io(::std::io::Error) #[doc = "A wrapper around `std::io::Error`"]; HandlebarsRender(::handlebars::RenderError) #[doc = "Handlebars rendering failed"]; diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs index 90a057b0..2e3a88e3 100644 --- a/src/preprocess/links.rs +++ b/src/preprocess/links.rs @@ -143,17 +143,19 @@ fn parse_include_path(path: &str) -> LinkType<'static> { match start { Some(start) => match end { Some(end) => LinkType::IncludeRange(path, Range { start, end }), - None => if has_end { - LinkType::IncludeRangeFrom(path, RangeFrom { start }) - } else { - LinkType::IncludeRange( - path, - Range { - start, - end: start + 1, - }, - ) - }, + None => { + if has_end { + LinkType::IncludeRangeFrom(path, RangeFrom { start }) + } else { + LinkType::IncludeRange( + path, + Range { + start, + end: start + 1, + }, + ) + } + } }, None => match end { Some(end) => LinkType::IncludeRangeTo(path, RangeTo { end }), @@ -304,7 +306,8 @@ fn find_links(contents: &str) -> LinkIter { \s+ # separating whitespace ([a-zA-Z0-9\s_.\-:/\\]+) # link target path and space separated properties \s*\}\} # whitespace and link closing parens" - ).unwrap(); + ) + .unwrap(); } LinkIter(RE.captures_iter(contents)) } diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index 7ecafbcb..956b8125 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -36,7 +36,11 @@ impl HtmlHandlebars { let string_path = ch.path.parent().unwrap().display().to_string(); - let fixed_content = utils::render_markdown_with_base(&ch.content, ctx.html_config.curly_quotes, &string_path); + let fixed_content = utils::render_markdown_with_base( + &ch.content, + ctx.html_config.curly_quotes, + &string_path, + ); print_content.push_str(&fixed_content); // Update the context with data for this file @@ -507,7 +511,8 @@ fn build_header_links(html: &str) -> String { .expect("Regex should ensure we only ever get numbers here"); wrap_header_with_link(level, &caps[2], &mut id_counter) - }).into_owned() + }) + .into_owned() } /// Wraps a single header tag with a link, making sure each tag gets its own @@ -558,7 +563,8 @@ fn fix_code_blocks(html: &str) -> String { classes = classes, after = after ) - }).into_owned() + }) + .into_owned() } fn add_playpen_pre(html: &str, playpen_config: &Playpen) -> String { @@ -594,7 +600,8 @@ fn add_playpen_pre(html: &str, playpen_config: &Playpen) -> String { // not language-rust, so no-op text.to_owned() } - }).into_owned() + }) + .into_owned() } fn partition_source(s: &str) -> (String, String) { diff --git a/src/renderer/html_handlebars/helpers/navigation.rs b/src/renderer/html_handlebars/helpers/navigation.rs index 0e551004..e62ae2f6 100644 --- a/src/renderer/html_handlebars/helpers/navigation.rs +++ b/src/renderer/html_handlebars/helpers/navigation.rs @@ -178,23 +178,23 @@ mod tests { #[test] fn test_next_previous() { let data = json!({ - "name": "two", - "path": "two.path", - "chapters": [ - { - "name": "one", - "path": "one.path" - }, - { - "name": "two", - "path": "two.path", - }, - { - "name": "three", - "path": "three.path" - } - ] - }); + "name": "two", + "path": "two.path", + "chapters": [ + { + "name": "one", + "path": "one.path" + }, + { + "name": "two", + "path": "two.path", + }, + { + "name": "three", + "path": "three.path" + } + ] + }); let mut h = Handlebars::new(); h.register_helper("previous", Box::new(previous)); @@ -209,23 +209,23 @@ mod tests { #[test] fn test_first() { let data = json!({ - "name": "one", - "path": "one.path", - "chapters": [ - { - "name": "one", - "path": "one.path" - }, - { - "name": "two", - "path": "two.path", - }, - { - "name": "three", - "path": "three.path" - } - ] - }); + "name": "one", + "path": "one.path", + "chapters": [ + { + "name": "one", + "path": "one.path" + }, + { + "name": "two", + "path": "two.path", + }, + { + "name": "three", + "path": "three.path" + } + ] + }); let mut h = Handlebars::new(); h.register_helper("previous", Box::new(previous)); @@ -239,23 +239,23 @@ mod tests { #[test] fn test_last() { let data = json!({ - "name": "three", - "path": "three.path", - "chapters": [ - { - "name": "one", - "path": "one.path" - }, - { - "name": "two", - "path": "two.path", - }, - { - "name": "three", - "path": "three.path" - } - ] - }); + "name": "three", + "path": "three.path", + "chapters": [ + { + "name": "one", + "path": "one.path" + }, + { + "name": "two", + "path": "two.path", + }, + { + "name": "three", + "path": "three.path" + } + ] + }); let mut h = Handlebars::new(); h.register_helper("previous", Box::new(previous)); diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 76dd16b9..2a6324f1 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -34,7 +34,8 @@ pub fn normalize_id(content: &str) -> String { } else { None } - }).collect::() + }) + .collect::() } /// Generate an ID for use with anchors which is derived from a "normalised" @@ -195,7 +196,8 @@ fn convert_quotes_to_curly(original_text: &str) -> String { preceded_by_whitespace = original_char.is_whitespace(); converted_char - }).collect() + }) + .collect() } /// Prints a "backtrace" of some `Error`. diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index 062674a3..2449498c 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -30,8 +30,12 @@ const TOC_TOP_LEVEL: &[&'static str] = &[ "Dummy Book", "Introduction", ]; -const TOC_SECOND_LEVEL: &[&'static str] = - &["1.1. Nested Chapter", "1.2. Includes", "2.1. Nested Chapter", "1.3. Recursive"]; +const TOC_SECOND_LEVEL: &[&'static str] = &[ + "1.1. Nested Chapter", + "1.2. Includes", + "2.1. Nested Chapter", + "1.3. Recursive", +]; /// Make sure you can load the dummy book and build it without panicking. #[test]