Skip to content

Commit

Permalink
Merge pull request #383 from gjtorikian/ignore-dirs-for-zeitwerk
Browse files Browse the repository at this point in the history
Have Zeitwerk not automatically load filters
  • Loading branch information
gjtorikian authored Aug 16, 2023
2 parents a2e02ac + 716e537 commit e848621
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 11 deletions.
16 changes: 13 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: daily
interval: weekly
day: monday
time: "09:00"
timezone: "Etc/UTC"
groups:
github-actions:
patterns:
- "*"
open-pull-requests-limit: 10

- package-ecosystem: "bundler"
- package-ecosystem: bundler
directory: "/"
schedule:
interval: daily
interval: weekly
day: monday
time: "09:00"
timezone: "Etc/UTC"
open-pull-requests-limit: 10
groups:
bundler-dependencies:
patterns:
- "*"
20 changes: 14 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 Expand Up @@ -267,6 +267,14 @@ gem "rouge"
When developing a custom filter, call `HTMLPipeline.require_dependency` at the start to ensure that the local machine has the necessary dependency. You can also use `HTMLPipeline.require_dependencies` to provide a list of dependencies to check.

On a similar note, you must manually require whichever filters you desire:

```ruby
require "html_pipeline" # must be included
require "html_pipeline/convert_filter/markdown_filter" # included because you want to use this filter
require "html_pipeline/node_filter/mention_filter" # included because you want to use this filter
```

## Documentation

Full reference documentation can be [found here](http://rubydoc.info/gems/html-pipeline/frames).
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/node_filter/emoji_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EmojiFilter < NodeFilter

# Build a regexp that matches all valid :emoji: names.
def after_initialize
@emoji_pattern ||= /:(#{emoji_names.map { |name| Regexp.escape(name) }.join('|')}):/
@emoji_pattern ||= /:(#{emoji_names.map { |name| Regexp.escape(name) }.join("|")}):/
end

def selector
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
1 change: 1 addition & 0 deletions test/html_pipeline/convert_filter/markdown_filter_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "test_helper"
require "html_pipeline/convert_filter/markdown_filter"

MarkdownFilter = HTMLPipeline::ConvertFilter::MarkdownFilter

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "test_helper"
require "html_pipeline/node_filter/absolute_source_filter"

AbsoluteSourceFilter = HTMLPipeline::NodeFilter::AbsoluteSourceFilter
class HTMLPipeline
Expand Down
1 change: 1 addition & 0 deletions test/html_pipeline/node_filter/asset_proxy_filter_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "test_helper"
require "html_pipeline/node_filter/asset_proxy_filter"

class HTMLPipeline
class AssetProxyFilterTest < Minitest::Spec
Expand Down
1 change: 1 addition & 0 deletions test/html_pipeline/node_filter/emoji_filter_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "test_helper"
require "html_pipeline/node_filter/emoji_filter"

EmojiFilterFilter = HTMLPipeline::NodeFilter::EmojiFilter
class HTMLPipeline
Expand Down
1 change: 1 addition & 0 deletions test/html_pipeline/node_filter/https_filter_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "test_helper"
require "html_pipeline/node_filter/https_filter"

HttpsFilter = HTMLPipeline::NodeFilter::HttpsFilter

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "test_helper"
require "html_pipeline/node_filter/syntax_highlight_filter"

SyntaxHighlightFilter = HTMLPipeline::NodeFilter::SyntaxHighlightFilter

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "test_helper"
require "html_pipeline/node_filter/table_of_contents_filter"

class HTMLPipeline
class NodeFilter
Expand Down
1 change: 1 addition & 0 deletions test/html_pipeline/node_filter/team_mention_filter_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "test_helper"
require "html_pipeline/node_filter/team_mention_filter"

class HTMLPipeline
class TeamMentionFilterTest < Minitest::Test
Expand Down
1 change: 1 addition & 0 deletions test/html_pipeline/text_filter/image_filter_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "test_helper"
require "html_pipeline/text_filter/image_filter"

ImageFilter = HTMLPipeline::TextFilter::ImageFilter

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "test_helper"
require "html_pipeline/text_filter/plain_text_input_filter"

class HTMLPipeline
class PlainTextInputFilterTest < Minitest::Test
Expand Down
1 change: 1 addition & 0 deletions test/html_pipeline_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "test_helper"
require "helpers/mocked_instrumentation_service"
require "html_pipeline/node_filter/image_max_width_filter"

class HTMLPipelineTest < Minitest::Test
def setup
Expand Down
1 change: 1 addition & 0 deletions test/sanitization_filter_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "test_helper"
require "html_pipeline/node_filter/mention_filter"

class HTMLPipeline
class SanitizationFilterTest < Minitest::Test
Expand Down

0 comments on commit e848621

Please sign in to comment.