1
0
Fork 0
mirror of https://github.com/lise-henry/crowbook synced 2024-05-28 18:16:32 +02:00

compiles without warnings

This commit is contained in:
Elisabeth Henry 2016-02-18 22:50:23 +01:00
parent 9173e2f4e8
commit 2160f5d0d8
6 changed files with 18 additions and 24 deletions

View File

@ -3,29 +3,14 @@ extern crate crowbook;
use crowbook::{HtmlRenderer, Book};
use std::env;
fn main() {
let config = "
author: Lizzie Crowdagger
title: Pas tout à fait des hommes
lang: fr
numbering: false
autoclean: true
cover: book-example/cover.png
+ book_example/chapitre_01.md
+ book_example/chapitre_02.md
+ book_example/chapitre_03.md
";
let mut args = env::args();
args.next(); //discard program name
match args.next() {
None => println!("Needs the name of a book config file"),
Some(ref s) => {
let mut book = Book::new_from_file(s).unwrap();
let book = Book::new_from_file(s).unwrap();
let mut html = HtmlRenderer::new(&book);
println!("{}", html.render_book().unwrap());
}

View File

@ -1,5 +1,4 @@
use token::Token;
use std::borrow::Cow;
fn parse_token(token: Token) -> String {
match token {

View File

@ -3,6 +3,8 @@ use cleaner::{Cleaner, French};
use std::fs::File;
use std::io::Read;
use std::env;
use std::path::Path;
use mustache::MapBuilder;
@ -44,8 +46,21 @@ impl Book {
}
/// Creates a new book from a file
///
/// This method also changes the current directory to the one of this file
pub fn new_from_file(filename: &str) -> Result<Book> {
let mut f = try!(File::open(filename).map_err(|_| Error::FileNotFound(String::from(filename))));
let path = Path::new(filename);
let mut f = try!(File::open(&path).map_err(|_| Error::FileNotFound(String::from(filename))));
// change current directory
if let Some(parent) = path.parent() {
if !env::set_current_dir(&parent).is_ok() {
return Err(Error::ConfigParser("could not change current directory to the one of the config file",
format!("{}", parent.display())));
}
}
let mut s = String::new();
try!(f.read_to_string(&mut s).map_err(|_| Error::ConfigParser("file contains invalid UTF-8, could not parse it",
@ -109,7 +124,7 @@ impl Book {
for line in s.lines() {
let line = line.trim();
let bool_error = |_| Error::ConfigParser("could not parse bool", String::from(line));
if line.is_empty() {
if line.is_empty() || line.starts_with('#') {
continue;
}
if line.starts_with('-') {

View File

@ -1,5 +1,3 @@
use std::borrow::Cow;
/// Custom function because we don't really want to touch \t or \n
fn is_whitespace(c: char) -> bool {
c == ' ' || c == ' ' || c == ''

View File

@ -5,7 +5,6 @@ use parser::Parser;
use error::{Error,Result};
use mustache;
use mustache::MapBuilder;
/// Renderer for HTML.
///

View File

@ -1,5 +1,3 @@
use std::borrow::Cow;
#[derive(Debug, PartialEq, Clone)]
pub enum Token {
Str(String),