-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional boolean templates; #69
Conversation
Hmmm, why use these Do we know if Kyle is planning on adding parsing for a shorthand |
I think we should wait for @kylef to chime on this one. Not sure adding a |
I am wondering what the use-case is here. Would they be used in an Thanks to stencilproject/Stencil#143 there is an {% if "thing" not in collection %}
{% endif %} (I don't recall if filters are supported in if statements, but something like the following may work or be easy to implement): {% if not collection|hasPrefix:"test" %}
{% endif %} |
@kylef @AliSoftware to be honest, the most reason is to be able to easily remove filters from Generally speaking I'm fine to not merge this PR as it's actually not as generic as it should be especially with |
|
Again, my only concern is that some boolean filters (the ones in Stencil proper) will not have this kind of I think we can approve this for now, at least to go forward, but it would be better to convince @kylef to include that logic in Stencil proper in a later time for consistency between all boolean filters. |
Sources/Environment.swift
Outdated
@@ -15,6 +15,11 @@ public extension Extension { | |||
|
|||
// MARK: - Private | |||
|
|||
private func registerBooleanFilterWithArguments(_ name: String, filter: @escaping Filters.BooleanWithArguments) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just nitpicking, but I wonder if we shouldn't just call this method registerFilter
like all the others — and let the type overloading do the magic of using the proper version of registerFilter
depending on the kind of filter passed…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Antondomashnev up to you, but I think its good idea to leverage inference here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AliSoftware @krzysztofzablocki yes, it's a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, I've tried it but I forgot that call original registerFilter
inside the registerBooleanFilterWithArguments
and it leads to the recursion 😞 @krzysztofzablocki @AliSoftware do you have any idea how to workaround it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using as
to specify the overload you want to call should do it I think
typealias AnyFilter = (Any?, [Any?]) throws -> Any?
registerFilter(name, filter: filter as AnyFilter)
registerFilter("!\(name)", filter: { value, arguments in try !filter(value, arguments) } as AnyFilter)
f34d002
to
c3e9188
Compare
c3e9188
to
19a784c
Compare
FYI I created a PR that will add this functionality to Stencil stencilproject/Stencil#160 |
This is a result of the work on the Sourcery task. It brings the negative counterpart for
Strings+Boolean
filters:!contains
!hasPrefix
!hasSuffix
@AliSoftware @djbe I'm not sure whether we need to update docs or not, from my point of view we don't 😄