Skip to content

Conversation

@xyzshantaram
Copy link

This PR will fix #587 if merged.

I'm very new to Rust programming, my apologies if I've done something wrong here.
I've added a case_sensitive argument that when set to false will make the sorting case insensitive. Here's the code I used to test it.

use serde::{Deserialize, Serialize}; use tera::{Context, Tera}; #[derive(Deserialize, Serialize, Debug, Clone)] struct Person { name: String, } fn main() -> Result<(), tera::Error> { // Use globbing let tera = match Tera::new("templates/**/*.html") { Ok(t) => t, Err(e) => { println!("Parsing error(s): {}", e); ::std::process::exit(1); } }; let persons: Vec<Person> = vec![ Person { name: "Robert".into(), }, Person { name: "paul".into(), }, ]; let mut ctx = Context::new(); ctx.try_insert("persons", &persons)?; println!("{}", tera.render("foo.html", &ctx)?); Ok(()) }

With the following template

<div> {% for person in persons | sort(attribute="name") %} <div> {{person.name}} </div> {%endfor%} </div>

The output is

<div> <div> Robert </div> <div> paul </div> </div>

With case_sensitive=false

<div> {% for person in persons | sort(case_sensitive=false, attribute="name") %} <div> {{person.name}} </div> {%endfor%} </div>

The output becomes:

<div> <div> paul </div> <div> Robert </div> </div>

Please let me know if there's anything else I need to do before this can be merged.

@xyzshantaram xyzshantaram changed the title add case-sensitivity arg to sort filter add case-sensitive arg to sort filter Nov 29, 2021
@Keats
Copy link
Owner

Keats commented Aug 8, 2022

Sorry completely missed that. I'll have a look

@Keats Keats changed the base branch from master to next August 13, 2022 20:08
@Keats
Copy link
Owner

Keats commented Aug 13, 2022

The code looks ok. It's missing some tests so I won't merge it right now, probably for the version after though.

@Keats Keats deleted the branch Keats:next August 14, 2022 11:57
@Keats Keats closed this Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants