Skip to content

Commit a73c939

Browse files
committed
Add a builder method for includes in the populated assembly
1 parent 6a286b4 commit a73c939

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@ fn main() {
6262
if let Some(title) = cmdline_args.value_of("include-in") {
6363
// Gather all include statements for the other modules
6464
// TODO: Figure out if this can be done without calling .to_owned on all the Strings
65-
let includes: Vec<String> = non_populated
65+
let include_statements: Vec<String> = non_populated
6666
.iter()
6767
.map(|module| module.include_statement.to_owned())
6868
.collect();
6969

70-
// The includes should never be empty thanks to the required group in clap
71-
assert!(!includes.is_empty());
70+
// The include_statements should never be empty thanks to the required group in clap
71+
assert!(!include_statements.is_empty());
7272

7373
// Generate the populated assembly module
74-
let populated = Module::new(ModuleType::Assembly, title, Some(&includes), &options);
74+
let populated = Module::new(ModuleType::Assembly, title, &options)
75+
.includes(include_statements);
7576

7677
write_module(&populated, &options);
7778
}
@@ -94,7 +95,7 @@ fn process_module_type(titles: clap::Values, module_type_str: &str, options: &Op
9495
_ => unimplemented!(),
9596
};
9697

97-
let module = Module::new(module_type, title, None, &options);
98+
let module = Module::new(module_type, title, &options);
9899

99100
modules_from_type.push(module);
100101
}

src/module.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct Module {
1818
pub file_name: String,
1919
pub include_statement: String,
2020
pub text: String,
21+
included: Option<Vec<String>>,
2122
}
2223

2324
// Load the AsciiDoc templates at build time
@@ -31,14 +32,13 @@ impl Module {
3132
pub fn new(
3233
mod_type: ModuleType,
3334
title: &str,
34-
includes: Option<&[String]>,
3535
options: &Options,
3636
) -> Module {
3737
let title = String::from(title);
3838
let id = Module::convert_title_to_id(&title);
3939
let file_name = Module::compose_file_name(&id, &mod_type, &options);
4040
let include_statement = Module::compose_include_statement(&file_name);
41-
let text = Module::compose_text(&title, &id, &mod_type, includes, &options);
41+
let text = Module::compose_text(&title, &id, &mod_type, None, &options);
4242

4343
Module {
4444
mod_type,
@@ -47,9 +47,15 @@ impl Module {
4747
file_name,
4848
include_statement,
4949
text,
50+
included: None,
5051
}
5152
}
5253

54+
pub fn includes(mut self, include_statements: Vec<String>) -> Self {
55+
self.included = Some(include_statements);
56+
self
57+
}
58+
5359
/// Create an ID string that is derived from the human-readable title. The ID is usable as:
5460
///
5561
/// * An AsciiDoc section ID

0 commit comments

Comments
 (0)