From d5119133fc03694c6644cac9e307d1d496fc9bf2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Aug 2018 11:03:22 +0300 Subject: heck --- crates/tools/Cargo.toml | 1 + crates/tools/src/main.rs | 18 ++++++------------ 2 files changed, 7 insertions(+), 12 deletions(-) (limited to 'crates/tools') 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" clap = "2.32.0" failure = "0.1.1" commandspec = "0.10" +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; extern crate walkdir; #[macro_use] extern crate commandspec; +extern crate heck; use clap::{App, Arg, SubCommand}; +use heck::{CamelCase, ShoutySnakeCase}; use std::{ collections::HashMap, fs, @@ -87,18 +89,10 @@ fn render_template(template: &str) -> Result { .map_err(|e| format_err!("template error: {:?}", e))?; tera.register_global_function("concat", Box::new(concat)); tera.register_filter("camel", |arg, _| { - Ok(arg.as_str().unwrap() - .split("_") - .flat_map(|word| { - word.chars() - .next().unwrap() - .to_uppercase() - .chain( - word.chars().skip(1).flat_map(|c| c.to_lowercase()) - ) - }) - .collect::() - .into()) + Ok(arg.as_str().unwrap().to_camel_case().into()) + }); + tera.register_filter("SCREAM", |arg, _| { + Ok(arg.as_str().unwrap().to_shouty_snake_case().into()) }); let ret = tera .render("grammar", &grammar) -- cgit v1.2.3