mirror of
https://github.com/lise-henry/crowbook
synced 2024-05-28 01:36:17 +02:00
runned clippy, thus some minor corrections
This commit is contained in:
parent
56e786a938
commit
829746a762
|
@ -322,7 +322,7 @@ impl Book {
|
|||
"html_template" => (&self.html_template, html::TEMPLATE),
|
||||
_ => return Err(Error::ConfigParser("invalid template", template.to_owned())),
|
||||
};
|
||||
if let &Some (ref s) = option {
|
||||
if let Some (ref s) = *option {
|
||||
let mut f = try!(File::open(s).map_err(|_| Error::FileNotFound(s.to_owned())));
|
||||
let mut res = String::new();
|
||||
try!(f.read_to_string(&mut res)
|
||||
|
|
|
@ -8,7 +8,7 @@ fn is_whitespace(c: char) -> bool {
|
|||
/// NOT for code blocks, hyperlikns and so on!
|
||||
pub trait Cleaner {
|
||||
/// Cleans a string, removing multiple whitespaces
|
||||
fn clean<'a>(&self, s: &mut String) {
|
||||
fn clean(&self, s: &mut String) {
|
||||
if s.contains(is_whitespace) { // if not, no need to do anything
|
||||
let mut new_s = String::with_capacity(s.len());
|
||||
let mut previous_space = false;
|
||||
|
@ -48,7 +48,7 @@ impl French {
|
|||
|
||||
impl Cleaner for French {
|
||||
// puts non breaking spaces between :, ;, ?, !, «, »
|
||||
fn clean<'a>(&self, s: &mut String) {
|
||||
fn clean(&self, s: &mut String) {
|
||||
fn is_trouble(c: char) -> bool {
|
||||
match c {
|
||||
'?'|'!'|';'|':'|'»'|'«'|'—' => true,
|
||||
|
|
|
@ -38,18 +38,17 @@ impl<'a> EpubRenderer<'a> {
|
|||
|
||||
/// Render a book
|
||||
pub fn render_book(&mut self) -> Result<String> {
|
||||
let mut zipper = try!(Zipper::new(&self.book.temp_dir, &vec!("META-INF")));
|
||||
let mut zipper = try!(Zipper::new(&self.book.temp_dir, &["META-INF"]));
|
||||
|
||||
// Write mimetype
|
||||
try!(zipper.write("mimetype", b"application/epub+zip"));
|
||||
|
||||
// Write chapters
|
||||
let mut i = 0;
|
||||
for &(ref n, ref v) in &self.book.chapters {
|
||||
for (i, &(n, ref v)) in self.book.chapters.iter().enumerate() {
|
||||
match n {
|
||||
&Number::Unnumbered => self.current_numbering = false,
|
||||
&Number::Default => self.current_numbering = self.book.numbering,
|
||||
&Number::Specified(n) => {
|
||||
Number::Unnumbered => self.current_numbering = false,
|
||||
Number::Default => self.current_numbering = self.book.numbering,
|
||||
Number::Specified(n) => {
|
||||
self.current_numbering = self.book.numbering;
|
||||
self.current_chapter = n;
|
||||
}
|
||||
|
@ -57,7 +56,6 @@ impl<'a> EpubRenderer<'a> {
|
|||
let chapter = try!(self.render_chapter(v));
|
||||
|
||||
try!(zipper.write(&filenamer(i), &chapter.as_bytes()));
|
||||
i += 1;
|
||||
}
|
||||
|
||||
// Write CSS file
|
||||
|
|
|
@ -14,38 +14,36 @@ pub enum Error {
|
|||
|
||||
impl error::Error for Error {
|
||||
fn description(&self) -> &str {
|
||||
match self {
|
||||
&Error::Parser(ref s) => s,
|
||||
&Error::ConfigParser(ref s, _) => s,
|
||||
&Error::FileNotFound(_) => "File not found",
|
||||
&Error::Render(ref s) => s,
|
||||
&Error::Zipper(ref s) => s,
|
||||
match *self {
|
||||
Error::Parser(ref s) | Error::ConfigParser(ref s, _) | Error::Render(ref s) => s,
|
||||
Error::Zipper(ref s) => s,
|
||||
Error::FileNotFound(_) => "File not found",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
&Error::Parser(ref s) => {
|
||||
match *self {
|
||||
Error::Parser(ref s) => {
|
||||
try!(f.write_str("Error parsing markdown: "));
|
||||
f.write_str(s)
|
||||
},
|
||||
&Error::ConfigParser(ref s, ref line) => {
|
||||
Error::ConfigParser(ref s, ref line) => {
|
||||
try!(f.write_str("Error parsing configuration file: "));
|
||||
try!(f.write_str(s));
|
||||
try!(f.write_str(" in:\n"));
|
||||
f.write_str(line)
|
||||
},
|
||||
&Error::FileNotFound(ref file) => {
|
||||
Error::FileNotFound(ref file) => {
|
||||
try!(f.write_str("File not found: "));
|
||||
f.write_str(file)
|
||||
},
|
||||
&Error::Render(ref s) => {
|
||||
Error::Render(ref s) => {
|
||||
try!(f.write_str("Error during rendering: "));
|
||||
f.write_str(s)
|
||||
},
|
||||
&Error::Zipper(ref s) => {
|
||||
Error::Zipper(ref s) => {
|
||||
try!(f.write_str("Error during temporary files editing: "));
|
||||
f.write_str(s)
|
||||
},
|
||||
|
|
|
@ -2,7 +2,6 @@ use escape::escape_html;
|
|||
use token::Token;
|
||||
use book::{Book, Number};
|
||||
use error::{Error,Result};
|
||||
use templates::html::*;
|
||||
|
||||
use mustache;
|
||||
|
||||
|
@ -29,11 +28,11 @@ impl<'a> HtmlRenderer<'a> {
|
|||
pub fn render_book(&mut self) -> Result<String> {
|
||||
let mut content = String::new();
|
||||
|
||||
for &(ref n, ref v) in &self.book.chapters {
|
||||
for &(n, ref v) in &self.book.chapters {
|
||||
match n {
|
||||
&Number::Unnumbered => self.current_numbering = false,
|
||||
&Number::Default => self.current_numbering = self.book.numbering,
|
||||
&Number::Specified(n) => {
|
||||
Number::Unnumbered => self.current_numbering = false,
|
||||
Number::Default => self.current_numbering = self.book.numbering,
|
||||
Number::Specified(n) => {
|
||||
self.current_numbering = self.book.numbering;
|
||||
self.current_chapter = n;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ impl<'a> LatexRenderer<'a> {
|
|||
let base_file = try!(Path::new(pdf_file).file_stem().ok_or(Error::Render("could not stem pdf filename")));
|
||||
let tex_file = format!("{}.tex", base_file.to_str().unwrap());
|
||||
let content = try!(self.render_book());
|
||||
let mut zipper = try!(Zipper::new(&self.book.temp_dir, &vec!()));
|
||||
let mut zipper = try!(Zipper::new(&self.book.temp_dir, &[]));
|
||||
try!(zipper.write(&tex_file, &content.as_bytes()));
|
||||
zipper.generate_pdf(&self.book.tex_command, &tex_file, pdf_file)
|
||||
} else {
|
||||
|
|
|
@ -55,7 +55,7 @@ impl Parser {
|
|||
Event::Text(text) => {
|
||||
let mut text = text.into_owned();
|
||||
if let Some(&Token::Str(_)) = v.last() {
|
||||
if let &mut Token::Str(ref mut s) = v.last_mut().unwrap() {
|
||||
if let Token::Str(ref mut s) = *v.last_mut().unwrap() {
|
||||
s.push_str(&text);
|
||||
if let Some(ref cleaner) = self.cleaner {
|
||||
if !self.verbatim {
|
||||
|
|
Loading…
Reference in New Issue