Skip to content

Commit 39ff79f

Browse files
committed
Add the --no-examples option to remove sample content; #4
1 parent c333d38 commit 39ff79f

File tree

7 files changed

+59
-3
lines changed

7 files changed

+59
-3
lines changed

src/cmd_line.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ pub fn get_args() -> ArgMatches<'static> {
7272
.long("no-comments")
7373
.help("Generate the file without any comments"),
7474
)
75+
.arg(
76+
Arg::with_name("no-examples")
77+
.short("E")
78+
.long("no-examples")
79+
.alias("expert-mode")
80+
.help("Generate the file without any example, placeholder content"),
81+
)
7582
.arg(
7683
Arg::with_name("detect-directory")
7784
.short("D")

src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use module::{Input, Module, ModuleType};
1010
pub struct Options {
1111
comments: bool,
1212
prefixes: bool,
13+
examples: bool,
1314
target_dir: String,
1415
detect_directory: bool,
1516
}
@@ -22,8 +23,9 @@ fn main() {
2223
// Comments and prefixes are enabled (true) by default unless you disable them
2324
// on the command line. If the no-comments or no-prefixes option is passed
2425
// (occurences > 0), the feature is disabled, so the option is set to false.
25-
comments: cmdline_args.occurrences_of("no-comments") == 0,
26-
prefixes: cmdline_args.occurrences_of("no-prefixes") == 0,
26+
comments: !cmdline_args.is_present("no-comments"),
27+
prefixes: !cmdline_args.is_present("no-prefixes"),
28+
examples: !cmdline_args.is_present("no-examples"),
2729
// Set the target directory as specified or fall back on the current directory
2830
target_dir: if let Some(dir) = cmdline_args.value_of("target-dir") {
2931
String::from(dir)

src/module.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,34 @@ impl Input {
255255

256256
template_with_replacements =
257257
template_with_replacements.replace("${include_statements}", &includes_text);
258-
} else {
258+
} else if self.options.examples {
259259
template_with_replacements = template_with_replacements
260260
.replace("${include_statements}", "Include modules here.");
261+
} else {
262+
template_with_replacements = template_with_replacements
263+
.replace("${include_statements}\n", "");
264+
}
265+
266+
// If the `--no-examples` option is active, remove all lines between the <example> tags.
267+
if !self.options.examples {
268+
let examples: Regex = RegexBuilder::new(r"^// <example>\n[\s\S]*\n^// </example>\n")
269+
.multi_line(true)
270+
.swap_greed(true)
271+
.build()
272+
.unwrap();
273+
template_with_replacements = examples
274+
.replace_all(&template_with_replacements, "")
275+
.to_string();
276+
// If the `--no-examples` option isn't active, remove just the <example> tags.
277+
} else {
278+
let example_tags: Regex = RegexBuilder::new(r"^// </?example>\n")
279+
.multi_line(true)
280+
.swap_greed(true)
281+
.build()
282+
.unwrap();
283+
template_with_replacements = example_tags
284+
.replace_all(&template_with_replacements, "")
285+
.to_string();
261286
}
262287

263288
// If comments are disabled via an option, delete comment lines from the content

templates/assembly.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ endif::[]
2626
:context: ${module_id}
2727
// The `context` attribute enables module reuse. Every module's ID includes {context}, which ensures that the module has a unique ID even if it is reused multiple times in a guide.
2828
29+
// <example>
2930
This paragraph is the assembly introduction. It explains what the user will accomplish by working through the modules in the assembly and sets the context for the user story the assembly is based on. Can include more than one paragraph. Consider using the information from the user story.
31+
// </example>
3032
3133
.Prerequisites
3234
35+
// <example>
3336
* A bulleted list of conditions that must be satisfied before the user starts following this assembly.
3437
* You can also link to other modules or assemblies the user must follow before starting this assembly.
3538
* Delete the section title and bullets if the assembly has no prerequisites.
39+
// </example>
3640
3741
// The following include statements pull in the module files that comprise the assembly. Include any combination of concept, procedure, or reference modules required to cover the user story. You can also include other assemblies.
3842
@@ -46,9 +50,11 @@ ${include_statements}
4650
4751
== Additional resources (or Next steps)
4852
53+
// <example>
4954
* A bulleted list of links to other material closely related to the contents of the assembly, including xref links to other assemblies in your collection.
5055
* For more details on writing assemblies, see the link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
5156
* Use a consistent system for file names, IDs, and titles. For tips, see _Anchor Names and File Names_ in link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
57+
// </example>
5258

5359
// Restore the context to what it was before this assembly.
5460
ifdef::parent-context-of-${module_id}[:context: {parent-context-of-${module_id}}]

templates/concept.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// In the title of concept modules, include nouns or noun phrases that are used in the body text. This helps readers and search engines find the information quickly.
1515
// Do not start the title of concept modules with a verb. See also _Wording of headings_ in _The IBM Style Guide_.
1616

17+
// <example>
1718
A short introductory paragraph is required for the concept module.
1819
It will provide an overview of the module.
1920

@@ -22,11 +23,14 @@ The contents of a concept module give the user descriptions and explanations nee
2223
* Look at nouns and noun phrases in related procedure modules and assemblies to find the concepts to explain to users.
2324
* Explain only things that are visible to users. Even if a concept is interesting, it probably does not require explanation if it is not visible to users.
2425
* Do not include any instructions to perform an action, such as executing a command. Action items belong in procedure modules.
26+
// </example>
2527

2628
.Additional resources
2729

30+
// <example>
2831
* A bulleted list of links to other material closely related to the contents of the concept module.
2932
* Currently, modules cannot include xrefs, so you cannot include links to other content in your collection. If you need to link to another assembly, add the xref to the assembly that includes this module.
3033
* For more details on writing concept modules, see the link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
3134
* Use a consistent system for file names, IDs, and titles. For tips, see _Anchor Names and File Names_ in link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
35+
// </example>
3236

templates/procedure.adoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,39 @@
1313
= ${module_title}
1414
// Start the title of a procedure module with a verb, such as Creating or Create. See also _Wording of headings_ in _The IBM Style Guide_.
1515

16+
// <example>
1617
This paragraph is the procedure module introduction: a short description of the procedure.
18+
// </example>
1719

1820
.Prerequisites
1921

22+
// <example>
2023
* A bulleted list of conditions that must be satisfied before the user starts following this assembly.
2124
* You can also link to other modules or assemblies the user must follow before starting this assembly.
2225
* Delete the section title and bullets if the assembly has no prerequisites.
26+
// </example>
2327

2428
.Procedure
2529

30+
// <example>
2631
. Start each step with an active verb.
2732
. Include one command or action per step.
2833
. Use an unnumbered bullet (*) if the procedure includes only one step.
34+
// </example>
2935

3036
.Verification steps
3137

38+
// <example>
3239
. Optional: Provide the user with verification method(s) for the procedure, such as expected output or commands that can be used to check for success or failure.
3340
. Use an unnumbered bullet (*) if the procedure includes only one step.
41+
// </example>
3442

3543
.Additional resources
3644

45+
// <example>
3746
* A bulleted list of links to other material closely related to the contents of the procedure module.
3847
* Currently, modules cannot include xrefs, so you cannot include links to other content in your collection. If you need to link to another assembly, add the xref to the assembly that includes this module.
3948
* For more details on writing procedure modules, see the link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
4049
* Use a consistent system for file names, IDs, and titles. For tips, see _Anchor Names and File Names_ in link:https://github.com/redhat-documentation/modular-docs#modular-documentation-reference-guide[Modular Documentation Reference Guide].
50+
// </example>
4151

templates/reference.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
= ${module_title}
1414
// In the title of a reference module, include nouns that are used in the body text. For example, "Keyboard shortcuts for ___" or "Command options for ___." This helps readers and search engines find the information quickly.
1515

16+
// <example>
1617
A short introductory paragraph is required for the reference module.
1718
It will provide an overview of the module.
1819

@@ -37,4 +38,5 @@ Term 2:: Definition
3738
|Row 1, column 1|Row 1, column 2|Row 1, column 3
3839
|Row 2, column 1|Row 2, column 2|Row 2, column 3
3940
|====
41+
// </example>
4042

0 commit comments

Comments
 (0)