-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
Pass context along to every part of the pipeline #403
Conversation
84ac3d0
to
6f51e52
Compare
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.
Thanks for this patch! This works out for my use case.
end | ||
end | ||
|
||
unless @node_filters.empty? | ||
instrument("call_node_filters.html_pipeline", payload) do | ||
@node_filters.each { |filter| filter.context = (filter.context || {}).merge(context) } |
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.
IMHO: This line might not align with the text_filters and convert_filter, as they pass the new context directly without merging. However this can be a non-problem since it's up to each text_filter and convert_filter to decide whether to overwrite the default context with the passed context or to merge the passed one to the default one.
test/test_helper.rb
Outdated
@@ -25,6 +25,6 @@ def call(input, context: {}, result: {}) | |||
# bolds any instance of the word yeH | |||
class YehBolderFilter < HTMLPipeline::TextFilter | |||
def call(input, context: {}, result: {}) | |||
input.gsub("yeH", "**yeH**") | |||
input.gsub("yeH", "**yeH**") unless context[:no_bolding] == false |
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.
nits
- I think it's more natural if
yeH
is converted only ifcontext[:no_bolding]
is false. unless XXX == false
is difficult to read.- We can safely remove
== true
or== false
, andnil
should be treated as falsy.
input.gsub("yeH", "**yeH**") unless context[:no_bolding] == false | |
input.gsub("yeH", "**yeH**") unless context[:no_bolding] |
Test cases are also affected.
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.
Oh you’re quite right. I was hurriedly putting together a test here!
This PR allows for more correct abstractions around contexts for the pipeline. Context for each filter can now be passed when the filter is instantiated, or, when the pipeline is called. This allows for the same filters and pipelines to execute in different ways, depending on the context at runtime.
Closes #402