aboutsummaryrefslogtreecommitdiff
path: root/crates/tools
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-11 09:03:22 +0100
committerAleksey Kladov <[email protected]>2018-08-11 09:03:22 +0100
commitd5119133fc03694c6644cac9e307d1d496fc9bf2 (patch)
treec8498441aa91abc5af44ed9f978c98dd419495ab /crates/tools
parent78f41ea707cc8aeaa8d1ba8a7216cb8712f13e98 (diff)
heck
Diffstat (limited to 'crates/tools')
-rw-r--r--crates/tools/Cargo.toml1
-rw-r--r--crates/tools/src/main.rs18
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"
12clap = "2.32.0" 12clap = "2.32.0"
13failure = "0.1.1" 13failure = "0.1.1"
14commandspec = "0.10" 14commandspec = "0.10"
15heck = "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;
7extern crate walkdir; 7extern crate walkdir;
8#[macro_use] 8#[macro_use]
9extern crate commandspec; 9extern crate commandspec;
10extern crate heck;
10 11
11use clap::{App, Arg, SubCommand}; 12use clap::{App, Arg, SubCommand};
13use heck::{CamelCase, ShoutySnakeCase};
12use std::{ 14use 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)