From 5ff96c7b032d89690ec360a8c22dedc54924321e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Such=C3=A1nek?= Date: Fri, 27 Oct 2023 22:04:23 +0200 Subject: [PATCH] Display the private ticket footnote only when enabled in project; #24 --- src/footnote.rs | 1 - src/lib.rs | 2 ++ src/note.rs | 8 ++++---- src/templating.rs | 11 +++++++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/footnote.rs b/src/footnote.rs index 938d163..337d796 100644 --- a/src/footnote.rs +++ b/src/footnote.rs @@ -26,7 +26,6 @@ pub fn is_footnote_defined(project: &Path) -> Result { } } - log::info!("The private ticket footnote is not defined."); Ok(false) } diff --git a/src/lib.rs b/src/lib.rs index 3d8baf1..12a34e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -157,11 +157,13 @@ impl Document { &tickets_for_internal, &project.templates, DocumentVariant::Internal, + project.private_footnote, ); let external_modules = templating::format_document( &tickets_for_external, &project.templates, DocumentVariant::External, + project.private_footnote, ); let (status_table, json_status) = status_report::analyze_status(&abstract_tickets)?; diff --git a/src/note.rs b/src/note.rs index 82aa1ed..68af8be 100644 --- a/src/note.rs +++ b/src/note.rs @@ -22,7 +22,7 @@ use crate::ticket_abstraction::AbstractTicket; impl AbstractTicket { /// Compose a release note from an abstract ticket. #[must_use] - pub fn release_note(&self, variant: DocumentVariant) -> String { + pub fn release_note(&self, variant: DocumentVariant, with_priv_footnote: bool) -> String { let anchor = self.anchor_declaration(); // This debug information line appears at empty release notes @@ -51,7 +51,7 @@ impl AbstractTicket { "{}\n{}\n\n{} {}", anchor, doc_text_unix, - self.all_signatures(), + self.all_signatures(with_priv_footnote), // In the internal variant, add the debug information line. if variant == DocumentVariant::Internal { &debug_info @@ -89,8 +89,8 @@ impl AbstractTicket { /// Prepare a list with signatures to this ticket and all its optional references. /// The result is a comma-separated list of signatures, enclosed in parentheses. #[must_use] - fn all_signatures(&self) -> String { - let mut signatures = vec![self.signature(true)]; + fn all_signatures(&self, with_priv_footnote: bool) -> String { + let mut signatures = vec![self.signature(with_priv_footnote)]; if let Some(references) = self.references.as_ref() { signatures.append(&mut references.clone()); diff --git a/src/templating.rs b/src/templating.rs index 7976c65..a7eea21 100644 --- a/src/templating.rs +++ b/src/templating.rs @@ -161,6 +161,7 @@ impl config::Section { id: &str, tickets: &[&AbstractTicket], variant: DocumentVariant, + with_priv_footnote: bool, ticket_stats: &mut HashMap, u32>, ) -> Option { let matching_tickets: Vec<_> = tickets.iter().filter(|t| self.matches_ticket(t)).collect(); @@ -178,7 +179,7 @@ impl config::Section { } else { let release_notes: Vec<_> = matching_tickets .iter() - .map(|t| t.release_note(variant)) + .map(|t| t.release_note(variant, with_priv_footnote)) .collect(); let template = Leaf { @@ -206,6 +207,7 @@ impl config::Section { tickets: &[&AbstractTicket], prefix: Option<&str>, variant: DocumentVariant, + with_priv_footnote: bool, ticket_stats: &mut HashMap, u32>, ) -> Option { let matching_tickets: Vec<&AbstractTicket> = tickets @@ -227,7 +229,7 @@ impl config::Section { let included_modules: Vec = sections .iter() .filter_map(|s| { - s.modules(&matching_tickets, Some(&module_id), variant, ticket_stats) + s.modules(&matching_tickets, Some(&module_id), variant, with_priv_footnote, ticket_stats) }) .collect(); // If the assembly receives no modules, because all its modules are empty, return None. @@ -261,7 +263,7 @@ impl config::Section { } else { // If the module receives no release notes and its body is empty, return None. // Otherwise, return the module formatted with its release notes. - self.render(&module_id, tickets, variant, ticket_stats) + self.render(&module_id, tickets, variant, with_priv_footnote, ticket_stats) .map(|text| Module { file_name: format!("ref_{module_id}.adoc"), text, @@ -335,6 +337,7 @@ pub fn format_document( tickets: &[&AbstractTicket], template: &config::Template, variant: DocumentVariant, + with_priv_footnote: bool, ) -> Vec { // Prepare a container for ticket usage statistics. let mut ticket_stats = HashMap::new(); @@ -354,7 +357,7 @@ pub fn format_document( let chapters: Vec<_> = template .chapters .iter() - .filter_map(|section| section.modules(tickets, None, variant, &mut ticket_stats)) + .filter_map(|section| section.modules(tickets, None, variant, with_priv_footnote, &mut ticket_stats)) .collect(); log::debug!("Chapters: {:#?}", chapters);