Skip to content

Commit 3bc5d90

Browse files
Merge pull request #641 from rust-lang-nursery/pre-release
Pre release
2 parents 4af155e + 3cd12e7 commit 3bc5d90

File tree

6 files changed

+160
-144
lines changed

6 files changed

+160
-144
lines changed

Cargo.lock

Lines changed: 62 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "mdbook"
3-
version = "0.1.4-alpha.0"
3+
version = "0.1.5-alpha.0"
44
authors = ["Mathieu David <mathieudavid@mathieudavid.org>", "Michael-F-Bryan <michaelfbryan@gmail.com>"]
5-
description = "create books from markdown files (like Gitbook)"
5+
description = "Create books from markdown files"
66
documentation = "http://rust-lang-nursery.github.io/mdBook/index.html"
77
repository = "https://github.com/rust-lang-nursery/mdBook"
88
keywords = ["book", "gitbook", "rustbook", "markdown"]
@@ -16,13 +16,13 @@ exclude = [
1616

1717
[package.metadata.release]
1818
sign-commit = true
19-
push-remote = "upstream"
19+
push-remote = "origin"
2020
tag-prefix = "v"
2121

2222
[dependencies]
2323
clap = "2.24"
2424
chrono = "0.4"
25-
handlebars = "0.29"
25+
handlebars = "0.32"
2626
serde = "1.0"
2727
serde_derive = "1.0"
2828
error-chain = "0.11"
@@ -51,15 +51,15 @@ staticfile = { version = "0.4", optional = true }
5151
ws = { version = "0.7", optional = true}
5252

5353
# Search feature
54-
elasticlunr-rs = { version = "0.2", optional = true }
54+
elasticlunr-rs = { version = "1.0", optional = true }
5555
ammonia = { version = "1.1", optional = true }
5656

5757
[build-dependencies]
5858
error-chain = "0.11"
5959

6060
[dev-dependencies]
6161
select = "0.4"
62-
pretty_assertions = "0.4"
62+
pretty_assertions = "0.5"
6363
walkdir = "2.0"
6464
pulldown-cmark-to-cmark = "1.1.0"
6565

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<tr>
1111
<td><strong>Windows</strong></td>
1212
<td>
13-
<a href="https://ci.appveyor.com/project/azerupi/mdbook/"><img src="https://ci.appveyor.com/api/projects/status/o38racsnbcospyc8/branch/master?svg=true"></a>
13+
<a href="https://ci.appveyor.com/project/rust-lang-libs/mdbook"><img src="https://ci.appveyor.com/api/projects/status/ysyke2rvo85sni55?svg=true"></a>
1414
</td>
1515
</tr>
1616
<tr>

src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! # mdBook
22
//!
3-
//! **mdBook** is similar to GitBook but implemented in Rust.
4-
//! It offers a command line interface, but can also be used as a regular crate.
3+
//! **mdBook** is a tool for rendering a collection of markdown documents into
4+
//! a form more suitable for end users like HTML or EPUB. It offers a command
5+
//! line interface, but this crate can be used if more control is required.
56
//!
67
//! This is the API doc, the [user guide] is also available if you want
78
//! information about the command line tool, format, structure etc. It is also
@@ -15,6 +16,12 @@
1516
//! - Accessing the public API to help create a new Renderer
1617
//! - ...
1718
//!
19+
//! > **Note:** While we try to ensure `mdbook`'s command-line interface and
20+
//! > behaviour are backwards compatible, the tool's internals are still
21+
//! > evolving and being iterated on. If you wish to prevent accidental
22+
//! > breakages it is recommended to pin any tools building on top of the
23+
//! > `mdbook` crate to a specific release.
24+
//!
1825
//! # Examples
1926
//!
2027
//! If creating a new book from scratch, you'll want to get a `BookBuilder` via

src/renderer/html_handlebars/helpers/navigation.rs

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::collections::BTreeMap;
44
use serde_json;
55
use handlebars::{Context, Handlebars, Helper, RenderContext, RenderError, Renderable};
66

7-
87
type StringMap = BTreeMap<String, String>;
98

109
/// Target for `find_chapter`.
@@ -15,22 +14,23 @@ enum Target {
1514

1615
impl Target {
1716
/// Returns target if found.
18-
fn find(&self,
19-
base_path: &String,
20-
current_path: &String,
21-
current_item: &StringMap,
22-
previous_item: &StringMap,
23-
) -> Result<Option<StringMap>, RenderError> {
17+
fn find(
18+
&self,
19+
base_path: &String,
20+
current_path: &String,
21+
current_item: &StringMap,
22+
previous_item: &StringMap,
23+
) -> Result<Option<StringMap>, RenderError> {
2424
match self {
2525
&Target::Next => {
26-
let previous_path = previous_item.get("path").ok_or_else(|| {
27-
RenderError::new("No path found for chapter in JSON data")
28-
})?;
26+
let previous_path = previous_item
27+
.get("path")
28+
.ok_or_else(|| RenderError::new("No path found for chapter in JSON data"))?;
2929

3030
if previous_path == base_path {
3131
return Ok(Some(current_item.clone()));
3232
}
33-
},
33+
}
3434

3535
&Target::Previous => {
3636
if current_path == base_path {
@@ -43,21 +43,18 @@ impl Target {
4343
}
4444
}
4545

46-
fn find_chapter(
47-
rc: &mut RenderContext,
48-
target: Target
49-
) -> Result<Option<StringMap>, RenderError> {
46+
fn find_chapter(rc: &mut RenderContext, target: Target) -> Result<Option<StringMap>, RenderError> {
5047
debug!("Get data from context");
5148

52-
let chapters = rc.evaluate_absolute("chapters").and_then(|c| {
49+
let chapters = rc.evaluate_absolute("chapters", true).and_then(|c| {
5350
serde_json::value::from_value::<Vec<StringMap>>(c.clone())
5451
.map_err(|_| RenderError::new("Could not decode the JSON data"))
5552
})?;
5653

57-
let base_path = rc.evaluate_absolute("path")?
58-
.as_str()
59-
.ok_or_else(|| RenderError::new("Type error for `path`, string expected"))?
60-
.replace("\"", "");
54+
let base_path = rc.evaluate_absolute("path", true)?
55+
.as_str()
56+
.ok_or_else(|| RenderError::new("Type error for `path`, string expected"))?
57+
.replace("\"", "");
6158

6259
let mut previous: Option<StringMap> = None;
6360

@@ -78,7 +75,7 @@ fn find_chapter(
7875
}
7976
}
8077

81-
Ok(None)
78+
Ok(None)
8279
}
8380

8481
fn render(
@@ -91,18 +88,21 @@ fn render(
9188

9289
let mut context = BTreeMap::new();
9390

94-
chapter.get("name")
95-
.ok_or_else(|| RenderError::new("No title found for chapter in JSON data"))
96-
.map(|name| context.insert("title".to_owned(), json!(name)))?;
97-
98-
chapter.get("path")
99-
.ok_or_else(|| RenderError::new("No path found for chapter in JSON data"))
100-
.and_then(|p| {
101-
Path::new(p).with_extension("html")
102-
.to_str()
103-
.ok_or_else(|| RenderError::new("Link could not be converted to str"))
104-
.map(|p| context.insert("link".to_owned(), json!(p.replace("\\", "/"))))
105-
})?;
91+
chapter
92+
.get("name")
93+
.ok_or_else(|| RenderError::new("No title found for chapter in JSON data"))
94+
.map(|name| context.insert("title".to_owned(), json!(name)))?;
95+
96+
chapter
97+
.get("path")
98+
.ok_or_else(|| RenderError::new("No path found for chapter in JSON data"))
99+
.and_then(|p| {
100+
Path::new(p)
101+
.with_extension("html")
102+
.to_str()
103+
.ok_or_else(|| RenderError::new("Link could not be converted to str"))
104+
.map(|p| context.insert("link".to_owned(), json!(p.replace("\\", "/"))))
105+
})?;
106106

107107
trace!("Render template");
108108

@@ -138,14 +138,14 @@ pub fn next(_h: &Helper, r: &Handlebars, rc: &mut RenderContext) -> Result<(), R
138138

139139
#[cfg(test)]
140140
mod tests {
141-
use super::*;
141+
use super::*;
142142

143-
static TEMPLATE: &'static str =
144-
"{{#previous}}{{title}}: {{link}}{{/previous}}|{{#next}}{{title}}: {{link}}{{/next}}";
143+
static TEMPLATE: &'static str =
144+
"{{#previous}}{{title}}: {{link}}{{/previous}}|{{#next}}{{title}}: {{link}}{{/next}}";
145145

146-
#[test]
147-
fn test_next_previous() {
148-
let data = json!({
146+
#[test]
147+
fn test_next_previous() {
148+
let data = json!({
149149
"name": "two",
150150
"path": "two.path",
151151
"chapters": [
@@ -164,18 +164,19 @@ mod tests {
164164
]
165165
});
166166

167-
let mut h = Handlebars::new();
168-
h.register_helper("previous", Box::new(previous));
169-
h.register_helper("next", Box::new(next));
167+
let mut h = Handlebars::new();
168+
h.register_helper("previous", Box::new(previous));
169+
h.register_helper("next", Box::new(next));
170170

171-
assert_eq!(
172-
h.template_render(TEMPLATE, &data).unwrap(),
173-
"one: one.html|three: three.html");
174-
}
171+
assert_eq!(
172+
h.render_template(TEMPLATE, &data).unwrap(),
173+
"one: one.html|three: three.html"
174+
);
175+
}
175176

176-
#[test]
177-
fn test_first() {
178-
let data = json!({
177+
#[test]
178+
fn test_first() {
179+
let data = json!({
179180
"name": "one",
180181
"path": "one.path",
181182
"chapters": [
@@ -194,17 +195,18 @@ mod tests {
194195
]
195196
});
196197

197-
let mut h = Handlebars::new();
198-
h.register_helper("previous", Box::new(previous));
199-
h.register_helper("next", Box::new(next));
200-
201-
assert_eq!(
202-
h.template_render(TEMPLATE, &data).unwrap(),
203-
"|two: two.html");
204-
}
205-
#[test]
206-
fn test_last() {
207-
let data = json!({
198+
let mut h = Handlebars::new();
199+
h.register_helper("previous", Box::new(previous));
200+
h.register_helper("next", Box::new(next));
201+
202+
assert_eq!(
203+
h.render_template(TEMPLATE, &data).unwrap(),
204+
"|two: two.html"
205+
);
206+
}
207+
#[test]
208+
fn test_last() {
209+
let data = json!({
208210
"name": "three",
209211
"path": "three.path",
210212
"chapters": [
@@ -223,12 +225,13 @@ mod tests {
223225
]
224226
});
225227

226-
let mut h = Handlebars::new();
227-
h.register_helper("previous", Box::new(previous));
228-
h.register_helper("next", Box::new(next));
228+
let mut h = Handlebars::new();
229+
h.register_helper("previous", Box::new(previous));
230+
h.register_helper("next", Box::new(next));
229231

230-
assert_eq!(
231-
h.template_render(TEMPLATE, &data).unwrap(),
232-
"two: two.html|");
233-
}
232+
assert_eq!(
233+
h.render_template(TEMPLATE, &data).unwrap(),
234+
"two: two.html|"
235+
);
236+
}
234237
}

src/renderer/html_handlebars/helpers/toc.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ use pulldown_cmark::{html, Event, Parser, Tag};
88
// Handlebars helper to construct TOC
99
#[derive(Clone, Copy)]
1010
pub struct RenderToc {
11-
pub no_section_label: bool
11+
pub no_section_label: bool,
1212
}
1313

1414
impl HelperDef for RenderToc {
1515
fn call(&self, _h: &Helper, _: &Handlebars, rc: &mut RenderContext) -> Result<(), RenderError> {
1616
// get value from context data
1717
// rc.get_path() is current json parent path, you should always use it like this
1818
// param is the key of value you want to display
19-
let chapters = rc.evaluate_absolute("chapters").and_then(|c| {
19+
let chapters = rc.evaluate_absolute("chapters", true).and_then(|c| {
2020
serde_json::value::from_value::<Vec<BTreeMap<String, String>>>(c.clone())
2121
.map_err(|_| RenderError::new("Could not decode the JSON data"))
2222
})?;
23-
let current = rc.evaluate_absolute("path")?
24-
.as_str()
25-
.ok_or_else(|| RenderError::new("Type error for `path`, string expected"))?
26-
.replace("\"", "");
23+
let current = rc.evaluate_absolute("path", true)?
24+
.as_str()
25+
.ok_or_else(|| RenderError::new("Type error for `path`, string expected"))?
26+
.replace("\"", "");
2727

2828
rc.writer.write_all(b"<ol class=\"chapter\">")?;
2929

@@ -107,12 +107,12 @@ impl HelperDef for RenderToc {
107107

108108
// filter all events that are not inline code blocks
109109
let parser = Parser::new(name).filter(|event| match *event {
110-
Event::Start(Tag::Code) |
111-
Event::End(Tag::Code) |
112-
Event::InlineHtml(_) |
113-
Event::Text(_) => true,
114-
_ => false,
115-
});
110+
Event::Start(Tag::Code)
111+
| Event::End(Tag::Code)
112+
| Event::InlineHtml(_)
113+
| Event::Text(_) => true,
114+
_ => false,
115+
});
116116

117117
// render markdown to html
118118
let mut markdown_parsed_name = String::with_capacity(name.len() * 3 / 2);

0 commit comments

Comments
 (0)