liquid.cr icon indicating copy to clipboard operation
liquid.cr copied to clipboard

Implement all filters

Open TechMagister opened this issue 8 years ago • 6 comments
trafficstars

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

TechMagister avatar Jan 01 '17 14:01 TechMagister

Going to try helping where I can :), already did my first PR for downcase.

exts avatar Jan 14 '17 15:01 exts

Thanks for your contribution 🍰

TechMagister avatar Jan 14 '17 16:01 TechMagister

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?

exts avatar Jan 16 '17 08:01 exts

Using the [] operator can be a solution, but it means that the map filter will be restricted to hash :/

TechMagister avatar Jan 16 '17 10:01 TechMagister

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.

exts avatar Jan 16 '17 12:01 exts

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.

exts avatar Jan 16 '17 13:01 exts