Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition to 2018 edition #933

Merged
merged 3 commits into from
May 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ authors = [
"Michael-F-Bryan <[email protected]>",
"Matt Ickstadt <[email protected]>"
]
description = "Creates a book from markdown files"
documentation = "http://rust-lang-nursery.github.io/mdBook/index.html"
repository = "https://github.com/rust-lang-nursery/mdBook"
edition = "2018"
exclude = ["/book-example/*"]
keywords = ["book", "gitbook", "rustbook", "markdown"]
license = "MPL-2.0"
readme = "README.md"
exclude = ["book-example/*"]
repository = "https://github.com/rust-lang-nursery/mdBook"
description = "Creates a book from markdown files"

[dependencies]
clap = "2.24"
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<tr>
<td><strong>Linux / OS X</strong></td>
<td>
<a href="https://travis-ci.org/rust-lang-nursery/mdBook"><img src="https://travis-ci.org/rust-lang-nursery/mdBook.svg?branch=master"></a>
<a href="https://travis-ci.com/rust-lang-nursery/mdBook"><img src="https://travis-ci.com/rust-lang-nursery/mdBook.svg?branch=master"></a>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -65,7 +65,7 @@ There are multiple ways to install mdBook.
cargo install mdbook --vers "^0.1.0"
```

3. **From Git**
3. **From Git**

The version published to crates.io will ever so slightly be behind the
version hosted here on GitHub. If you need the latest version you can build
Expand All @@ -77,7 +77,7 @@ There are multiple ways to install mdBook.

Again, make sure to add the Cargo bin directory to your `PATH`.

4. **For Contributions**
4. **For Contributions**

If you want to contribute to mdBook you will have to clone the repository on
your local machine:
Expand Down Expand Up @@ -152,9 +152,9 @@ party plugins. These plugins are just programs which will be invoked during the
build process and are split into roughly two categories, *preprocessors* and
*renderers*.

Preprocessors are used to transform a book before it is sent to a renderer.
One example would be to replace all occurrences of
`{{#include some_file.ext}}` with the contents of that file. Some existing
Preprocessors are used to transform a book before it is sent to a renderer.
One example would be to replace all occurrences of
`{{#include some_file.ext}}` with the contents of that file. Some existing
preprocessors are:

- `index` - a built-in preprocessor (enabled by default) which will transform
Expand Down
5 changes: 0 additions & 5 deletions examples/de-emphasize.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
//! An example preprocessor for removing all forms of emphasis from a markdown
//! book.

extern crate mdbook;
extern crate pulldown_cmark;
extern crate pulldown_cmark_to_cmark;

use mdbook::book::{Book, BookItem, Chapter};
use mdbook::errors::{Error, Result};
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
Expand Down
6 changes: 1 addition & 5 deletions examples/nop-preprocessor.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
extern crate clap;
extern crate mdbook;
extern crate serde_json;

use crate::nop_lib::Nop;
use clap::{App, Arg, ArgMatches, SubCommand};
use mdbook::book::Book;
use mdbook::errors::Error;
use mdbook::preprocess::{CmdPreprocessor, Preprocessor, PreprocessorContext};
use nop_lib::Nop;
use std::io;
use std::process;

Expand Down
4 changes: 2 additions & 2 deletions src/book/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::io::{Read, Write};
use std::path::{Path, PathBuf};

use super::summary::{parse_summary, Link, SectionNumber, Summary, SummaryItem};
use config::BuildConfig;
use errors::*;
use crate::config::BuildConfig;
use crate::errors::*;

/// Load a book into memory from its `src/` directory.
pub fn load_book<P: AsRef<Path>>(src_dir: P, cfg: &BuildConfig) -> Result<Book> {
Expand Down
7 changes: 3 additions & 4 deletions src/book/init.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::fs::{self, File};
use std::io::Write;
use std::path::PathBuf;
use toml;

use super::MDBook;
use config::Config;
use errors::*;
use theme;
use crate::config::Config;
use crate::errors::*;
use crate::theme;

/// A helper for setting up a new book and its directory structure.
#[derive(Debug, Clone, PartialEq)]
Expand Down
11 changes: 5 additions & 6 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ use std::string::ToString;
use tempfile::Builder as TempFileBuilder;
use toml::Value;

use errors::*;
use preprocess::{
use crate::errors::*;
use crate::preprocess::{
CmdPreprocessor, IndexPreprocessor, LinkPreprocessor, Preprocessor, PreprocessorContext,
};
use renderer::{CmdRenderer, HtmlHandlebars, RenderContext, Renderer};
use utils;
use crate::renderer::{CmdRenderer, HtmlHandlebars, RenderContext, Renderer};
use crate::utils;

use config::Config;
use crate::config::Config;

/// The object used to manage and build a book.
pub struct MDBook {
Expand Down Expand Up @@ -124,7 +124,6 @@ impl MDBook {
/// `(section: String, bookitem: &BookItem)`
///
/// ```no_run
/// # extern crate mdbook;
/// # use mdbook::MDBook;
/// # use mdbook::book::BookItem;
/// # #[allow(unused_variables)]
Expand Down
2 changes: 1 addition & 1 deletion src/book/summary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use errors::*;
use crate::errors::*;
use memchr::{self, Memchr};
use pulldown_cmark::{self, Event, Tag};
use std::fmt::{self, Display, Formatter};
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{get_book_dir, open};
use clap::{App, ArgMatches, SubCommand};
use mdbook::errors::Result;
use mdbook::MDBook;
use {get_book_dir, open};

// Create clap subcommand arguments
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/clean.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::get_book_dir;
use clap::{App, ArgMatches, SubCommand};
use get_book_dir;
use mdbook::errors::*;
use mdbook::MDBook;
use std::fs;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/init.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::get_book_dir;
use clap::{App, ArgMatches, SubCommand};
use get_book_dir;
use mdbook::config;
use mdbook::errors::Result;
use mdbook::MDBook;
Expand Down
11 changes: 2 additions & 9 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
extern crate iron;
extern crate staticfile;
extern crate ws;

use self::iron::{
status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request, Response, Set,
};
#[cfg(feature = "watch")]
use super::watch;
use crate::{get_book_dir, open};
use clap::{App, Arg, ArgMatches, SubCommand};
use iron::{status, AfterMiddleware, Chain, Iron, IronError, IronResult, Request, Response, Set};
use mdbook::errors::*;
use mdbook::utils;
use mdbook::MDBook;
use std;
use {get_book_dir, open};

struct ErrorRecover;

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::get_book_dir;
use clap::{App, Arg, ArgMatches, SubCommand};
use get_book_dir;
use mdbook::errors::Result;
use mdbook::MDBook;

Expand Down
10 changes: 4 additions & 6 deletions src/cmd/watch.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
extern crate notify;

use self::notify::Watcher;
use crate::{get_book_dir, open};
use clap::{App, ArgMatches, SubCommand};
use mdbook::errors::Result;
use mdbook::utils;
use mdbook::MDBook;
use notify::Watcher;
use std::path::{Path, PathBuf};
use std::sync::mpsc::channel;
use std::thread::sleep;
use std::time::Duration;
use {get_book_dir, open};

// Create clap subcommand arguments
pub fn make_subcommand<'a, 'b>() -> App<'a, 'b> {
Expand Down Expand Up @@ -55,8 +53,8 @@ pub fn trigger_on_change<F>(book: &MDBook, closure: F)
where
F: Fn(Vec<PathBuf>, &Path),
{
use self::notify::DebouncedEvent::*;
use self::notify::RecursiveMode::*;
use notify::DebouncedEvent::*;
use notify::RecursiveMode::*;

// Create a channel to receive the events.
let (tx, rx) = channel();
Expand Down
5 changes: 1 addition & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
//! # Examples
//!
//! ```rust
//! # extern crate mdbook;
//! # use mdbook::errors::*;
//! # extern crate toml;
//! use std::path::PathBuf;
//! use std::str::FromStr;
//! use mdbook::Config;
Expand Down Expand Up @@ -52,7 +50,6 @@
#![deny(missing_docs)]

use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json;
use std::env;
use std::fs::File;
use std::io::Read;
Expand All @@ -64,7 +61,7 @@ use toml_query::delete::TomlValueDeleteExt;
use toml_query::insert::TomlValueInsertExt;
use toml_query::read::TomlValueReadExt;

use errors::*;
use crate::errors::*;

/// The overall configuration object for MDBook, essentially an in-memory
/// representation of `book.toml`.
Expand Down
18 changes: 4 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,14 @@

#[macro_use]
extern crate error_chain;
extern crate handlebars;
extern crate itertools;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate memchr;
extern crate pulldown_cmark;
extern crate regex;
extern crate serde;
#[macro_use]
extern crate serde_derive;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use macro imports and get rid of extern crates for these as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. But I think we should land it as is. Because we already transit
new edition. Also because I don't want to deal with missing macro importing
somewhere while trying to get rid of those extern crate.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool no issues

#[macro_use]
extern crate serde_json;
extern crate shlex;
extern crate tempfile;
extern crate toml;
extern crate toml_query;

#[cfg(test)]
#[macro_use]
Expand All @@ -121,10 +111,10 @@ pub mod utils;
/// compatibility checks.
pub const MDBOOK_VERSION: &str = env!("CARGO_PKG_VERSION");

pub use book::BookItem;
pub use book::MDBook;
pub use config::Config;
pub use renderer::Renderer;
pub use crate::book::BookItem;
pub use crate::book::MDBook;
pub use crate::config::Config;
pub use crate::renderer::Renderer;

/// The error types used through out this crate.
pub mod errors {
Expand Down
5 changes: 0 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
extern crate chrono;
#[macro_use]
extern crate clap;
extern crate env_logger;
extern crate error_chain;
#[macro_use]
extern crate log;
extern crate mdbook;
extern crate open;

use chrono::Local;
use clap::{App, AppSettings, ArgMatches};
Expand Down
7 changes: 3 additions & 4 deletions src/preprocess/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::{Preprocessor, PreprocessorContext};
use book::Book;
use errors::*;
use serde_json;
use crate::book::Book;
use crate::errors::*;
use shlex::Shlex;
use std::io::{self, Read, Write};
use std::process::{Child, Command, Stdio};
Expand Down Expand Up @@ -168,8 +167,8 @@ impl Preprocessor for CmdPreprocessor {
#[cfg(test)]
mod tests {
use super::*;
use crate::MDBook;
use std::path::Path;
use MDBook;

fn book_example() -> MDBook {
let example = Path::new(env!("CARGO_MANIFEST_DIR")).join("book-example");
Expand Down
4 changes: 2 additions & 2 deletions src/preprocess/index.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use regex::Regex;
use std::path::Path;

use errors::*;
use crate::errors::*;

use super::{Preprocessor, PreprocessorContext};
use book::{Book, BookItem};
use crate::book::{Book, BookItem};

/// A preprocessor for converting file name `README.md` to `index.md` since
/// `README.md` is the de facto index file in markdown-based documentation.
Expand Down
8 changes: 4 additions & 4 deletions src/preprocess/links.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use errors::*;
use crate::errors::*;
use crate::utils::fs::file_to_string;
use crate::utils::take_lines;
use regex::{CaptureMatches, Captures, Regex};
use std::ops::{Range, RangeFrom, RangeFull, RangeTo};
use std::path::{Path, PathBuf};
use utils::fs::file_to_string;
use utils::take_lines;

use super::{Preprocessor, PreprocessorContext};
use book::{Book, BookItem};
use crate::book::{Book, BookItem};

const ESCAPE_CHAR: char = '\\';
const MAX_LINK_NESTED_DEPTH: usize = 10;
Expand Down
8 changes: 4 additions & 4 deletions src/preprocess/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ mod cmd;
mod index;
mod links;

use book::Book;
use config::Config;
use errors::*;
use crate::book::Book;
use crate::config::Config;
use crate::errors::*;

use std::path::PathBuf;

Expand All @@ -37,7 +37,7 @@ impl PreprocessorContext {
root,
config,
renderer,
mdbook_version: ::MDBOOK_VERSION.to_string(),
mdbook_version: crate::MDBOOK_VERSION.to_string(),
__non_exhaustive: (),
}
}
Expand Down
Loading