Crates.io | liquid-heck |
lib.rs | liquid-heck |
version | 0.1.0 |
source | src |
created_at | 2024-03-04 06:05:46.263777 |
updated_at | 2024-03-04 06:05:46.263777 |
description | Case conversion (CamelCase, snake_case, ...) filters for Liquid using Heck library. |
homepage | https://github.com/djedi23/liquid-heck |
repository | https://github.com/djedi23/liquid-heck |
max_upload_size | |
id | 1161221 |
size | 20,756 |
Case conversion (CamelCase, snake_case, ...) filters for Liquid using Heck library.
This library provides case conversion filters for the Liquid template engine, utilizing the Heck library for case conversion.
... in filter() |
... in templates |
---|---|
KebabCase | kebabcase |
LowerCamelCase | lowercamelcase |
ShoutyKebabCase | shoutykebabcase |
ShoutySnakeCase | shoutysnakecase |
SnakeCase | snakecase |
TitleCase | titlecase |
TrainCase | traincase |
UpperCamelCase | uppercamelcase |
To use the case conversion filters in your Liquid templates, you first need to register the filters.
use liquid_heck::{UpperCamelCase,SnakeCase,TrainCase};
let template = liquid::ParserBuilder::with_stdlib()
.filter(UpperCamelCase) // Register the filters
.filter(SnakeCase)
.filter(TrainCase)
.build().unwrap()
.parse("{{text | uppercamelcase}} {{text | snakecase}} {{text | traincase}}").unwrap();
let mut globals = liquid::object!({
"text": "Some text to convert"
});
let output = template.render(&globals).unwrap();
assert_eq!(output, "SomeTextToConvert some_text_to_convert Some-Text-To-Convert".to_string());