liquid-heck

Case conversion (CamelCase, snake_case, ...) filters for Liquid using Heck library

1 unstable release

0.1.0 Mar 4, 2024

MIT license

15KB
311 lines

liquid-heck

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

Example

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());

Dependencies

~6–8MB
~153K SLoC