Skip to content

Commit

Permalink
Have Zeitwerk not automatically load filters
Browse files Browse the repository at this point in the history
This causes problems if the underlying filter is not called, because
Zeitwerk attempts to laod the required dependencies

cf https://github.com/fxn/zeitwerk#use-case-the-adapter-pattern
  • Loading branch information
gjtorikian committed Aug 16, 2023
1 parent a2e02ac commit 5fec5a2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ end

pipeline = HTMLPipeline.new(
text_filters: [HelloJohnnyFilter.new]
convert_filter: HTMLPipeline::ConvertFilter::MarkdownFilter.new),
convert_filter: HTMLPipeline::ConvertFilter::MarkdownFilter.new,
# note: next line is not needed as sanitization occurs by default;
# see below for more info
sanitization_config: HTMLPipeline::SanitizationFilter::DEFAULT_CONFIG,
Expand Down Expand Up @@ -126,8 +126,8 @@ context = {

# Pipeline used for user provided content on the web
MarkdownPipeline = HTMLPipeline.new (
text_filters: [HTMLPipeline::TextFilter::ImageMaxWidthFilter.new],
convert_filter: [HTMLPipeline::ConvertFilter::MarkdownFilter.new],
text_filters: [HTMLPipeline::TextFilter::ImageFilter.new],
convert_filter: HTMLPipeline::ConvertFilter::MarkdownFilter.new,
node_filters: [
HTMLPipeline::NodeFilter::HttpsFilter.new,HTMLPipeline::NodeFilter::MentionFilter.new,
], context: context)
Expand All @@ -137,7 +137,7 @@ MarkdownPipeline = HTMLPipeline.new (
HtmlEmailPipeline = HTMLPipeline.new(
text_filters: [
PlainTextInputFilter.new,
ImageMaxWidthFilter.new
ImageFilter.new
], {})
```

Expand Down Expand Up @@ -173,7 +173,7 @@ pipeline = HTMLPipeline.new \
text_filters: [
HTMLPipeline::MarkdownFilter,
],
convert_filter: [HTMLPipeline::ConvertFilter::MarkdownFilter.new],
convert_filter: HTMLPipeline::ConvertFilter::MarkdownFilter.new,
sanitization_config: ALLOWLIST

result = pipeline.call <<-CODE
Expand Down Expand Up @@ -201,7 +201,7 @@ pipeline = HTMLPipeline.new \
text_filters: [
HTMLPipeline::MarkdownFilter,
],
convert_filter: [HTMLPipeline::ConvertFilter::MarkdownFilter.new],
convert_filter: HTMLPipeline::ConvertFilter::MarkdownFilter.new,
sanitization_config: nil
```

Expand Down
5 changes: 5 additions & 0 deletions lib/html_pipeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

require "zeitwerk"
lib_dir = File.join(File.dirname(__dir__), "lib")
lib_html_pipeline_dir = File.join(File.dirname(__dir__), "lib", "html_pipeline")
gem_loader = Zeitwerk::Loader.for_gem
gem_loader.inflector.inflect(
"html_pipeline" => "HTMLPipeline",
)

gem_loader.ignore(File.join(lib_html_pipeline_dir, "convert_filter"))
gem_loader.ignore(File.join(lib_html_pipeline_dir, "node_filter"))
gem_loader.ignore(File.join(lib_html_pipeline_dir, "text_filter"))
gem_loader.ignore(File.join(lib_dir, "html-pipeline.rb"))
gem_loader.setup

Expand Down
2 changes: 1 addition & 1 deletion lib/html_pipeline/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class HTMLPipeline
VERSION = "3.0.0.pre5"
VERSION = "3.0.0.pre6"
end

0 comments on commit 5fec5a2

Please sign in to comment.