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

Migrate to rinja #2487

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
181 changes: 88 additions & 93 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 @@ -26,12 +26,12 @@ clap = { version = "4.3.12", features = ["cargo", "wrap_help"] }
clap_complete = "4.3.2"
once_cell = "1.17.1"
env_logger = "0.11.1"
handlebars = "6.0"
log = "0.4.17"
memchr = "2.5.0"
opener = "0.7.0"
pulldown-cmark = { version = "0.10.0", default-features = false, features = ["html"] } # Do not update, part of the public api.
regex = "1.8.1"
rinja = "0.3.5"
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
shlex = "1.3.0"
Expand Down
6 changes: 3 additions & 3 deletions guide/src/format/theme/index-hbs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# index.hbs
# index.html

`index.hbs` is the handlebars template that is used to render the book. The
`index.html` is the jinja template that is used to render the book. The
markdown files are processed to html and then injected in that template.

If you want to change the layout or style of your book, chances are that you
Expand All @@ -11,7 +11,7 @@ will have to modify this template a little bit. Here is what you need to know.
A lot of data is exposed to the handlebars template with the "context". In the
handlebars template you can access this information by using

```handlebars
```jinja
{{name_of_property}}
```

Expand Down
3 changes: 3 additions & 0 deletions rinja.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[escaper]]
path = "rinja::filters::Text"
extensions = ["js"]
3 changes: 0 additions & 3 deletions src/book/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ impl BookBuilder {
fs::create_dir(&themedir)?;
}

let mut index = File::create(themedir.join("index.hbs"))?;
index.write_all(theme::INDEX)?;

let cssdir = themedir.join("css");
if !cssdir.exists() {
fs::create_dir(&cssdir)?;
Expand Down
10 changes: 5 additions & 5 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::errors::*;
use crate::preprocess::{
CmdPreprocessor, IndexPreprocessor, LinkPreprocessor, Preprocessor, PreprocessorContext,
};
use crate::renderer::{CmdRenderer, HtmlHandlebars, MarkdownRenderer, RenderContext, Renderer};
use crate::renderer::{CmdRenderer, HtmlRenderer, MarkdownRenderer, RenderContext, Renderer};
use crate::utils;

use crate::config::{Config, RustEdition};
Expand Down Expand Up @@ -435,7 +435,7 @@ fn determine_renderers(config: &Config) -> Vec<Box<dyn Renderer>> {
if let Some(output_table) = config.get("output").and_then(Value::as_table) {
renderers.extend(output_table.iter().map(|(key, table)| {
if key == "html" {
Box::new(HtmlHandlebars::new()) as Box<dyn Renderer>
Box::new(HtmlRenderer::new()) as Box<dyn Renderer>
} else if key == "markdown" {
Box::new(MarkdownRenderer::new()) as Box<dyn Renderer>
} else {
Expand All @@ -446,7 +446,7 @@ fn determine_renderers(config: &Config) -> Vec<Box<dyn Renderer>> {

// if we couldn't find anything, add the HTML renderer as a default
if renderers.is_empty() {
renderers.push(Box::new(HtmlHandlebars::new()));
renderers.push(Box::new(HtmlRenderer::new()));
}

renderers
Expand Down Expand Up @@ -858,7 +858,7 @@ mod tests {
.and_then(Value::as_str)
.unwrap();
assert_eq!(html, "html");
let html_renderer = HtmlHandlebars::default();
let html_renderer = HtmlRenderer::default();
let pre = LinkPreprocessor::new();

let should_run = preprocessor_should_run(&pre, &html_renderer, &cfg);
Expand All @@ -883,7 +883,7 @@ mod tests {
#[test]
fn preprocessor_should_run_falls_back_to_supports_renderer_method() {
let cfg = Config::default();
let html = HtmlHandlebars::new();
let html = HtmlRenderer::new();

let should_be = true;
let got = preprocessor_should_run(&BoolPreprocessor(should_be), &html, &cfg);
Expand Down
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,14 @@ impl TextDirection {
_ => TextDirection::LeftToRight,
}
}

/// Convert the text representation.
pub fn as_str(&self) -> &'static str {
match self {
Self::LeftToRight => "ltr",
Self::RightToLeft => "rtl",
}
}
}

/// Configuration for the build procedure.
Expand Down
3 changes: 0 additions & 3 deletions src/renderer/html_handlebars/helpers/mod.rs

This file was deleted.

Loading