Skip to content

Commit

Permalink
Add titlecase to renamer
Browse files Browse the repository at this point in the history
  • Loading branch information
Marekkon5 committed Jan 9, 2024
1 parent cddf7c8 commit cb3b364
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
18 changes: 18 additions & 0 deletions 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/onetagger-renamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pad = "0.1"
dunce = "1.0"
regex = "1.7"
anyhow = "1.0"
titlecase = "2.2"
lazy_static = "1.4"
pulldown-cmark = "0.9"

Expand Down
3 changes: 2 additions & 1 deletion crates/onetagger-renamer/src/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ lazy_static! {
SymbolDoc::prop("last", "Get the last item in an array"),
];

pub static ref FUNCTIONS: [SymbolDoc; 14] = [
pub static ref FUNCTIONS: [SymbolDoc; 15] = [
SymbolDoc::f("lower", "Convert all to lowercase", vec![]),
SymbolDoc::f("lowercase", "Convert all to lowercase", vec![]),
SymbolDoc::f("upper", "Convert all to uppercase", vec![]),
SymbolDoc::f("uppercase", "Convert all to uppercase", vec![]),
SymbolDoc::f("slice", "Take a range out of array or substring", vec![DocParameter::n("start", true), DocParameter::n("end", false)]),
SymbolDoc::f("range", "Take a range out of array or substring", vec![DocParameter::n("start", true), DocParameter::n("end", false)]),
SymbolDoc::f("capitalize", "Convert first letter to uppercase", vec![]),
SymbolDoc::f("titlecase", "Conver to titlecase (Capitalize Every Word)", vec![]),
SymbolDoc::f("replace", "Replace text. `from` parameter accepts regex expressions.", vec![DocParameter::s("from", true), DocParameter::s("to", true)]),
SymbolDoc::f("pad", "Pad on the left side with given character to reach given length", vec![DocParameter::s("char", true), DocParameter::n("length", true)]),
SymbolDoc::f("sort", "Sort the array alphabetically", vec![]),
Expand Down
5 changes: 5 additions & 0 deletions crates/onetagger-renamer/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,11 @@ impl Token for TokenFunction {
};
Some(Data::String(o))
},
// Convert to title case
"titlecase" => {
let s = data.to_string(&config.separator);
Some(Data::String(titlecase::titlecase(&s)))
},
// Replace string with string
"replace" => {
let from = self.param_str(0, true)?;
Expand Down

0 comments on commit cb3b364

Please sign in to comment.