liquid.cr
liquid.cr copied to clipboard
Implement all filters
Filters
- [x] abs
- [x] append
- [x] capitalize
- [x] ceil
- [x] compact
- [x] date
- [x] default
- [x] divided_by
- [x] downcase
- [x] escape
- [x] escape_once
- [x] first
- [x] floor
- [x] join
- [x] last
- [x] lstrip
- [x] map
- [x] minus
- [x] modulo
- [x] newline_to_br
- [x] plus
- [x] prepend
- [x] remove
- [x] remove_first
- [x] replace
- [x] replace_first
- [x] reverse
- [x] round
- [x] rstrip
- [x] size
- [x] slice
- [ ] sort
- [ ] sort_natural
- [x] split
- [x] strip
- [x] strip_html
- [x] strip_newlines
- [ ] times
- [ ] truncate
- [ ] truncatewords
- [ ] uniq
Going to try helping where I can :), already did my first PR for downcase.
Thanks for your contribution 🍰
As for the map filter, I don't think that's possible in crystal since you can't call properties/methods dynamically unless you know a way to do it with macros?
Using the [] operator can be a solution, but it means that the map filter will be restricted to hash :/
Maybe this could be a reason for them to support this feature in the language? I ran into a similar issue when trying to create php style dynamic controller/actions as well and was forced to use a single method as the solution :/
I almost had a breakthrough though, basically i found out that constant arrays can be used dynamically in {% for ... %}{% end %} macros, only problem is idk how to create a single value array constant at compile time w/ the data we'd need to run that loop.
actually now looking at the liquid source, it looks like they only really support Enumerable's w/ the map option that responds to []
Guess like you said, that'll have to do for now.
My current solution: https://github.com/exts/liquid.cr/commit/c03a643d26afb8a90e310285d491034d38846d32 will push later once I add more filters.