gjtorikian / html-pipeline

HTML processing filters and utilities
MIT License
2.27k stars 383 forks source link

Fix example code in README #393

Closed ppworks closed 9 months ago

ppworks commented 10 months ago

An error will occur if new is added to the class specified for text_filters.

Reading the source code, it appears that specifying the class is the correct behavior, so I changed the README.

Example

require 'html_pipeline'
require 'html_pipeline/text_filter/image_filter'
pipeline = HTMLPipeline.new(text_filters: [HTMLPipeline::TextFilter::ImageFilter.new])
lib/html_pipeline/text_filter.rb:7:in `initialize': wrong number of arguments (given 0, expected 1) (ArgumentError)
gjtorikian commented 10 months ago

I think actually the README is (aspirationaly) correct, and the code might be wrong. The other filters (node_filters) do expect an object, so I am not sure why I had it such that a class needs to be passed here. 🤔

ppworks commented 10 months ago

Yes I too think that assuming an object is natural.

However, in the current code, if I pass an object by new method, I get an error.

lib/html_pipeline/text_filter.rb:7:ininitialize': wrong number of arguments (given 0, expected 1) (ArgumentError)`

Maybe we should fix the code instead of the README 😄

gjtorikian commented 9 months ago

Maybe we should fix the code instead of the README

Yep--I will do this when I get the chance! Thank you for noticing.

gjtorikian commented 9 months ago

https://github.com/gjtorikian/html-pipeline/pull/398 will address this. Thanks for your PR and bringing this to my attention!