mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-24 10:16:59 -06:00
Merge PR #637
This commit is contained in:
@@ -34,3 +34,6 @@ sync_github_name = true
|
||||
|
||||
[people.thaynej]
|
||||
real_name = "Jeffrey Thayne"
|
||||
|
||||
[people.webdevtodayjason]
|
||||
display_name = "Jason Brashear"
|
||||
|
||||
+19
-1
@@ -184,10 +184,15 @@ fn entry_text(spec: &IndexSpec, n: &Node, page_name: &dyn Fn(usize) -> String) -
|
||||
t
|
||||
}
|
||||
|
||||
// `build` limits topic paths to four levels, bounding this traversal.
|
||||
fn run_in_subtopics(spec: &IndexSpec, n: &Node, page_name: &dyn Fn(usize) -> String) -> Vec<String> {
|
||||
n.children.values().flat_map(|c| [entry_text(spec, c, page_name)].into_iter().chain(run_in_subtopics(spec, c, page_name))).collect()
|
||||
}
|
||||
|
||||
fn emit(spec: &IndexSpec, n: &Node, level: usize, page_name: &dyn Fn(usize) -> String, out: &mut Vec<(String, String)>) {
|
||||
if spec.run_in && level == 1 {
|
||||
let mut t = entry_text(spec, n, page_name);
|
||||
let subs: Vec<String> = n.children.values().map(|c| entry_text(spec, c, page_name)).collect();
|
||||
let subs = run_in_subtopics(spec, n, page_name);
|
||||
if !subs.is_empty() {
|
||||
t.push_str(": ");
|
||||
t.push_str(&subs.join(&spec.between_entries));
|
||||
@@ -209,6 +214,19 @@ mod tests {
|
||||
Resolved { r: IndexRef { topics: topics.iter().map(|s| s.to_string()).collect(), sort: vec![], range }, pages }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_in_keeps_all_topic_levels_in_sort_order() {
|
||||
let refs = vec![
|
||||
r(&["Typography", "kerning", "pairs", "optical"], IndexRange::CurrentPage, Some((4, 4))),
|
||||
r(&["Typography", "kerning", "pairs"], IndexRange::CurrentPage, Some((2, 2))),
|
||||
r(&["Typography", "leading"], IndexRange::CurrentPage, Some((6, 6))),
|
||||
r(&["Typography", "kerning", "adjustment"], IndexRange::See("Spacing".into()), None),
|
||||
];
|
||||
let spec = IndexSpec { run_in: true, title: String::new(), section_headings: false, between_entries: " / ".into(), ..IndexSpec::default() };
|
||||
let out = build(&spec, &refs, &|p| (p + 1).to_string());
|
||||
assert_eq!(out, [("Index Level 1".into(), "Typography: kerning / adjustment See Spacing / pairs 3 / optical 5 / leading 7".into())]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_nested_index() {
|
||||
let refs = vec![
|
||||
|
||||
Reference in New Issue
Block a user