@@ -12,12 +12,11 @@ pub enum ModuleType {
1212/// A representation of the module with all its metadata and the generated AsciiDoc content
1313#[ derive( Debug ) ]
1414pub struct Module {
15- pub mod_type : ModuleType ,
16- pub title : String ,
17- pub id : String ,
15+ mod_type : ModuleType ,
16+ title : String ,
17+ id : String ,
1818 pub file_name : String ,
1919 pub include_statement : String ,
20- pub text : String ,
2120 included : Option < Vec < String > > ,
2221}
2322
@@ -38,19 +37,18 @@ impl Module {
3837 let id = Module :: convert_title_to_id ( & title) ;
3938 let file_name = Module :: compose_file_name ( & id, & mod_type, & options) ;
4039 let include_statement = Module :: compose_include_statement ( & file_name) ;
41- let text = Module :: compose_text ( & title, & id, & mod_type, None , & options) ;
4240
4341 Module {
4442 mod_type,
4543 title,
4644 id,
4745 file_name,
4846 include_statement,
49- text,
5047 included : None ,
5148 }
5249 }
5350
51+ /// Set the optional include statements for files that this assembly includes
5452 pub fn includes ( mut self , include_statements : Vec < String > ) -> Self {
5553 self . included = Some ( include_statements) ;
5654 self
@@ -135,25 +133,22 @@ impl Module {
135133
136134 /// Perform string replacements in the modular template that matches the `ModuleType`.
137135 /// Return the template text with all replacements.
138- fn compose_text (
139- title : & str ,
140- module_id : & str ,
141- module_type : & ModuleType ,
142- includes : Option < & [ String ] > ,
136+ pub fn compose_text (
137+ & self ,
143138 options : & Options ,
144139 ) -> String {
145140 // TODO: Add a comment in the generated file with a pre-filled include statement
146141
147142 // Pick the right template
148- let current_template = match module_type {
143+ let current_template = match self . mod_type {
149144 ModuleType :: Assembly => ASSEMBLY_TEMPLATE ,
150145 ModuleType :: Concept => CONCEPT_TEMPLATE ,
151146 ModuleType :: Procedure => PROCEDURE_TEMPLATE ,
152147 ModuleType :: Reference => REFERENCE_TEMPLATE ,
153148 } ;
154149
155150 // Define the strings that will be replaced in the template
156- let replacements = [ ( "${module_title}" , title) , ( "${module_id}" , module_id ) ] ;
151+ let replacements = [ ( "${module_title}" , & self . title ) , ( "${module_id}" , & self . id ) ] ;
157152
158153 // Perform substitutions in the template
159154 // TODO: Create a separate function to perform a replacement
@@ -163,12 +158,12 @@ impl Module {
163158 template_with_replacements = template_with_replacements. replace ( old, new) ;
164159 }
165160
166- if let Some ( includes ) = includes {
161+ if let Some ( include_statements ) = & self . included {
167162 // The includes should never be empty thanks to the required group in clap
168- assert ! ( !includes . is_empty( ) ) ;
163+ assert ! ( !include_statements . is_empty( ) ) ;
169164 // Join the includes into a block of text, with blank lines in between to prevent
170165 // the AsciiDoc syntax to blend between modules
171- let includes_text = includes . join ( "\n \n " ) ;
166+ let includes_text = include_statements . join ( "\n \n " ) ;
172167
173168 template_with_replacements =
174169 template_with_replacements. replace ( "${include_statements}" , & includes_text) ;
0 commit comments