stencilproject / Stencil

Stencil is a simple and powerful template language for Swift.
https://stencil.fuller.li
BSD 2-Clause "Simplified" License
2.34k stars 223 forks source link

Added map, compact and filter array filters #189

Open ilyapuchka opened 6 years ago

AliSoftware commented 6 years ago

Isn't that a duplicate from the map we have in StencilSwiftKit? I'm all for bringing our generic filters like this one in Stencil proper, but be sure they won't interfere and maybe keep the syntax we used if it's indeed the same idea?

(Disclaimer: I'm on vacation and only skimming thru the issues from my phone so didn't read this in details)

ilyapuchka commented 6 years ago

@AliSoftware this is filter, you have node in StencilSwiftKit as far as I can see.

ilyapuchka commented 6 years ago

@kylef I've solved conflicts so this is ready for review. I also added filter filter that allows using filters and boolean expressions, i.e. items|filter:"$0|isPositive" or items|filter:"$0 > 0", and refactored a bit parsing of expressions so that it matches API for parsing filters

ilyapuchka commented 6 years ago

@kylef I've made some changes here converting filter to filterEach and changing behaviour of filter. Now it will resolve it's argument as filter expression which will allow to apply dynamic filters. The use case for that can be using Sourcery to generated code for Codable and use different key coding strategies applied for different data models. It will allow to specify strategy as a filter in type annotation, i.e. uppercaseFirstLetter or camelCaseToSnakeCase. Currently in template I have to check annotations against hardcoded set of filters to be able to apply them. If you want I can break it out in a separate PR as it is not related to other array filters added here.

ilyapuchka commented 6 years ago

Extracted filter functionality to #203 This now only contains filters for mapping and filtering arrays. Can we merge this @kylef ?

IvanUshakov commented 5 years ago

Do you have any news on this?

opfeffer commented 4 years ago

Curious about the status on this @ilyapuchka. Would love to see this make it in! Thanks

namolnad commented 2 years ago

Hi all, wanted to bump this to see if there was any chance of merging in or updating this PR to get it back to a mergeable state. Happy to help — thanks!