Git Product home page Git Product logo

Comments (8)

mitsuhiko avatar mitsuhiko commented on May 16, 2024 1

I an not considering this closed, but the |items filter landed in main.

from minijinja.

mitsuhiko avatar mitsuhiko commented on May 16, 2024

It’s something I’m in fact considering but I worry a bit about where this might lead. For now you can use the |dictsort filter.

from minijinja.

mitsuhiko avatar mitsuhiko commented on May 16, 2024

So this could be implemented. One kinda odd consequence is that in Jinja2 foo.items often is ambiguous because it can both address into foo as an item or attribute lookup. In MiniJinja this problem does not exist at the moment because maps and structs don't have attributes on them. Interestingly because of how I choice to implement method calls foo.items() is a method call in MiniJinja and foo.items is an attribute lookup so it's possible to disambiguate them.

I am however not sure how I feel about this. I figured |dictsort is a good compromise because it exists in both Jinja2 and MiniJinja but I can see .items() being very popular in templates.

Related one issue is that MiniJinja currently loses the original order of structs and maps because it feeds everything into a BTreeMap which loses order. It might be interesting to try to have something like a preserve_order feature like serde_json which uses indexmap.

from minijinja.

digitalresistor avatar digitalresistor commented on May 16, 2024

I honestly don't mind losing the original order for keys in a map. I have never relied on them being in a particular order in the first place, but I also understand that I may be an outlier.

.items() was the first thing I tried taking a Jinja2 template I used in a Python project, and thus was kind of surprised I got an error and went hunting for a work-around.

I see why you would be hesitant to add it, since it is directly adding Python behavior/methods on top of Rust, but it may help reduce support costs from a "least surprise" when trying to use this library.

from minijinja.

mitsuhiko avatar mitsuhiko commented on May 16, 2024

I think I'm not completely opposed to the idea but I think I want to explore a bit what other methods actually call that leak out from Python so I get a better idea what I'm signing up for.

from minijinja.

digitalresistor avatar digitalresistor commented on May 16, 2024

I am going to play around a little bit more with existing templates I have, to get a better idea for what I may be missing! Thanks for the consideration!

from minijinja.

mitsuhiko avatar mitsuhiko commented on May 16, 2024

I think these are the potentially interesting methods:

  • str.replace (|replace exists)
  • str.format (I see this used a lot, but that is a lot of work to implement)
  • str.startswith (same as is startingwith)
  • str.endswith (same as is endingwith)
  • str.strip (same as |trim)
  • str.lstrip / str.rstrip (no equivalent)
  • str.split (this one is probably quite useful)
  • str.splitlines (this one is probably useful)
  • str.title / str.capitalize (no equivalent but could be a filter)
  • str.lower / str.upper (filter equivalent in |upper, |lower)
  • dict.values (not sure how useful this is)
  • dict.keys (same as direct iteration but creates a list)
  • dict.items (seems useful, but could in theory be a filter)

from minijinja.

mitsuhiko avatar mitsuhiko commented on May 16, 2024

I decided on no longer implementing this.

from minijinja.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.