diff options
author | Federico Igne <git@federicoigne.com> | 2022-12-30 16:36:38 +0000 |
---|---|---|
committer | Federico Igne <git@federicoigne.com> | 2022-12-30 16:36:38 +0000 |
commit | 79e64869680f012cb282f75eb0f518b94cccebd0 (patch) | |
tree | 544adcbdfb28a8ef914e3c318382ec5399c49f56 | |
parent | 0168e6717641cb16c786eb20bd0d05dcd4911599 (diff) | |
download | pangler-79e64869680f012cb282f75eb0f518b94cccebd0.tar.gz pangler-79e64869680f012cb282f75eb0f518b94cccebd0.zip |
docs: update PDF manual
-rw-r--r-- | README.md | 35 | ||||
-rw-r--r-- | README.pdf | bin | 277696 -> 290388 bytes | |||
-rw-r--r-- | src/main.rs | 27 |
3 files changed, 43 insertions, 19 deletions
@@ -122,9 +122,11 @@ if !id.is_empty() { | |||
122 | let entry = clss.contains(&String::from("entry")); | 122 | let entry = clss.contains(&String::from("entry")); |
123 | let path = attrs | 123 | let path = attrs |
124 | .into_iter() | 124 | .into_iter() |
125 | .find_map(|(k,p)| if k == "path" { Some(p.clone()) } else { None }); | 125 | .find_map(|(k,p)| |
126 | if k == "path" { Some(p.clone()) } else { None }); | ||
126 | if entry || path.is_some() || PATH.is_match(id) { | 127 | if entry || path.is_some() || PATH.is_match(id) { |
127 | let path = PathBuf::from(path.unwrap_or_default()).join(id); | 128 | let path = |
129 | PathBuf::from(path.unwrap_or_default()).join(id); | ||
128 | if path.starts_with(&target) { | 130 | if path.starts_with(&target) { |
129 | Some(Key::Entry(path)) | 131 | Some(Key::Entry(path)) |
130 | } else { | 132 | } else { |
@@ -189,7 +191,13 @@ An alternative way to compile the project is using Docker. | |||
189 | Run the following from the root of the project without the need to install Rust locally. | 191 | Run the following from the root of the project without the need to install Rust locally. |
190 | 192 | ||
191 | ```sh | 193 | ```sh |
192 | docker run --rm --user "$(id -u)":"$(id -g)" -v "$PWD":/usr/src/pangler -w /usr/src/pangler rust:latest cargo build --release | 194 | docker run \ |
195 | --rm \ | ||
196 | --user "$(id -u)":"$(id -g)" \ | ||
197 | --volume "$PWD":/usr/src/pangler \ | ||
198 | --workdir /usr/src/pangler \ | ||
199 | rust:latest \ | ||
200 | cargo build --release | ||
193 | ``` | 201 | ``` |
194 | 202 | ||
195 | See the [official documentation](https://hub.docker.com/_/rust) for more information. | 203 | See the [official documentation](https://hub.docker.com/_/rust) for more information. |
@@ -279,8 +287,8 @@ By default `pangler` will generate all entry points gathered from the input file | |||
279 | This behaviour can be overridden with the `-t/--target` flag. | 287 | This behaviour can be overridden with the `-t/--target` flag. |
280 | 288 | ||
281 | ```{#config_target .rust} | 289 | ```{#config_target .rust} |
282 | /// Limit entry points to those matching the provided prefix | 290 | /// Limit entry points to those matching the given prefix |
283 | #[clap(short, long, value_name = "PREFIX")] | 291 | #[clap(short, long, value_name="PREFIX")] |
284 | target: Option<PathBuf>, | 292 | target: Option<PathBuf>, |
285 | ``` | 293 | ``` |
286 | 294 | ||
@@ -315,7 +323,7 @@ If the output folder does not exists, *it will be created*. | |||
315 | 323 | ||
316 | ```{#config_output .rust} | 324 | ```{#config_output .rust} |
317 | /// Base output directory [default: './'] | 325 | /// Base output directory [default: './'] |
318 | #[clap(short, long, value_name = "PATH")] | 326 | #[clap(short, long, value_name="PATH")] |
319 | output: Option<PathBuf>, | 327 | output: Option<PathBuf>, |
320 | ``` | 328 | ``` |
321 | 329 | ||
@@ -326,7 +334,7 @@ By default, `pangler` will stop after 10 substitution iterations, but this param | |||
326 | 334 | ||
327 | ```{#config_depth .rust} | 335 | ```{#config_depth .rust} |
328 | /// Maximum substitution depth | 336 | /// Maximum substitution depth |
329 | #[clap(short, long, default_value_t = 10, value_name = "N")] | 337 | #[clap(short, long, default_value_t=10, value_name="N")] |
330 | depth: u32, | 338 | depth: u32, |
331 | ``` | 339 | ``` |
332 | 340 | ||
@@ -475,7 +483,9 @@ In case we reach the maximum allowed depth we truncate code block substitution a | |||
475 | if current_depth < max_depth { | 483 | if current_depth < max_depth { |
476 | let block = blocks | 484 | let block = blocks |
477 | .get(&Key::Macro(caps[2].to_string())) | 485 | .get(&Key::Macro(caps[2].to_string())) |
478 | .unwrap_or_else(|| panic!("Block \"{}\" not present", caps[2].to_string())) | 486 | .unwrap_or_else(|| panic!( |
487 | "Block \"{}\" not present", | ||
488 | caps[2].to_string())) | ||
479 | .clone(); | 489 | .clone(); |
480 | indent(block, caps[1].len()) | 490 | indent(block, caps[1].len()) |
481 | } else { | 491 | } else { |
@@ -498,7 +508,9 @@ fn build( | |||
498 | <<regex_macro_lazy>> | 508 | <<regex_macro_lazy>> |
499 | blocks | 509 | blocks |
500 | .iter() | 510 | .iter() |
501 | .filter_map(|(key,code)| { key.get_path().map(|k| (k,code)) }) | 511 | .filter_map(|(key,code)| { |
512 | key.get_path().map(|k| (k,code)) | ||
513 | }) | ||
502 | .for_each(|(path,code)| { | 514 | .for_each(|(path,code)| { |
503 | <<code_generation>> | 515 | <<code_generation>> |
504 | }) | 516 | }) |
@@ -660,7 +672,10 @@ fn write_to_file( | |||
660 | <<parent_directory_creation>> | 672 | <<parent_directory_creation>> |
661 | <<write_to_file>> | 673 | <<write_to_file>> |
662 | } else { | 674 | } else { |
663 | eprintln!("Absolute paths not supported: {}", path.display()) | 675 | eprintln!( |
676 | "Absolute paths not supported: {}", | ||
677 | path.display() | ||
678 | ) | ||
664 | } | 679 | } |
665 | Ok(()) | 680 | Ok(()) |
666 | } | 681 | } |
Binary files differ | |||
diff --git a/src/main.rs b/src/main.rs index acb08ad..44dab99 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -21,13 +21,13 @@ struct Config { | |||
21 | #[clap(short, long)] | 21 | #[clap(short, long)] |
22 | list: bool, | 22 | list: bool, |
23 | /// Maximum substitution depth | 23 | /// Maximum substitution depth |
24 | #[clap(short, long, default_value_t = 10, value_name = "N")] | 24 | #[clap(short, long, default_value_t=10, value_name="N")] |
25 | depth: u32, | 25 | depth: u32, |
26 | /// Base output directory [default: './'] | 26 | /// Base output directory [default: './'] |
27 | #[clap(short, long, value_name = "PATH")] | 27 | #[clap(short, long, value_name="PATH")] |
28 | output: Option<PathBuf>, | 28 | output: Option<PathBuf>, |
29 | /// Limit entry points to those matching the provided prefix | 29 | /// Limit entry points to those matching the given prefix |
30 | #[clap(short, long, value_name = "PREFIX")] | 30 | #[clap(short, long, value_name="PREFIX")] |
31 | target: Option<PathBuf>, | 31 | target: Option<PathBuf>, |
32 | /// Input files | 32 | /// Input files |
33 | input: Vec<PathBuf>, | 33 | input: Vec<PathBuf>, |
@@ -63,7 +63,9 @@ fn build( | |||
63 | } | 63 | } |
64 | blocks | 64 | blocks |
65 | .iter() | 65 | .iter() |
66 | .filter_map(|(key,code)| { key.get_path().map(|k| (k,code)) }) | 66 | .filter_map(|(key,code)| { |
67 | key.get_path().map(|k| (k,code)) | ||
68 | }) | ||
67 | .for_each(|(path,code)| { | 69 | .for_each(|(path,code)| { |
68 | let mut current_depth = 0; | 70 | let mut current_depth = 0; |
69 | let mut code = code.clone(); | 71 | let mut code = code.clone(); |
@@ -73,7 +75,9 @@ fn build( | |||
73 | if current_depth < max_depth { | 75 | if current_depth < max_depth { |
74 | let block = blocks | 76 | let block = blocks |
75 | .get(&Key::Macro(caps[2].to_string())) | 77 | .get(&Key::Macro(caps[2].to_string())) |
76 | .unwrap_or_else(|| panic!("Block \"{}\" not present", caps[2].to_string())) | 78 | .unwrap_or_else(|| panic!( |
79 | "Block \"{}\" not present", | ||
80 | caps[2].to_string())) | ||
77 | .clone(); | 81 | .clone(); |
78 | indent(block, caps[1].len()) | 82 | indent(block, caps[1].len()) |
79 | } else { | 83 | } else { |
@@ -125,7 +129,10 @@ fn write_to_file( | |||
125 | fs::create_dir_all(path.parent().unwrap())?; | 129 | fs::create_dir_all(path.parent().unwrap())?; |
126 | fs::write(path, content)?; | 130 | fs::write(path, content)?; |
127 | } else { | 131 | } else { |
128 | eprintln!("Absolute paths not supported: {}", path.display()) | 132 | eprintln!( |
133 | "Absolute paths not supported: {}", | ||
134 | path.display() | ||
135 | ) | ||
129 | } | 136 | } |
130 | Ok(()) | 137 | Ok(()) |
131 | } | 138 | } |
@@ -156,9 +163,11 @@ fn main() -> Result<()> { | |||
156 | let entry = clss.contains(&String::from("entry")); | 163 | let entry = clss.contains(&String::from("entry")); |
157 | let path = attrs | 164 | let path = attrs |
158 | .into_iter() | 165 | .into_iter() |
159 | .find_map(|(k,p)| if k == "path" { Some(p.clone()) } else { None }); | 166 | .find_map(|(k,p)| |
167 | if k == "path" { Some(p.clone()) } else { None }); | ||
160 | if entry || path.is_some() || PATH.is_match(id) { | 168 | if entry || path.is_some() || PATH.is_match(id) { |
161 | let path = PathBuf::from(path.unwrap_or_default()).join(id); | 169 | let path = |
170 | PathBuf::from(path.unwrap_or_default()).join(id); | ||
162 | if path.starts_with(&target) { | 171 | if path.starts_with(&target) { |
163 | Some(Key::Entry(path)) | 172 | Some(Key::Entry(path)) |
164 | } else { | 173 | } else { |