Comments (8)
I an not considering this closed, but the |items
filter landed in main.
from minijinja.
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.
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.
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.
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.
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.
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 asis startingwith
)str.endswith
(same asis 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.
I decided on no longer implementing this.
from minijinja.
Related Issues (20)
- Obtain eval type of an expression [question] HOT 2
- Support for formatting dates HOT 2
- Loader FnMut and lifetime HOT 4
- raw/endraw includes raw/endraw tags in the output HOT 2
- just a suggestion: comparison between minijinja and tera HOT 1
- impl ArgType for datetime? HOT 3
- None value is converted to string when passed down to filter HOT 2
- Ability to add entries to a Value HOT 6
- {{}} in {%%} cannot work HOT 2
- Please support converting to FluentValue HOT 2
- auto impl ArgType trait for a Deserializeable value. HOT 7
- Wrong datetime iso format
- Macros are not callable when transported to other state HOT 2
- filter `indent` escapes HTML to `<` and `>` HOT 1
- Request: support keeping trailing newlines from templates HOT 1
- Support for localization HOT 1
- `ops::int_div` panics on overflow HOT 2
- Capturing a global attribute in a macro leads to leaking memory HOT 6
- Overload binary operators for a custom type HOT 2
- Allow prepending a directory path for errors HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minijinja.