@@ -61,7 +61,7 @@ pub struct Input {
6161pub struct Module {
6262 mod_type : ContentType ,
6363 title : String ,
64- id : String ,
64+ anchor : String ,
6565 pub file_name : String ,
6666 pub include_statement : String ,
6767 includes : Option < Vec < String > > ,
@@ -108,7 +108,7 @@ impl Input {
108108 /// let options = Options::default();
109109 /// let input = Input::new(mod_type, title, &options);
110110 ///
111- /// assert_eq!("con_a -test-with-problematic-characters", input.id());
111+ /// assert_eq!("a -test-with-problematic-characters", input.id());
112112 /// ```
113113 #[ must_use]
114114 pub fn id ( & self ) -> String {
@@ -188,34 +188,99 @@ impl Input {
188188 title_with_replacements = title_with_replacements[ ..len - 1 ] . to_string ( ) ;
189189 }
190190
191- let prefix = self . prefix ( ) ;
192-
193- format ! ( "{}{}" , prefix, title_with_replacements)
191+ title_with_replacements
194192 }
195193
196194 /// Prepare the file name for the generated file.
197195 ///
198- /// The file name is based on the module ID, with the `.adoc` extension.
196+ /// The file name is based on the module ID,
197+ /// with an optional prefix and the `.adoc` extension.
198+ ///
199+ /// # Examples
200+ ///
201+ /// ```
202+ /// use newdoc::{ContentType, Input, Options};
203+ ///
204+ /// let mod_type = ContentType::Concept;
205+ /// let title = "Default file name configuration";
206+ /// let options = Options::default();
207+ /// let input = Input::new(mod_type, title, &options);
208+ ///
209+ /// assert_eq!("con_default-file-name-configuration.adoc", input.file_name());
210+ ///
211+ /// let mod_type = ContentType::Concept;
212+ /// let title = "No prefix file name configuration";
213+ /// let options = Options {
214+ /// file_prefixes: false,
215+ /// ..Default::default()
216+ /// };
217+ /// let input = Input::new(mod_type, title, &options);
218+ ///
219+ /// assert_eq!("no-prefix-file-name-configuration.adoc", input.file_name());
220+ /// ```
199221 #[ must_use]
200222 pub fn file_name ( & self ) -> String {
223+ // Add a prefix only if they're enabled.
224+ let prefix = if self . options . file_prefixes {
225+ self . prefix ( )
226+ } else {
227+ ""
228+ } ;
229+
230+ let id = self . id ( ) ;
231+
201232 let suffix = ".adoc" ;
202233
203- self . id ( ) + suffix
234+ [ prefix , & id , suffix] . join ( "" )
204235 }
205236
206- fn prefix ( & self ) -> & ' static str {
207- if self . options . prefixes {
208- // If prefixes are enabled, pick the right file prefix
209- match self . mod_type {
210- ContentType :: Assembly => "assembly_" ,
211- ContentType :: Concept => "con_" ,
212- ContentType :: Procedure => "proc_" ,
213- ContentType :: Reference => "ref_" ,
214- ContentType :: Snippet => "snip_" ,
215- }
237+ /// Prepare the AsciiDoc anchor or ID.
238+ ///
239+ /// The anchor is based on the module ID, with an optional prefix.
240+ ///
241+ /// # Examples
242+ ///
243+ /// ```
244+ /// use newdoc::{ContentType, Input, Options};
245+ ///
246+ /// let mod_type = ContentType::Concept;
247+ /// let title = "Default anchor configuration";
248+ /// let options = Options::default();
249+ /// let input = Input::new(mod_type, title, &options);
250+ ///
251+ /// assert_eq!("default-anchor-configuration", input.anchor());
252+ ///
253+ /// let mod_type = ContentType::Concept;
254+ /// let title = "Prefix anchor configuration";
255+ /// let options = Options {
256+ /// anchor_prefixes: true,
257+ /// ..Default::default()
258+ /// };
259+ /// let input = Input::new(mod_type, title, &options);
260+ ///
261+ /// assert_eq!("con_prefix-anchor-configuration", input.anchor());
262+ #[ must_use]
263+ pub fn anchor ( & self ) -> String {
264+ // Add a prefix only if they're enabled.
265+ let prefix = if self . options . anchor_prefixes {
266+ self . prefix ( )
216267 } else {
217- // If prefixes are disabled, use an empty string for the prefix
218268 ""
269+ } ;
270+
271+ let id = self . id ( ) ;
272+
273+ [ prefix, & id] . join ( "" )
274+ }
275+
276+ /// Pick the right file and ID prefix depending on the content type.
277+ fn prefix ( & self ) -> & ' static str {
278+ match self . mod_type {
279+ ContentType :: Assembly => "assembly_" ,
280+ ContentType :: Concept => "con_" ,
281+ ContentType :: Procedure => "proc_" ,
282+ ContentType :: Reference => "ref_" ,
283+ ContentType :: Snippet => "snip_" ,
219284 }
220285 }
221286
@@ -285,7 +350,7 @@ impl From<Input> for Module {
285350 let module = Module {
286351 mod_type : input. mod_type ,
287352 title : input. title . clone ( ) ,
288- id : input. id ( ) ,
353+ anchor : input. anchor ( ) ,
289354 file_name : input. file_name ( ) ,
290355 include_statement : input. include_statement ( ) ,
291356 includes : input. includes . clone ( ) ,
@@ -294,7 +359,7 @@ impl From<Input> for Module {
294359
295360 log:: debug!( "Generated module properties:" ) ;
296361 log:: debug!( "Type: {:?}" , & module. mod_type) ;
297- log:: debug!( "ID : {}" , & module. id ) ;
362+ log:: debug!( "Anchor : {}" , & module. anchor ) ;
298363 log:: debug!( "File name: {}" , & module. file_name) ;
299364 log:: debug!( "Include statement: {}" , & module. include_statement) ;
300365 log:: debug!(
@@ -328,7 +393,8 @@ mod tests {
328393 fn basic_options ( ) -> Options {
329394 Options {
330395 comments : false ,
331- prefixes : true ,
396+ file_prefixes : true ,
397+ anchor_prefixes : false ,
332398 examples : true ,
333399 target_dir : PathBuf :: from ( "." ) ,
334400 verbosity : Verbosity :: Default ,
@@ -338,7 +404,8 @@ mod tests {
338404 fn path_options ( ) -> Options {
339405 Options {
340406 comments : false ,
341- prefixes : true ,
407+ file_prefixes : true ,
408+ anchor_prefixes : false ,
342409 examples : true ,
343410 target_dir : PathBuf :: from ( "repo/modules/topic/" ) ,
344411 verbosity : Verbosity :: Default ,
@@ -360,8 +427,8 @@ mod tests {
360427 "A testing assembly with /special-characters*"
361428 ) ;
362429 assert_eq ! (
363- assembly. id ,
364- "assembly_a -testing-assembly-with-special-characters"
430+ assembly. anchor ,
431+ "a -testing-assembly-with-special-characters"
365432 ) ;
366433 assert_eq ! (
367434 assembly. file_name,
0 commit comments