Pass context along to every part of the pipeline#403
Merged
Conversation
84ac3d0 to
6f51e52
Compare
nekketsuuu
approved these changes
Apr 27, 2024
nekketsuuu
left a comment
There was a problem hiding this comment.
Thanks for this patch! This works out for my use case.
|
|
||
| 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.
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.
| 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.
nits
- I think it's more natural if
yeHis converted only ifcontext[:no_bolding]is false. unless XXX == falseis difficult to read.- We can safely remove
== trueor== false, andnilshould be treated as falsy.
Suggested change
| input.gsub("yeH", "**yeH**") unless context[:no_bolding] == false | |
| input.gsub("yeH", "**yeH**") unless context[:no_bolding] |
Test cases are also affected.
Owner
Author
There was a problem hiding this comment.
Oh you’re quite right. I was hurriedly putting together a test here!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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