liquid-heck

Crates.ioliquid-heck
lib.rsliquid-heck
version0.1.0
sourcesrc
created_at2024-03-04 06:05:46.263777
updated_at2024-03-04 06:05:46.263777
descriptionCase conversion (CamelCase, snake_case, ...) filters for Liquid using Heck library.
homepagehttps://github.com/djedi23/liquid-heck
repositoryhttps://github.com/djedi23/liquid-heck
max_upload_size
id1161221
size20,756
Moïse Valvassori (djedi23)

documentation

README

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());
Commit count: 0

cargo fmt