From d3fc6d9b470d4d55217cdadd48b99d5d0ee264ad Mon Sep 17 00:00:00 2001 From: "Simeon F. Willbanks" Date: Wed, 21 Aug 2013 19:25:18 -0700 Subject: [PATCH 1/8] Filters Manage Dependencies * Add dependency management test cases for each `Filter` with a dependency * Add `assert_dependency_management_error` custom assertion which asserts a custom exception and message are raised if a dependency is missing * Move all `Filter` dependencies to `Gemfile` `:test` block for test cases and CI * Implement `TestingDependency` helper to abstract unloading and loading `Gemfile` `:test` block gems when asserting dependency management errors * Implement `MissingDependencyException` custom exception with `MESSAGE` constant as a format string, so each `Filter` raises a uniform exception * Add `begin..rescue..end` blocks around each `Filter` `require` statement to raise a `MissingDependencyException` when a gem can not be loaded * Update README.md detailing new dependency management with listing of `Filter` gem dependencies * Add gemspec post install message to inform users their apps must bundle `Filter` dependencies --- Gemfile | 21 ++++- README.md | 21 ++++- html-pipeline.gemspec | 18 ++-- lib/html/pipeline.rb | 1 - lib/html/pipeline/autolink_filter.rb | 7 +- lib/html/pipeline/email_reply_filter.rb | 9 +- lib/html/pipeline/emoji_filter.rb | 9 +- lib/html/pipeline/filter.rb | 17 ++++ lib/html/pipeline/markdown_filter.rb | 9 +- lib/html/pipeline/plain_text_input_filter.rb | 9 +- lib/html/pipeline/sanitization_filter.rb | 7 +- lib/html/pipeline/syntax_highlight_filter.rb | 9 +- lib/html/pipeline/textile_filter.rb | 9 +- test/helpers/testing_dependency.rb | 92 +++++++++++++++++++ test/html/pipeline/autolink_filter_test.rb | 4 + test/html/pipeline/email_reply_filter_test.rb | 7 ++ test/html/pipeline/emoji_filter_test.rb | 14 ++- test/html/pipeline/markdown_filter_test.rb | 14 ++- .../pipeline/plain_text_input_filter_test.rb | 4 + .../html/pipeline/sanitization_filter_test.rb | 4 + .../pipeline/syntax_highlight_filter_test.rb | 7 ++ test/html/pipeline/textile_filter_test.rb | 7 ++ test/test_helper.rb | 29 ++++-- 23 files changed, 282 insertions(+), 46 deletions(-) create mode 100644 test/helpers/testing_dependency.rb create mode 100644 test/html/pipeline/email_reply_filter_test.rb create mode 100644 test/html/pipeline/syntax_highlight_filter_test.rb create mode 100644 test/html/pipeline/textile_filter_test.rb diff --git a/Gemfile b/Gemfile index 5b4d46d6..5b6a046f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,24 @@ -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in html-pipeline.gemspec gemspec group :development do - gem 'bundler' - gem 'rake' + gem "bundler" + gem "rake" +end + +group :test do + gem "rinku", "~> 1.7", :require => false + gem "gemoji", "~> 1.0", :require => false + gem "RedCloth", "~> 4.2.9", :require => false + gem "escape_utils", "~> 0.3", :require => false + gem "github-linguist", "~> 2.6.2", :require => false + gem "github-markdown", "~> 0.5", :require => false + + if RUBY_VERSION < "1.9.2" + gem "sanitize", ">= 2", "< 2.0.4", :require => false + else + gem "sanitize", "~> 2.0", :require => false + end end diff --git a/README.md b/README.md index 950b35db..dd651d5c 100644 --- a/README.md +++ b/README.md @@ -98,18 +98,29 @@ filter.call * `TextileFilter` - convert textile to html * `TableOfContentsFilter` - anchor headings with name attributes and generate Table of Contents html unordered list linking headings -## Syntax highlighting +## Dependencies +Filter gem dependencies are not bundled; you must bundle the filter's gem +dependencies. The below list details filters with dependencies. For example, `SyntaxHighlightFilter` uses [github-linguist](https://github.com/github/linguist) -to detect and highlight languages. It isn't included as a dependency by default -because it's a large dependency and -[a hassle to build on heroku](https://github.com/jch/html-pipeline/issues/33). -To use the filter, add the following to your Gemfile: +to detect and highlight languages. To use the `SyntaxHighlightFilter`, +add the following to your Gemfile: ```ruby gem 'github-linguist' ``` +* `AutolinkFilter` - `rinku` +* `EmailReplyFilter` - `escape_utils` +* `EmojiFilter` - `gemoji` +* `MarkdownFilter` - `github-markdown` +* `PlainTextInputFilter` - `escape_utils` +* `SanitizationFilter` - `sanitize` +* `SyntaxHighlightFilter` - `github-linguist` +* `TextileFilter` - `RedCloth` + +_Note:_ See [Gemfile](https://github.com/jch/html-pipeline/blob/master/Gemfile) `:test` block for version requirements. + ## Examples We define different pipelines for different parts of our app. Here are a few diff --git a/html-pipeline.gemspec b/html-pipeline.gemspec index 0fd38289..bf45e3c6 100644 --- a/html-pipeline.gemspec +++ b/html-pipeline.gemspec @@ -15,13 +15,17 @@ Gem::Specification.new do |gem| gem.test_files = gem.files.grep(%r{^test}) gem.require_paths = ["lib"] - gem.add_dependency "gemoji", "~> 1.0" - gem.add_dependency "nokogiri", RUBY_VERSION < "1.9.2" ? [">= 1.4", "< 1.6"] : "~> 1.4" - gem.add_dependency "github-markdown", "~> 0.5" - gem.add_dependency "sanitize", RUBY_VERSION < "1.9.2" ? [">= 2", "< 2.0.4"] : "~> 2.0" - gem.add_dependency "rinku", "~> 1.7" - gem.add_dependency "escape_utils", "~> 0.3" + gem.add_dependency "nokogiri", RUBY_VERSION < "1.9.2" ? [">= 1.4", "< 1.6"] : "~> 1.4" gem.add_development_dependency "activesupport", RUBY_VERSION < "1.9.3" ? [">= 2", "< 4"] : ">= 2" - gem.add_development_dependency "github-linguist", "~> 2.6.2" + + gem.post_install_message = < e + missing = HTML::Pipeline::Filter::MissingDependencyException + raise missing, missing::MESSAGE % "rinku", e.backtrace +end module HTML class Pipeline diff --git a/lib/html/pipeline/email_reply_filter.rb b/lib/html/pipeline/email_reply_filter.rb index a63a09a2..6f64f658 100644 --- a/lib/html/pipeline/email_reply_filter.rb +++ b/lib/html/pipeline/email_reply_filter.rb @@ -1,3 +1,10 @@ +begin + require "escape_utils" +rescue LoadError => e + missing = HTML::Pipeline::Filter::MissingDependencyException + raise missing, missing::MESSAGE % "escape_utils", e.backtrace +end + module HTML class Pipeline # HTML Filter that converts email reply text into an HTML DocumentFragment. @@ -53,4 +60,4 @@ def call end end end -end \ No newline at end of file +end diff --git a/lib/html/pipeline/emoji_filter.rb b/lib/html/pipeline/emoji_filter.rb index 87fb8828..c2336a86 100644 --- a/lib/html/pipeline/emoji_filter.rb +++ b/lib/html/pipeline/emoji_filter.rb @@ -1,4 +1,9 @@ -require 'emoji' +begin + require "gemoji" +rescue LoadError => e + missing = HTML::Pipeline::Filter::MissingDependencyException + raise missing, missing::MESSAGE % "gemoji", e.backtrace +end module HTML class Pipeline @@ -51,4 +56,4 @@ def asset_root end end end -end \ No newline at end of file +end diff --git a/lib/html/pipeline/filter.rb b/lib/html/pipeline/filter.rb index 0fe5a831..6edcb0df 100644 --- a/lib/html/pipeline/filter.rb +++ b/lib/html/pipeline/filter.rb @@ -27,6 +27,23 @@ class Pipeline # Each filter may define additional options and output values. See the class # docs for more info. class Filter + # Public: Custom Exception raised when a Filter dependency is not installed. + # + # Examples + # + # begin + # require "rinku" + # rescue LoadError => e + # missing = HTML::Pipeline::Filter::MissingDependencyException + # raise missing, missing::MESSAGE % "rinku", e.backtrace + # end + class MissingDependencyException < StandardError + # Public: Format String for MissingDependencyException message. + MESSAGE = "Missing html-pipeline dependency: " + + "Please add `%s` to your Gemfile; " + + "see html-pipeline Gemfile for version." + end + class InvalidDocumentException < StandardError; end def initialize(doc, context = nil, result = nil) diff --git a/lib/html/pipeline/markdown_filter.rb b/lib/html/pipeline/markdown_filter.rb index 6c25494e..db61a7f0 100644 --- a/lib/html/pipeline/markdown_filter.rb +++ b/lib/html/pipeline/markdown_filter.rb @@ -1,4 +1,9 @@ -require 'github/markdown' +begin + require "github/markdown" +rescue LoadError => e + missing = HTML::Pipeline::Filter::MissingDependencyException + raise missing, missing::MESSAGE % "github-markdown", e.backtrace +end module HTML class Pipeline @@ -26,4 +31,4 @@ def call end end end -end \ No newline at end of file +end diff --git a/lib/html/pipeline/plain_text_input_filter.rb b/lib/html/pipeline/plain_text_input_filter.rb index 3e776a75..db0876ef 100644 --- a/lib/html/pipeline/plain_text_input_filter.rb +++ b/lib/html/pipeline/plain_text_input_filter.rb @@ -1,3 +1,10 @@ +begin + require "escape_utils" +rescue LoadError => e + missing = HTML::Pipeline::Filter::MissingDependencyException + raise missing, missing::MESSAGE % "escape_utils", e.backtrace +end + module HTML class Pipeline # Simple filter for plain text input. HTML escapes the text input and wraps it @@ -8,4 +15,4 @@ def call end end end -end \ No newline at end of file +end diff --git a/lib/html/pipeline/sanitization_filter.rb b/lib/html/pipeline/sanitization_filter.rb index b5d65cf7..6ee6dd59 100644 --- a/lib/html/pipeline/sanitization_filter.rb +++ b/lib/html/pipeline/sanitization_filter.rb @@ -1,4 +1,9 @@ -require 'sanitize' +begin + require "sanitize" +rescue LoadError => e + missing = HTML::Pipeline::Filter::MissingDependencyException + raise missing, missing::MESSAGE % "sanitize", e.backtrace +end module HTML class Pipeline diff --git a/lib/html/pipeline/syntax_highlight_filter.rb b/lib/html/pipeline/syntax_highlight_filter.rb index 6660faff..98e1ccd2 100644 --- a/lib/html/pipeline/syntax_highlight_filter.rb +++ b/lib/html/pipeline/syntax_highlight_filter.rb @@ -1,7 +1,8 @@ begin - require 'linguist' -rescue LoadError - raise LoadError, "You need to install 'github-linguist' before using the SyntaxHighlightFilter. See README.md for details" + require "linguist" +rescue LoadError => e + missing = HTML::Pipeline::Filter::MissingDependencyException + raise missing, missing::MESSAGE % "github-linguist", e.backtrace end module HTML @@ -30,4 +31,4 @@ def highlight_with_timeout_handling(lexer, text) end end end -end \ No newline at end of file +end diff --git a/lib/html/pipeline/textile_filter.rb b/lib/html/pipeline/textile_filter.rb index 31619087..b3bcd16b 100644 --- a/lib/html/pipeline/textile_filter.rb +++ b/lib/html/pipeline/textile_filter.rb @@ -1,3 +1,10 @@ +begin + require "redcloth" +rescue LoadError => e + missing = HTML::Pipeline::Filter::MissingDependencyException + raise missing, missing::MESSAGE % "RedCloth", e.backtrace +end + module HTML class Pipeline # HTML Filter that converts Textile text into HTML and converts into a @@ -18,4 +25,4 @@ def call end end end -end \ No newline at end of file +end diff --git a/test/helpers/testing_dependency.rb b/test/helpers/testing_dependency.rb new file mode 100644 index 00000000..234de1e4 --- /dev/null +++ b/test/helpers/testing_dependency.rb @@ -0,0 +1,92 @@ +# Public: Methods useful for testing Filter dependencies. All methods are class +# methods and should be called on the TestingDependency class. +# +# Examples +# +# TestingDependency.temporarily_remove_dependency_by gem_name do +# exception = assert_raise HTML::Pipeline::Filter::MissingDependencyException do +# load TestingDependency.filter_path_from filter_name +# end +# end +class TestingDependency + # Public: Use to safely test a Filter's gem dependency error handling. + # For a certain gem dependency, remove the gem's loaded paths and features. + # Once these are removed, yield to a block which can assert a specific + # exception. Once the block is finished, add back the gem's paths and + # features to the load path and loaded features, so other tests can assert + # Filter functionality. + # + # gem_name - The String of the gem's name. + # block - Required block which asserts gem dependency error handling. + # + # Examples + # + # TestingDependency.temporarily_remove_dependency_by gem_name do + # exception = assert_raise HTML::Pipeline::Filter::MissingDependencyException do + # load TestingDependency.filter_path_from filter_name + # end + # end + # + # Returns nothing. + def self.temporarily_remove_dependency_by(gem_name, &block) + paths = gem_load_paths_from gem_name + features = gem_loaded_features_from gem_name + + $LOAD_PATH.delete_if { |path| paths.include? path } + $LOADED_FEATURES.delete_if { |feature| features.include? feature } + + yield + + $LOAD_PATH.unshift(*paths) + $LOADED_FEATURES.unshift(*features) + end + + # Public: Find a Filter's load path. + # + # gem_name - The String of the gem's name. + # + # Examples + # + # filter_path_from("autolink_filter") + # # => "/Users/simeon/Projects/html-pipeline/test/helpers/../../lib/html/pipeline/autolink_filter.rb" + # + # Returns String of load path. + def self.filter_path_from(filter_name) + File.join(File.dirname(__FILE__), "..", "..", "lib", "html", "pipeline", "#{filter_name}.rb") + end + + private + # Internal: Find a gem's load paths. + # + # gem_name - The String of the gem's name. + # + # Examples + # + # gem_load_paths_from("rinku") + # # => ["/Users/simeon/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/rinku-1.7.3/lib"] + # + # Returns Array of load paths. + def self.gem_load_paths_from(gem_name) + $LOAD_PATH.select{ |path| /#{gem_name}/i =~ path } + end + + # Internal: Find a gem's loaded features. + # + # gem_name - The String of the gem's name. + # + # Examples + # + # gem_loaded_features_from("rinku") + # # => ["/Users/simeon/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/rinku-1.7.3/lib/rinku.bundle", + # "/Users/simeon/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/rinku-1.7.3/lib/rinku.rb"] + # + # Returns Array of loaded features. + def self.gem_loaded_features_from(gem_name) + # gem github-markdown has a feature "github/markdown.rb". + # Replace gem name dashes and underscores with regexp + # range to match all features. + gem_name_regexp = gem_name.split(/[-_]/).join("[\/_-]") + + $LOADED_FEATURES.select{ |feature| /#{gem_name_regexp}/i =~ feature } + end +end diff --git a/test/html/pipeline/autolink_filter_test.rb b/test/html/pipeline/autolink_filter_test.rb index dfda5e56..10c837fb 100644 --- a/test/html/pipeline/autolink_filter_test.rb +++ b/test/html/pipeline/autolink_filter_test.rb @@ -3,6 +3,10 @@ AutolinkFilter = HTML::Pipeline::AutolinkFilter class HTML::Pipeline::AutolinkFilterTest < Test::Unit::TestCase + def test_dependency_management + assert_dependency_management_error "autolink_filter", "rinku" + end + def test_uses_rinku_for_autolinking # just try to parse a complicated piece of HTML # that Rails auto_link cannot handle diff --git a/test/html/pipeline/email_reply_filter_test.rb b/test/html/pipeline/email_reply_filter_test.rb new file mode 100644 index 00000000..f6744e7e --- /dev/null +++ b/test/html/pipeline/email_reply_filter_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class HTML::Pipeline::EmailReplyFilterTest < Test::Unit::TestCase + def test_dependency_management + assert_dependency_management_error "email_reply_filter", "escape_utils" + end +end diff --git a/test/html/pipeline/emoji_filter_test.rb b/test/html/pipeline/emoji_filter_test.rb index 20518484..2683bb98 100644 --- a/test/html/pipeline/emoji_filter_test.rb +++ b/test/html/pipeline/emoji_filter_test.rb @@ -1,12 +1,16 @@ -require 'test_helper' +require "test_helper" class HTML::Pipeline::EmojiFilterTest < Test::Unit::TestCase EmojiFilter = HTML::Pipeline::EmojiFilter - + + def test_dependency_management + assert_dependency_management_error "emoji_filter", "gemoji" + end + def test_emojify - filter = EmojiFilter.new("

:shipit:

", {:asset_root => 'https://foo.com'}) + filter = EmojiFilter.new("

:shipit:

", {:asset_root => "https://foo.com"}) doc = filter.call - assert_match "https://foo.com/emoji/shipit.png", doc.search('img').attr('src').value + assert_match "https://foo.com/emoji/shipit.png", doc.search("img").attr("src").value end def test_required_context_validation @@ -15,4 +19,4 @@ def test_required_context_validation } assert_match /:asset_root/, exception.message end -end \ No newline at end of file +end diff --git a/test/html/pipeline/markdown_filter_test.rb b/test/html/pipeline/markdown_filter_test.rb index a0b2f732..dfc2442e 100644 --- a/test/html/pipeline/markdown_filter_test.rb +++ b/test/html/pipeline/markdown_filter_test.rb @@ -18,6 +18,10 @@ def setup "```" end + def test_dependency_management + assert_dependency_management_error "markdown_filter", "github-markdown" + end + def test_fails_when_given_a_documentfragment body = "

heyo

" doc = HTML::Pipeline.parse(body) @@ -27,26 +31,26 @@ def test_fails_when_given_a_documentfragment def test_gfm_enabled_by_default doc = MarkdownFilter.to_document(@haiku, {}) assert doc.kind_of?(HTML::Pipeline::DocumentFragment) - assert_equal 2, doc.search('br').size + assert_equal 2, doc.search("br").size end def test_disabling_gfm doc = MarkdownFilter.to_document(@haiku, :gfm => false) assert doc.kind_of?(HTML::Pipeline::DocumentFragment) - assert_equal 0, doc.search('br').size + assert_equal 0, doc.search("br").size end def test_fenced_code_blocks doc = MarkdownFilter.to_document(@code) assert doc.kind_of?(HTML::Pipeline::DocumentFragment) - assert_equal 1, doc.search('pre').size + assert_equal 1, doc.search("pre").size end def test_fenced_code_blocks_with_language doc = MarkdownFilter.to_document(@code.sub("```", "``` ruby")) assert doc.kind_of?(HTML::Pipeline::DocumentFragment) - assert_equal 1, doc.search('pre').size - assert_equal 'ruby', doc.search('pre').first['lang'] + assert_equal 1, doc.search("pre").size + assert_equal "ruby", doc.search("pre").first["lang"] end end diff --git a/test/html/pipeline/plain_text_input_filter_test.rb b/test/html/pipeline/plain_text_input_filter_test.rb index 22c419f4..8f2daddb 100644 --- a/test/html/pipeline/plain_text_input_filter_test.rb +++ b/test/html/pipeline/plain_text_input_filter_test.rb @@ -3,6 +3,10 @@ class HTML::Pipeline::PlainTextInputFilterTest < Test::Unit::TestCase PlainTextInputFilter = HTML::Pipeline::PlainTextInputFilter + def test_dependency_management + assert_dependency_management_error "plain_text_input_filter", "escape_utils" + end + def test_fails_when_given_a_documentfragment body = "

heyo

" doc = Nokogiri::HTML::DocumentFragment.parse(body) diff --git a/test/html/pipeline/sanitization_filter_test.rb b/test/html/pipeline/sanitization_filter_test.rb index db9c98df..c271ff83 100644 --- a/test/html/pipeline/sanitization_filter_test.rb +++ b/test/html/pipeline/sanitization_filter_test.rb @@ -3,6 +3,10 @@ class HTML::Pipeline::SanitizationFilterTest < Test::Unit::TestCase SanitizationFilter = HTML::Pipeline::SanitizationFilter + def test_dependency_management + assert_dependency_management_error "sanitization_filter", "sanitize" + end + def test_removing_script_tags orig = %(

) html = SanitizationFilter.call(orig).to_s diff --git a/test/html/pipeline/syntax_highlight_filter_test.rb b/test/html/pipeline/syntax_highlight_filter_test.rb new file mode 100644 index 00000000..426837e3 --- /dev/null +++ b/test/html/pipeline/syntax_highlight_filter_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class HTML::Pipeline::SyntaxHighlightFilterTest < Test::Unit::TestCase + def test_dependency_management + assert_dependency_management_error "syntax_highlight_filter", "github-linguist" + end +end diff --git a/test/html/pipeline/textile_filter_test.rb b/test/html/pipeline/textile_filter_test.rb new file mode 100644 index 00000000..4d0b802c --- /dev/null +++ b/test/html/pipeline/textile_filter_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class HTML::Pipeline::TextileFilterTest < Test::Unit::TestCase + def test_dependency_management + assert_dependency_management_error "textile_filter", "RedCloth" + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index bce1cb33..b999d4ad 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,14 +1,15 @@ -require 'bundler/setup' -require 'html/pipeline' -require 'test/unit' +require "bundler/setup" +require "html/pipeline" +require "test/unit" +require "helpers/testing_dependency" -require 'active_support/core_ext/object/try' +require "active_support/core_ext/object/try" module TestHelpers # Asserts that `needle` is not a member of `haystack`, where # `haystack` is any object that responds to `include?`. def assert_doesnt_include(needle, haystack, message = nil) - error = ' included in ' + error = " included in " message = build_message(message, error, needle.to_s, Array(haystack).map(&:to_s)) assert_block message do @@ -19,7 +20,7 @@ def assert_doesnt_include(needle, haystack, message = nil) # Asserts that `needle` is a member of `haystack`, where # `haystack` is any object that responds to `include?`. def assert_includes(needle, haystack, message = nil) - error = ' not included in ' + error = " not included in " message = build_message(message, error, needle.to_s, Array(haystack).map(&:to_s)) assert_block message do @@ -33,6 +34,20 @@ def assert_equal_html(expected, actual) assert_equal Nokogiri::HTML::DocumentFragment.parse(expected).to_hash, Nokogiri::HTML::DocumentFragment.parse(actual).to_hash end + + # Asserts that when a Filter is loaded without its dependencies installed, + # a HTML::Pipeline::Filter::MissingDependencyException is raised with a + # message describing the problem and a fix. + def assert_dependency_management_error(filter_name, gem_name) + TestingDependency.temporarily_remove_dependency_by gem_name do + exception = assert_raise HTML::Pipeline::Filter::MissingDependencyException do + load TestingDependency.filter_path_from filter_name + end + + assert_equal exception.message, + "Missing html-pipeline dependency: Please add `#{gem_name}` to your Gemfile; see html-pipeline Gemfile for version." + end + end end -Test::Unit::TestCase.send(:include, TestHelpers) \ No newline at end of file +Test::Unit::TestCase.send(:include, TestHelpers) From c25c89098045b3a5e6584b3f234123696d6a0b51 Mon Sep 17 00:00:00 2001 From: "Simeon F. Willbanks" Date: Tue, 27 Aug 2013 19:19:13 -0700 Subject: [PATCH 2/8] Address Pull Request comments: * Copy edit README.md * In gemspec, link README.md dependencies and update post install message * Rename test helper to `assert_dependency` * Remove `TestingDependency` in favor of stubbing `Kernal#require` --- README.md | 2 +- html-pipeline.gemspec | 7 +- test/helpers/testing_dependency.rb | 92 ------------------- test/html/pipeline/autolink_filter_test.rb | 2 +- test/html/pipeline/email_reply_filter_test.rb | 2 +- test/html/pipeline/emoji_filter_test.rb | 2 +- test/html/pipeline/markdown_filter_test.rb | 2 +- .../pipeline/plain_text_input_filter_test.rb | 2 +- .../html/pipeline/sanitization_filter_test.rb | 2 +- .../pipeline/syntax_highlight_filter_test.rb | 2 +- test/html/pipeline/textile_filter_test.rb | 2 +- test/test_helper.rb | 17 ++-- 12 files changed, 22 insertions(+), 112 deletions(-) delete mode 100644 test/helpers/testing_dependency.rb diff --git a/README.md b/README.md index dd651d5c..169cbaa4 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ filter.call Filter gem dependencies are not bundled; you must bundle the filter's gem dependencies. The below list details filters with dependencies. For example, `SyntaxHighlightFilter` uses [github-linguist](https://github.com/github/linguist) -to detect and highlight languages. To use the `SyntaxHighlightFilter`, +to detect and highlight languages. For example, to use the `SyntaxHighlightFilter`, add the following to your Gemfile: ```ruby diff --git a/html-pipeline.gemspec b/html-pipeline.gemspec index bf45e3c6..23df17de 100644 --- a/html-pipeline.gemspec +++ b/html-pipeline.gemspec @@ -20,12 +20,11 @@ Gem::Specification.new do |gem| gem.add_development_dependency "activesupport", RUBY_VERSION < "1.9.3" ? [">= 2", "< 4"] : ">= 2" gem.post_install_message = < "/Users/simeon/Projects/html-pipeline/test/helpers/../../lib/html/pipeline/autolink_filter.rb" - # - # Returns String of load path. - def self.filter_path_from(filter_name) - File.join(File.dirname(__FILE__), "..", "..", "lib", "html", "pipeline", "#{filter_name}.rb") - end - - private - # Internal: Find a gem's load paths. - # - # gem_name - The String of the gem's name. - # - # Examples - # - # gem_load_paths_from("rinku") - # # => ["/Users/simeon/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/rinku-1.7.3/lib"] - # - # Returns Array of load paths. - def self.gem_load_paths_from(gem_name) - $LOAD_PATH.select{ |path| /#{gem_name}/i =~ path } - end - - # Internal: Find a gem's loaded features. - # - # gem_name - The String of the gem's name. - # - # Examples - # - # gem_loaded_features_from("rinku") - # # => ["/Users/simeon/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/rinku-1.7.3/lib/rinku.bundle", - # "/Users/simeon/.rbenv/versions/1.9.3-p429/lib/ruby/gems/1.9.1/gems/rinku-1.7.3/lib/rinku.rb"] - # - # Returns Array of loaded features. - def self.gem_loaded_features_from(gem_name) - # gem github-markdown has a feature "github/markdown.rb". - # Replace gem name dashes and underscores with regexp - # range to match all features. - gem_name_regexp = gem_name.split(/[-_]/).join("[\/_-]") - - $LOADED_FEATURES.select{ |feature| /#{gem_name_regexp}/i =~ feature } - end -end diff --git a/test/html/pipeline/autolink_filter_test.rb b/test/html/pipeline/autolink_filter_test.rb index 10c837fb..50f301bc 100644 --- a/test/html/pipeline/autolink_filter_test.rb +++ b/test/html/pipeline/autolink_filter_test.rb @@ -4,7 +4,7 @@ class HTML::Pipeline::AutolinkFilterTest < Test::Unit::TestCase def test_dependency_management - assert_dependency_management_error "autolink_filter", "rinku" + assert_dependency "autolink_filter", "rinku" end def test_uses_rinku_for_autolinking diff --git a/test/html/pipeline/email_reply_filter_test.rb b/test/html/pipeline/email_reply_filter_test.rb index f6744e7e..13a519fc 100644 --- a/test/html/pipeline/email_reply_filter_test.rb +++ b/test/html/pipeline/email_reply_filter_test.rb @@ -2,6 +2,6 @@ class HTML::Pipeline::EmailReplyFilterTest < Test::Unit::TestCase def test_dependency_management - assert_dependency_management_error "email_reply_filter", "escape_utils" + assert_dependency "email_reply_filter", "escape_utils" end end diff --git a/test/html/pipeline/emoji_filter_test.rb b/test/html/pipeline/emoji_filter_test.rb index 2683bb98..ad3bbc4e 100644 --- a/test/html/pipeline/emoji_filter_test.rb +++ b/test/html/pipeline/emoji_filter_test.rb @@ -4,7 +4,7 @@ class HTML::Pipeline::EmojiFilterTest < Test::Unit::TestCase EmojiFilter = HTML::Pipeline::EmojiFilter def test_dependency_management - assert_dependency_management_error "emoji_filter", "gemoji" + assert_dependency "emoji_filter", "gemoji" end def test_emojify diff --git a/test/html/pipeline/markdown_filter_test.rb b/test/html/pipeline/markdown_filter_test.rb index dfc2442e..7161ea43 100644 --- a/test/html/pipeline/markdown_filter_test.rb +++ b/test/html/pipeline/markdown_filter_test.rb @@ -19,7 +19,7 @@ def setup end def test_dependency_management - assert_dependency_management_error "markdown_filter", "github-markdown" + assert_dependency "markdown_filter", "github-markdown" end def test_fails_when_given_a_documentfragment diff --git a/test/html/pipeline/plain_text_input_filter_test.rb b/test/html/pipeline/plain_text_input_filter_test.rb index 8f2daddb..a7f40903 100644 --- a/test/html/pipeline/plain_text_input_filter_test.rb +++ b/test/html/pipeline/plain_text_input_filter_test.rb @@ -4,7 +4,7 @@ class HTML::Pipeline::PlainTextInputFilterTest < Test::Unit::TestCase PlainTextInputFilter = HTML::Pipeline::PlainTextInputFilter def test_dependency_management - assert_dependency_management_error "plain_text_input_filter", "escape_utils" + assert_dependency "plain_text_input_filter", "escape_utils" end def test_fails_when_given_a_documentfragment diff --git a/test/html/pipeline/sanitization_filter_test.rb b/test/html/pipeline/sanitization_filter_test.rb index c271ff83..498e9c02 100644 --- a/test/html/pipeline/sanitization_filter_test.rb +++ b/test/html/pipeline/sanitization_filter_test.rb @@ -4,7 +4,7 @@ class HTML::Pipeline::SanitizationFilterTest < Test::Unit::TestCase SanitizationFilter = HTML::Pipeline::SanitizationFilter def test_dependency_management - assert_dependency_management_error "sanitization_filter", "sanitize" + assert_dependency "sanitization_filter", "sanitize" end def test_removing_script_tags diff --git a/test/html/pipeline/syntax_highlight_filter_test.rb b/test/html/pipeline/syntax_highlight_filter_test.rb index 426837e3..6c344789 100644 --- a/test/html/pipeline/syntax_highlight_filter_test.rb +++ b/test/html/pipeline/syntax_highlight_filter_test.rb @@ -2,6 +2,6 @@ class HTML::Pipeline::SyntaxHighlightFilterTest < Test::Unit::TestCase def test_dependency_management - assert_dependency_management_error "syntax_highlight_filter", "github-linguist" + assert_dependency "syntax_highlight_filter", "github-linguist" end end diff --git a/test/html/pipeline/textile_filter_test.rb b/test/html/pipeline/textile_filter_test.rb index 4d0b802c..4bb511e2 100644 --- a/test/html/pipeline/textile_filter_test.rb +++ b/test/html/pipeline/textile_filter_test.rb @@ -2,6 +2,6 @@ class HTML::Pipeline::TextileFilterTest < Test::Unit::TestCase def test_dependency_management - assert_dependency_management_error "textile_filter", "RedCloth" + assert_dependency "textile_filter", "RedCloth" end end diff --git a/test/test_helper.rb b/test/test_helper.rb index b999d4ad..5f63b798 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,7 +1,6 @@ require "bundler/setup" require "html/pipeline" require "test/unit" -require "helpers/testing_dependency" require "active_support/core_ext/object/try" @@ -38,15 +37,19 @@ def assert_equal_html(expected, actual) # Asserts that when a Filter is loaded without its dependencies installed, # a HTML::Pipeline::Filter::MissingDependencyException is raised with a # message describing the problem and a fix. - def assert_dependency_management_error(filter_name, gem_name) - TestingDependency.temporarily_remove_dependency_by gem_name do - exception = assert_raise HTML::Pipeline::Filter::MissingDependencyException do - load TestingDependency.filter_path_from filter_name + def assert_dependency(filter_name, gem_name) + Kernel.module_eval do + def require(name) + raise LoadError end + end - assert_equal exception.message, - "Missing html-pipeline dependency: Please add `#{gem_name}` to your Gemfile; see html-pipeline Gemfile for version." + exception = assert_raise HTML::Pipeline::Filter::MissingDependencyException do + load File.join(File.dirname(__FILE__), "..", "lib", "html", "pipeline", "#{filter_name}.rb") end + + assert_equal exception.message, + "Missing html-pipeline dependency: Please add `#{gem_name}` to your Gemfile; see html-pipeline Gemfile for version." end end From f0983dca6d9afde4d6ec172bffdb406d55f0bb5b Mon Sep 17 00:00:00 2001 From: "Simeon F. Willbanks" Date: Tue, 27 Aug 2013 21:08:19 -0700 Subject: [PATCH 3/8] Textile Filter does require RedCloth --- bin/html-pipeline | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/html-pipeline b/bin/html-pipeline index eb4064ca..f1d8ed45 100755 --- a/bin/html-pipeline +++ b/bin/html-pipeline @@ -54,8 +54,6 @@ else case name when "Text" raise NameError # Text filter doesn't work, no call method - when "Textile" - require "RedCloth" # Textile filter doesn't require RedCloth end HTML::Pipeline.const_get("#{name}Filter") @@ -77,4 +75,4 @@ context = { :gfm => true } -puts HTML::Pipeline.new(filters, context).call(ARGF.read)[:output] \ No newline at end of file +puts HTML::Pipeline.new(filters, context).call(ARGF.read)[:output] From f9c6d0607ce50a4ad3b0afb4005cba0680a3356d Mon Sep 17 00:00:00 2001 From: "Simeon F. Willbanks" Date: Tue, 27 Aug 2013 21:19:04 -0700 Subject: [PATCH 4/8] Move ActiveSupport::XmlMini_Nokogiri to test helper, since its mixed in #to_hash is only used by #assert_equal_html --- lib/html/pipeline.rb | 1 - test/test_helper.rb | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/html/pipeline.rb b/lib/html/pipeline.rb index 2e526d93..7677af9a 100644 --- a/lib/html/pipeline.rb +++ b/lib/html/pipeline.rb @@ -1,5 +1,4 @@ require "nokogiri" -require "active_support/xml_mini/nokogiri" # convert Documents to hashes module HTML # GitHub HTML processing filters and utilities. This module includes a small diff --git a/test/test_helper.rb b/test/test_helper.rb index 5f63b798..783e8e93 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,6 +3,7 @@ require "test/unit" require "active_support/core_ext/object/try" +require "active_support/xml_mini/nokogiri" # convert Documents to hashes module TestHelpers # Asserts that `needle` is not a member of `haystack`, where From 0471de42da3f375af4d7d05a13e35e947e984dd2 Mon Sep 17 00:00:00 2001 From: "Simeon F. Willbanks" Date: Tue, 22 Oct 2013 19:36:08 -0700 Subject: [PATCH 5/8] Relative link to Gemfile --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f8a72bba..20562b75 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ gem 'github-linguist' * `SyntaxHighlightFilter` - `github-linguist` * `TextileFilter` - `RedCloth` -_Note:_ See [Gemfile](https://github.com/jch/html-pipeline/blob/master/Gemfile) `:test` block for version requirements. +_Note:_ See [Gemfile](/Gemfile) `:test` block for version requirements. ## 3rd Party Extensions From 154ef94444a648f5d74d5774a5786a7dafa1aae0 Mon Sep 17 00:00:00 2001 From: "Simeon F. Willbanks" Date: Tue, 22 Oct 2013 20:03:47 -0700 Subject: [PATCH 6/8] Don't test dependency management since its testing require and is brittle --- test/html/pipeline/autolink_filter_test.rb | 4 --- test/html/pipeline/email_reply_filter_test.rb | 7 ---- test/html/pipeline/emoji_filter_test.rb | 14 +++----- test/html/pipeline/markdown_filter_test.rb | 14 +++----- .../pipeline/plain_text_input_filter_test.rb | 4 --- .../html/pipeline/sanitization_filter_test.rb | 4 --- .../pipeline/syntax_highlight_filter_test.rb | 4 --- test/html/pipeline/textile_filter_test.rb | 7 ---- test/test_helper.rb | 32 ++++--------------- 9 files changed, 17 insertions(+), 73 deletions(-) delete mode 100644 test/html/pipeline/email_reply_filter_test.rb delete mode 100644 test/html/pipeline/textile_filter_test.rb diff --git a/test/html/pipeline/autolink_filter_test.rb b/test/html/pipeline/autolink_filter_test.rb index 5ff1e5b4..f8fe0c9d 100644 --- a/test/html/pipeline/autolink_filter_test.rb +++ b/test/html/pipeline/autolink_filter_test.rb @@ -3,10 +3,6 @@ AutolinkFilter = HTML::Pipeline::AutolinkFilter class HTML::Pipeline::AutolinkFilterTest < Test::Unit::TestCase - def test_dependency_management - assert_dependency "autolink_filter", "rinku" - end - def test_uses_rinku_for_autolinking # just try to parse a complicated piece of HTML # that Rails auto_link cannot handle diff --git a/test/html/pipeline/email_reply_filter_test.rb b/test/html/pipeline/email_reply_filter_test.rb deleted file mode 100644 index 13a519fc..00000000 --- a/test/html/pipeline/email_reply_filter_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require "test_helper" - -class HTML::Pipeline::EmailReplyFilterTest < Test::Unit::TestCase - def test_dependency_management - assert_dependency "email_reply_filter", "escape_utils" - end -end diff --git a/test/html/pipeline/emoji_filter_test.rb b/test/html/pipeline/emoji_filter_test.rb index ad3bbc4e..20518484 100644 --- a/test/html/pipeline/emoji_filter_test.rb +++ b/test/html/pipeline/emoji_filter_test.rb @@ -1,16 +1,12 @@ -require "test_helper" +require 'test_helper' class HTML::Pipeline::EmojiFilterTest < Test::Unit::TestCase EmojiFilter = HTML::Pipeline::EmojiFilter - - def test_dependency_management - assert_dependency "emoji_filter", "gemoji" - end - + def test_emojify - filter = EmojiFilter.new("

:shipit:

", {:asset_root => "https://foo.com"}) + filter = EmojiFilter.new("

:shipit:

", {:asset_root => 'https://foo.com'}) doc = filter.call - assert_match "https://foo.com/emoji/shipit.png", doc.search("img").attr("src").value + assert_match "https://foo.com/emoji/shipit.png", doc.search('img').attr('src').value end def test_required_context_validation @@ -19,4 +15,4 @@ def test_required_context_validation } assert_match /:asset_root/, exception.message end -end +end \ No newline at end of file diff --git a/test/html/pipeline/markdown_filter_test.rb b/test/html/pipeline/markdown_filter_test.rb index 7161ea43..a0b2f732 100644 --- a/test/html/pipeline/markdown_filter_test.rb +++ b/test/html/pipeline/markdown_filter_test.rb @@ -18,10 +18,6 @@ def setup "```" end - def test_dependency_management - assert_dependency "markdown_filter", "github-markdown" - end - def test_fails_when_given_a_documentfragment body = "

heyo

" doc = HTML::Pipeline.parse(body) @@ -31,26 +27,26 @@ def test_fails_when_given_a_documentfragment def test_gfm_enabled_by_default doc = MarkdownFilter.to_document(@haiku, {}) assert doc.kind_of?(HTML::Pipeline::DocumentFragment) - assert_equal 2, doc.search("br").size + assert_equal 2, doc.search('br').size end def test_disabling_gfm doc = MarkdownFilter.to_document(@haiku, :gfm => false) assert doc.kind_of?(HTML::Pipeline::DocumentFragment) - assert_equal 0, doc.search("br").size + assert_equal 0, doc.search('br').size end def test_fenced_code_blocks doc = MarkdownFilter.to_document(@code) assert doc.kind_of?(HTML::Pipeline::DocumentFragment) - assert_equal 1, doc.search("pre").size + assert_equal 1, doc.search('pre').size end def test_fenced_code_blocks_with_language doc = MarkdownFilter.to_document(@code.sub("```", "``` ruby")) assert doc.kind_of?(HTML::Pipeline::DocumentFragment) - assert_equal 1, doc.search("pre").size - assert_equal "ruby", doc.search("pre").first["lang"] + assert_equal 1, doc.search('pre').size + assert_equal 'ruby', doc.search('pre').first['lang'] end end diff --git a/test/html/pipeline/plain_text_input_filter_test.rb b/test/html/pipeline/plain_text_input_filter_test.rb index a7f40903..22c419f4 100644 --- a/test/html/pipeline/plain_text_input_filter_test.rb +++ b/test/html/pipeline/plain_text_input_filter_test.rb @@ -3,10 +3,6 @@ class HTML::Pipeline::PlainTextInputFilterTest < Test::Unit::TestCase PlainTextInputFilter = HTML::Pipeline::PlainTextInputFilter - def test_dependency_management - assert_dependency "plain_text_input_filter", "escape_utils" - end - def test_fails_when_given_a_documentfragment body = "

heyo

" doc = Nokogiri::HTML::DocumentFragment.parse(body) diff --git a/test/html/pipeline/sanitization_filter_test.rb b/test/html/pipeline/sanitization_filter_test.rb index 498e9c02..db9c98df 100644 --- a/test/html/pipeline/sanitization_filter_test.rb +++ b/test/html/pipeline/sanitization_filter_test.rb @@ -3,10 +3,6 @@ class HTML::Pipeline::SanitizationFilterTest < Test::Unit::TestCase SanitizationFilter = HTML::Pipeline::SanitizationFilter - def test_dependency_management - assert_dependency "sanitization_filter", "sanitize" - end - def test_removing_script_tags orig = %(

) html = SanitizationFilter.call(orig).to_s diff --git a/test/html/pipeline/syntax_highlight_filter_test.rb b/test/html/pipeline/syntax_highlight_filter_test.rb index bd7b9be5..2dea999f 100644 --- a/test/html/pipeline/syntax_highlight_filter_test.rb +++ b/test/html/pipeline/syntax_highlight_filter_test.rb @@ -3,10 +3,6 @@ SyntaxHighlightFilter = HTML::Pipeline::SyntaxHighlightFilter class HTML::Pipeline::SyntaxHighlightFilterTest < Test::Unit::TestCase - def test_dependency_management - assert_dependency "syntax_highlight_filter", "github-linguist" - end - def test_highlight_default filter = SyntaxHighlightFilter.new \ "
hello
", :highlight => "coffeescript" diff --git a/test/html/pipeline/textile_filter_test.rb b/test/html/pipeline/textile_filter_test.rb deleted file mode 100644 index 4bb511e2..00000000 --- a/test/html/pipeline/textile_filter_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require "test_helper" - -class HTML::Pipeline::TextileFilterTest < Test::Unit::TestCase - def test_dependency_management - assert_dependency "textile_filter", "RedCloth" - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb index fc4b57b6..65e38906 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,15 +1,15 @@ -require "bundler/setup" -require "html/pipeline" -require "test/unit" +require 'bundler/setup' +require 'html/pipeline' +require 'test/unit' -require "active_support/core_ext/string" -require "active_support/core_ext/object/try" +require 'active_support/core_ext/string' +require 'active_support/core_ext/object/try' module TestHelpers # Asserts that `needle` is not a member of `haystack`, where # `haystack` is any object that responds to `include?`. def assert_doesnt_include(needle, haystack, message = nil) - error = " included in " + error = ' included in ' message = build_message(message, error, needle.to_s, Array(haystack).map(&:to_s)) assert_block message do @@ -20,7 +20,7 @@ def assert_doesnt_include(needle, haystack, message = nil) # Asserts that `needle` is a member of `haystack`, where # `haystack` is any object that responds to `include?`. def assert_includes(needle, haystack, message = nil) - error = " not included in " + error = ' not included in ' message = build_message(message, error, needle.to_s, Array(haystack).map(&:to_s)) assert_block message do @@ -34,24 +34,6 @@ def assert_equal_html(expected, actual) assert_equal Nokogiri::HTML::DocumentFragment.parse(expected).to_hash, Nokogiri::HTML::DocumentFragment.parse(actual).to_hash end - - # Asserts that when a Filter is loaded without its dependencies installed, - # a HTML::Pipeline::Filter::MissingDependencyException is raised with a - # message describing the problem and a fix. - def assert_dependency(filter_name, gem_name) - Kernel.module_eval do - def require(name) - raise LoadError - end - end - - exception = assert_raise HTML::Pipeline::Filter::MissingDependencyException do - load File.join(File.dirname(__FILE__), "..", "lib", "html", "pipeline", "#{filter_name}.rb") - end - - assert_equal exception.message, - "Missing html-pipeline dependency: Please add `#{gem_name}` to your Gemfile; see html-pipeline Gemfile for version." - end end Test::Unit::TestCase.send(:include, TestHelpers) From 6ff25ad54876996d052241e577e3aaf651d4265c Mon Sep 17 00:00:00 2001 From: "Simeon F. Willbanks" Date: Tue, 22 Oct 2013 20:04:23 -0700 Subject: [PATCH 7/8] No need for MissingDependencyException --- lib/html/pipeline/filter.rb | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/lib/html/pipeline/filter.rb b/lib/html/pipeline/filter.rb index 6edcb0df..0fe5a831 100644 --- a/lib/html/pipeline/filter.rb +++ b/lib/html/pipeline/filter.rb @@ -27,23 +27,6 @@ class Pipeline # Each filter may define additional options and output values. See the class # docs for more info. class Filter - # Public: Custom Exception raised when a Filter dependency is not installed. - # - # Examples - # - # begin - # require "rinku" - # rescue LoadError => e - # missing = HTML::Pipeline::Filter::MissingDependencyException - # raise missing, missing::MESSAGE % "rinku", e.backtrace - # end - class MissingDependencyException < StandardError - # Public: Format String for MissingDependencyException message. - MESSAGE = "Missing html-pipeline dependency: " + - "Please add `%s` to your Gemfile; " + - "see html-pipeline Gemfile for version." - end - class InvalidDocumentException < StandardError; end def initialize(doc, context = nil, result = nil) From a0acb6956fdede396b814ce695eef78af0d56b96 Mon Sep 17 00:00:00 2001 From: "Simeon F. Willbanks" Date: Tue, 22 Oct 2013 20:11:41 -0700 Subject: [PATCH 8/8] If a dependency is missing, exit with a 1 status and write help message to STDERR. --- lib/html/pipeline/autolink_filter.rb | 5 ++--- lib/html/pipeline/email_reply_filter.rb | 5 ++--- lib/html/pipeline/emoji_filter.rb | 5 ++--- lib/html/pipeline/markdown_filter.rb | 5 ++--- lib/html/pipeline/plain_text_input_filter.rb | 5 ++--- lib/html/pipeline/sanitization_filter.rb | 5 ++--- lib/html/pipeline/syntax_highlight_filter.rb | 5 ++--- lib/html/pipeline/textile_filter.rb | 5 ++--- 8 files changed, 16 insertions(+), 24 deletions(-) diff --git a/lib/html/pipeline/autolink_filter.rb b/lib/html/pipeline/autolink_filter.rb index b6428585..4a2f6f73 100644 --- a/lib/html/pipeline/autolink_filter.rb +++ b/lib/html/pipeline/autolink_filter.rb @@ -1,8 +1,7 @@ begin require "rinku" -rescue LoadError => e - missing = HTML::Pipeline::Filter::MissingDependencyException - raise missing, missing::MESSAGE % "rinku", e.backtrace +rescue LoadError => _ + abort "Missing dependency 'rinku' for AutolinkFilter. See README.md for details." end module HTML diff --git a/lib/html/pipeline/email_reply_filter.rb b/lib/html/pipeline/email_reply_filter.rb index 6f64f658..cb8261a8 100644 --- a/lib/html/pipeline/email_reply_filter.rb +++ b/lib/html/pipeline/email_reply_filter.rb @@ -1,8 +1,7 @@ begin require "escape_utils" -rescue LoadError => e - missing = HTML::Pipeline::Filter::MissingDependencyException - raise missing, missing::MESSAGE % "escape_utils", e.backtrace +rescue LoadError => _ + abort "Missing dependency 'escape_utils' for EmailReplyFilter. See README.md for details." end module HTML diff --git a/lib/html/pipeline/emoji_filter.rb b/lib/html/pipeline/emoji_filter.rb index c2336a86..b061cf5d 100644 --- a/lib/html/pipeline/emoji_filter.rb +++ b/lib/html/pipeline/emoji_filter.rb @@ -1,8 +1,7 @@ begin require "gemoji" -rescue LoadError => e - missing = HTML::Pipeline::Filter::MissingDependencyException - raise missing, missing::MESSAGE % "gemoji", e.backtrace +rescue LoadError => _ + abort "Missing dependency 'gemoji' for EmojiFilter. See README.md for details." end module HTML diff --git a/lib/html/pipeline/markdown_filter.rb b/lib/html/pipeline/markdown_filter.rb index db61a7f0..d08e5412 100644 --- a/lib/html/pipeline/markdown_filter.rb +++ b/lib/html/pipeline/markdown_filter.rb @@ -1,8 +1,7 @@ begin require "github/markdown" -rescue LoadError => e - missing = HTML::Pipeline::Filter::MissingDependencyException - raise missing, missing::MESSAGE % "github-markdown", e.backtrace +rescue LoadError => _ + abort "Missing dependency 'github-markdown' for MarkdownFilter. See README.md for details." end module HTML diff --git a/lib/html/pipeline/plain_text_input_filter.rb b/lib/html/pipeline/plain_text_input_filter.rb index db0876ef..c6e468d7 100644 --- a/lib/html/pipeline/plain_text_input_filter.rb +++ b/lib/html/pipeline/plain_text_input_filter.rb @@ -1,8 +1,7 @@ begin require "escape_utils" -rescue LoadError => e - missing = HTML::Pipeline::Filter::MissingDependencyException - raise missing, missing::MESSAGE % "escape_utils", e.backtrace +rescue LoadError => _ + abort "Missing dependency 'escape_utils' for PlainTextInputFilter. See README.md for details." end module HTML diff --git a/lib/html/pipeline/sanitization_filter.rb b/lib/html/pipeline/sanitization_filter.rb index 6ee6dd59..33877bc6 100644 --- a/lib/html/pipeline/sanitization_filter.rb +++ b/lib/html/pipeline/sanitization_filter.rb @@ -1,8 +1,7 @@ begin require "sanitize" -rescue LoadError => e - missing = HTML::Pipeline::Filter::MissingDependencyException - raise missing, missing::MESSAGE % "sanitize", e.backtrace +rescue LoadError => _ + abort "Missing dependency 'sanitize' for SanitizationFilter. See README.md for details." end module HTML diff --git a/lib/html/pipeline/syntax_highlight_filter.rb b/lib/html/pipeline/syntax_highlight_filter.rb index b136f17e..ccdd31e0 100644 --- a/lib/html/pipeline/syntax_highlight_filter.rb +++ b/lib/html/pipeline/syntax_highlight_filter.rb @@ -1,8 +1,7 @@ begin require "linguist" -rescue LoadError => e - missing = HTML::Pipeline::Filter::MissingDependencyException - raise missing, missing::MESSAGE % "github-linguist", e.backtrace +rescue LoadError => _ + abort "Missing dependency 'github-linguist' for SyntaxHighlightFilter. See README.md for details." end module HTML diff --git a/lib/html/pipeline/textile_filter.rb b/lib/html/pipeline/textile_filter.rb index b3bcd16b..d08bce33 100644 --- a/lib/html/pipeline/textile_filter.rb +++ b/lib/html/pipeline/textile_filter.rb @@ -1,8 +1,7 @@ begin require "redcloth" -rescue LoadError => e - missing = HTML::Pipeline::Filter::MissingDependencyException - raise missing, missing::MESSAGE % "RedCloth", e.backtrace +rescue LoadError => _ + abort "Missing dependency 'RedCloth' for TextileFilter. See README.md for details." end module HTML