diff options
Diffstat (limited to 'crates/tools')
-rw-r--r-- | crates/tools/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/tools/src/main.rs | 18 |
2 files changed, 7 insertions, 12 deletions
diff --git a/crates/tools/Cargo.toml b/crates/tools/Cargo.toml index 856f7d8cb..32a6fbc91 100644 --- a/crates/tools/Cargo.toml +++ b/crates/tools/Cargo.toml | |||
@@ -12,3 +12,4 @@ tera = "0.11" | |||
12 | clap = "2.32.0" | 12 | clap = "2.32.0" |
13 | failure = "0.1.1" | 13 | failure = "0.1.1" |
14 | commandspec = "0.10" | 14 | commandspec = "0.10" |
15 | heck = "0.3.0" | ||
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index d42d3ecb7..b56be141a 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs | |||
@@ -7,8 +7,10 @@ extern crate tools; | |||
7 | extern crate walkdir; | 7 | extern crate walkdir; |
8 | #[macro_use] | 8 | #[macro_use] |
9 | extern crate commandspec; | 9 | extern crate commandspec; |
10 | extern crate heck; | ||
10 | 11 | ||
11 | use clap::{App, Arg, SubCommand}; | 12 | use clap::{App, Arg, SubCommand}; |
13 | use heck::{CamelCase, ShoutySnakeCase}; | ||
12 | use std::{ | 14 | use std::{ |
13 | collections::HashMap, | 15 | collections::HashMap, |
14 | fs, | 16 | fs, |
@@ -87,18 +89,10 @@ fn render_template(template: &str) -> Result<String> { | |||
87 | .map_err(|e| format_err!("template error: {:?}", e))?; | 89 | .map_err(|e| format_err!("template error: {:?}", e))?; |
88 | tera.register_global_function("concat", Box::new(concat)); | 90 | tera.register_global_function("concat", Box::new(concat)); |
89 | tera.register_filter("camel", |arg, _| { | 91 | tera.register_filter("camel", |arg, _| { |
90 | Ok(arg.as_str().unwrap() | 92 | Ok(arg.as_str().unwrap().to_camel_case().into()) |
91 | .split("_") | 93 | }); |
92 | .flat_map(|word| { | 94 | tera.register_filter("SCREAM", |arg, _| { |
93 | word.chars() | 95 | Ok(arg.as_str().unwrap().to_shouty_snake_case().into()) |
94 | .next().unwrap() | ||
95 | .to_uppercase() | ||
96 | .chain( | ||
97 | word.chars().skip(1).flat_map(|c| c.to_lowercase()) | ||
98 | ) | ||
99 | }) | ||
100 | .collect::<String>() | ||
101 | .into()) | ||
102 | }); | 96 | }); |
103 | let ret = tera | 97 | let ret = tera |
104 | .render("grammar", &grammar) | 98 | .render("grammar", &grammar) |