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 7b15b9a0..20562b75 100644 --- a/README.md +++ b/README.md @@ -98,6 +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 +## 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. For example, 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](/Gemfile) `:test` block for version requirements. + ## 3rd Party Extensions If you have an idea for a filter, propose it as @@ -107,19 +130,6 @@ built as an external gem. * [html-pipeline-asciidoc_filter](https://github.com/asciidoctor/html-pipeline-asciidoc_filter) - asciidoc support - -## Syntax highlighting - -`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: - -```ruby -gem 'github-linguist' -``` - ## Examples We define different pipelines for different parts of our app. Here are a few 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] diff --git a/html-pipeline.gemspec b/html-pipeline.gemspec index 154d209c..9737aa6f 100644 --- a/html-pipeline.gemspec +++ b/html-pipeline.gemspec @@ -15,13 +15,15 @@ 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 "activesupport", RUBY_VERSION < "1.9.3" ? [">= 2", "< 4"] : ">= 2" + gem.add_dependency "nokogiri", RUBY_VERSION < "1.9.2" ? [">= 1.4", "< 1.6"] : "~> 1.4" + gem.add_dependency "activesupport", RUBY_VERSION < "1.9.3" ? [">= 2", "< 4"] : ">= 2" - gem.add_development_dependency "github-linguist", "~> 2.6.2" + gem.post_install_message = < _ + abort "Missing dependency 'rinku' for AutolinkFilter. See README.md for details." +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..cb8261a8 100644 --- a/lib/html/pipeline/email_reply_filter.rb +++ b/lib/html/pipeline/email_reply_filter.rb @@ -1,3 +1,9 @@ +begin + require "escape_utils" +rescue LoadError => _ + abort "Missing dependency 'escape_utils' for EmailReplyFilter. See README.md for details." +end + module HTML class Pipeline # HTML Filter that converts email reply text into an HTML DocumentFragment. @@ -53,4 +59,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..b061cf5d 100644 --- a/lib/html/pipeline/emoji_filter.rb +++ b/lib/html/pipeline/emoji_filter.rb @@ -1,4 +1,8 @@ -require 'emoji' +begin + require "gemoji" +rescue LoadError => _ + abort "Missing dependency 'gemoji' for EmojiFilter. See README.md for details." +end module HTML class Pipeline @@ -51,4 +55,4 @@ def asset_root end end end -end \ No newline at end of file +end diff --git a/lib/html/pipeline/markdown_filter.rb b/lib/html/pipeline/markdown_filter.rb index 6c25494e..d08e5412 100644 --- a/lib/html/pipeline/markdown_filter.rb +++ b/lib/html/pipeline/markdown_filter.rb @@ -1,4 +1,8 @@ -require 'github/markdown' +begin + require "github/markdown" +rescue LoadError => _ + abort "Missing dependency 'github-markdown' for MarkdownFilter. See README.md for details." +end module HTML class Pipeline @@ -26,4 +30,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..c6e468d7 100644 --- a/lib/html/pipeline/plain_text_input_filter.rb +++ b/lib/html/pipeline/plain_text_input_filter.rb @@ -1,3 +1,9 @@ +begin + require "escape_utils" +rescue LoadError => _ + abort "Missing dependency 'escape_utils' for PlainTextInputFilter. See README.md for details." +end + module HTML class Pipeline # Simple filter for plain text input. HTML escapes the text input and wraps it @@ -8,4 +14,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..33877bc6 100644 --- a/lib/html/pipeline/sanitization_filter.rb +++ b/lib/html/pipeline/sanitization_filter.rb @@ -1,4 +1,8 @@ -require 'sanitize' +begin + require "sanitize" +rescue LoadError => _ + abort "Missing dependency 'sanitize' for SanitizationFilter. See README.md for details." +end module HTML class Pipeline diff --git a/lib/html/pipeline/syntax_highlight_filter.rb b/lib/html/pipeline/syntax_highlight_filter.rb index c3c4e6ea..ccdd31e0 100644 --- a/lib/html/pipeline/syntax_highlight_filter.rb +++ b/lib/html/pipeline/syntax_highlight_filter.rb @@ -1,7 +1,7 @@ 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 => _ + 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 31619087..d08bce33 100644 --- a/lib/html/pipeline/textile_filter.rb +++ b/lib/html/pipeline/textile_filter.rb @@ -1,3 +1,9 @@ +begin + require "redcloth" +rescue LoadError => _ + abort "Missing dependency 'RedCloth' for TextileFilter. See README.md for details." +end + module HTML class Pipeline # HTML Filter that converts Textile text into HTML and converts into a @@ -18,4 +24,4 @@ def call end end end -end \ No newline at end of file +end