Skip to content

Commit

Permalink
Merge pull request rust-lang#977 from sunng87/feature/handlebars-2.0
Browse files Browse the repository at this point in the history
(feat) update handlebars to 2.0
  • Loading branch information
ehuss authored Jul 12, 2019
2 parents 1165955 + a16a565 commit 6b1e580
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
16 changes: 13 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ chrono = "0.4"
clap = "2.24"
env_logger = "0.6"
error-chain = "0.12"
handlebars = { version = "1.0", default-features = false, features = ["no_dir_source"] }
handlebars = { version = "2.0", default-features = false, features = ["no_dir_source"] }
itertools = "0.8"
lazy_static = "1.0"
log = "0.4"
Expand Down
10 changes: 6 additions & 4 deletions src/renderer/html_handlebars/helpers/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ fn find_chapter(
) -> Result<Option<StringMap>, RenderError> {
debug!("Get data from context");

let chapters = rc.evaluate_absolute(ctx, "chapters", true).and_then(|c| {
serde_json::value::from_value::<Vec<StringMap>>(c.clone())
let chapters = rc.evaluate(ctx, "@root/chapters").and_then(|c| {
serde_json::value::from_value::<Vec<StringMap>>(c.as_json().clone())
.map_err(|_| RenderError::new("Could not decode the JSON data"))
})?;

let base_path = rc
.evaluate_absolute(ctx, "path", true)?
.evaluate(ctx, "@root/path")?
.as_json()
.as_str()
.ok_or_else(|| RenderError::new("Type error for `path`, string expected"))?
.replace("\"", "");
Expand Down Expand Up @@ -96,7 +97,8 @@ fn render(

let mut context = BTreeMap::new();
let base_path = rc
.evaluate_absolute(ctx, "path", false)?
.evaluate(ctx, "@root/path")?
.as_json()
.as_str()
.ok_or_else(|| RenderError::new("Type error for `path`, string expected"))?
.replace("\"", "");
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/html_handlebars/helpers/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ pub fn theme_option(
RenderError::new("Param 0 with String type is required for theme_option helper.")
})?;

let theme_name = rc
.evaluate_absolute(ctx, "default_theme", true)?
let default_theme = rc.evaluate(ctx, "@root/default_theme")?;
let default_theme_name = default_theme
.as_json()
.as_str()
.ok_or_else(|| RenderError::new("Type error for `default_theme`, string expected"))?;

out.write(param)?;
if param.to_lowercase() == theme_name.to_lowercase() {
if param.to_lowercase() == default_theme_name.to_lowercase() {
out.write(" (default)")?;
}

Expand Down
7 changes: 4 additions & 3 deletions src/renderer/html_handlebars/helpers/toc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ impl HelperDef for RenderToc {
// get value from context data
// rc.get_path() is current json parent path, you should always use it like this
// param is the key of value you want to display
let chapters = rc.evaluate_absolute(ctx, "chapters", true).and_then(|c| {
serde_json::value::from_value::<Vec<BTreeMap<String, String>>>(c.clone())
let chapters = rc.evaluate(ctx, "@root/chapters").and_then(|c| {
serde_json::value::from_value::<Vec<BTreeMap<String, String>>>(c.as_json().clone())
.map_err(|_| RenderError::new("Could not decode the JSON data"))
})?;
let current = rc
.evaluate_absolute(ctx, "path", true)?
.evaluate(ctx, "@root/path")?
.as_json()
.as_str()
.ok_or_else(|| RenderError::new("Type error for `path`, string expected"))?
.replace("\"", "");
Expand Down

0 comments on commit 6b1e580

Please sign in to comment.