Skip to content

Commit

Permalink
casing helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed May 14, 2024
1 parent b840f6a commit bb669a9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/templates_scaffolding_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ thiserror = "1.0.58"
file_tree_utils = { path = "../file_tree_utils" }
build-fs-tree = "0.4"
handlebars ="5.1.2"
convert_case = "0.6.0"
25 changes: 24 additions & 1 deletion crates/templates_scaffolding_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::{collections::BTreeMap, path::PathBuf};

use convert_case::{Case, Casing};
use file_tree_utils::{
file_content, find_files, flatten_file_tree, unflatten_file_tree, FileTree, FileTreeError,
};
use handlebars::Handlebars;
use handlebars::{handlebars_helper, Handlebars};
use regex::Regex;
use serde::Serialize;
use thiserror::Error;
Expand Down Expand Up @@ -217,3 +218,25 @@ pub fn render_template_file_tree_and_merge_with_existing<'a, T: Serialize>(

Ok(file_tree)
}

pub fn register_case_helpers<'a>(mut h: Handlebars<'a>) -> Handlebars<'a> {
handlebars_helper!(title_case: |s: String| s.to_case(Case::Title));
h.register_helper("title_case", Box::new(title_case));

handlebars_helper!(lower_case: |s: String| s.to_case(Case::Lower));
h.register_helper("lower_case", Box::new(lower_case));

handlebars_helper!(snake_case: |s: String| s.to_case(Case::Snake));
h.register_helper("snake_case", Box::new(snake_case));

handlebars_helper!(kebab_case: |s: String| s.to_case(Case::Kebab));
h.register_helper("kebab_case", Box::new(kebab_case));

handlebars_helper!(camel_case: |s: String| s.to_case(Case::Camel));
h.register_helper("camel_case", Box::new(camel_case));

handlebars_helper!(pascal_case: |s: String| s.to_case(Case::Pascal));
h.register_helper("pascal_case", Box::new(pascal_case));

h
}

0 comments on commit bb669a9

Please sign in to comment.