Skip to content

Commit

Permalink
Add rusty-hook integration
Browse files Browse the repository at this point in the history
  • Loading branch information
tchernobog authored and francisco-perez-sorrosal committed Aug 22, 2021
1 parent cca2ff7 commit 0dd92df
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .rusty-hook.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[hooks]
pre-commit = "cargo fmt -- --check && cargo clippy --all-targets --workspace -- -D warnings"
pre-push = "cargo test --workspace"

[logging]
verbose = true
46 changes: 46 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ toml = "0.5.8"

[dev-dependencies]
tempfile = "3.0"
rusty-hook = { version = "0.11" }

[badges]
is-it-maintained-issue-resolution = { repository = "https://github.com/francisco-perez-sorrosal/mdbook-bib" }
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Bibiography {
"Replacing placeholders: {{#cite ...}} and @@citation in {}",
chapter_path.as_path().display()
);
let new_content = replace_all_placeholders(&ch, bibliography, &mut cited);
let new_content = replace_all_placeholders(ch, bibliography, &mut cited);
ch.content = new_content;
}
}
Expand Down Expand Up @@ -381,7 +381,7 @@ impl Preprocessor for Bibiography {
}
}

fn replace_all_placeholders<'a>(
fn replace_all_placeholders(
chapter: &Chapter,
bibliography: &HashMap<String, BibItem>,
cited: &mut HashSet<String>,
Expand All @@ -394,8 +394,7 @@ fn replace_all_placeholders<'a>(

let chapter_path = chapter
.path
.as_ref()
.map(|p| p.as_path())
.as_deref()
.unwrap_or_else(|| std::path::Path::new(""));

for placeholder in find_placeholders(&chapter.content) {
Expand Down
2 changes: 1 addition & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn citations_in_subfolders_link_properly() {
// Check valid references included in a dummy text
let check_citations_for = |chapter: &Chapter, link: &str| {
let text_with_citations =
replace_all_placeholders(&chapter, &bibliography, &mut HashSet::new());
replace_all_placeholders(chapter, &bibliography, &mut HashSet::new());

// TODO: These asserts will probably fail if we allow users to specify the bibliography
// chapter name as per issue #6
Expand Down

0 comments on commit 0dd92df

Please sign in to comment.