File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use anyhow::{bail, Context};
44use clap:: { arg, command} ;
55use rustfmt_wrapper:: rustfmt;
66use std:: path:: Path ;
7+ use tera:: { from_value, to_value, Value } ;
78
89use outputs:: build_output_pairs;
910
@@ -60,7 +61,28 @@ fn main() -> anyhow::Result<()> {
6061 } else {
6162 None
6263 } ;
63- let tera = tera:: Tera :: new ( "templates/**/*.rs.tera" ) . context ( "tera parsing error(s)" ) ?;
64+ let mut tera = tera:: Tera :: new ( "templates/**/*.rs.tera" ) . context ( "tera parsing error(s)" ) ?;
65+ tera. register_filter (
66+ "snake_case" ,
67+ |value : & Value , _: & _ | -> tera:: Result < Value > {
68+ let input = from_value :: < String > ( value. clone ( ) ) ?;
69+ let mut iter = input. chars ( ) ;
70+
71+ let mut string = String :: new ( ) ;
72+
73+ if let Some ( first) = iter. next ( ) {
74+ string. push ( first. to_ascii_lowercase ( ) ) ;
75+
76+ for char in iter {
77+ if char. is_uppercase ( ) {
78+ string. push ( '_' ) ;
79+ }
80+ string. push ( char. to_ascii_lowercase ( ) ) ;
81+ }
82+ }
83+ tera:: Result :: Ok ( to_value ( string) ?)
84+ } ,
85+ ) ;
6486
6587 let repo = git2:: Repository :: open ( GLAM_ROOT ) . context ( "failed to open git repo" ) ?;
6688 let workdir = repo. workdir ( ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments