Skip to content

Commit d3fc6d9

Browse files
author
Simeon F. Willbanks
committed
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
1 parent a731d82 commit d3fc6d9

23 files changed

+282
-46
lines changed

Gemfile

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

33
# Specify your gem's dependencies in html-pipeline.gemspec
44
gemspec
55

66
group :development do
7-
gem 'bundler'
8-
gem 'rake'
7+
gem "bundler"
8+
gem "rake"
9+
end
10+
11+
group :test do
12+
gem "rinku", "~> 1.7", :require => false
13+
gem "gemoji", "~> 1.0", :require => false
14+
gem "RedCloth", "~> 4.2.9", :require => false
15+
gem "escape_utils", "~> 0.3", :require => false
16+
gem "github-linguist", "~> 2.6.2", :require => false
17+
gem "github-markdown", "~> 0.5", :require => false
18+
19+
if RUBY_VERSION < "1.9.2"
20+
gem "sanitize", ">= 2", "< 2.0.4", :require => false
21+
else
22+
gem "sanitize", "~> 2.0", :require => false
23+
end
924
end

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,29 @@ filter.call
9898
* `TextileFilter` - convert textile to html
9999
* `TableOfContentsFilter` - anchor headings with name attributes and generate Table of Contents html unordered list linking headings
100100

101-
## Syntax highlighting
101+
## Dependencies
102102

103+
Filter gem dependencies are not bundled; you must bundle the filter's gem
104+
dependencies. The below list details filters with dependencies. For example,
103105
`SyntaxHighlightFilter` uses [github-linguist](https://github.com/github/linguist)
104-
to detect and highlight languages. It isn't included as a dependency by default
105-
because it's a large dependency and
106-
[a hassle to build on heroku](https://github.com/jch/html-pipeline/issues/33).
107-
To use the filter, add the following to your Gemfile:
106+
to detect and highlight languages. To use the `SyntaxHighlightFilter`,
107+
add the following to your Gemfile:
108108

109109
```ruby
110110
gem 'github-linguist'
111111
```
112112

113+
* `AutolinkFilter` - `rinku`
114+
* `EmailReplyFilter` - `escape_utils`
115+
* `EmojiFilter` - `gemoji`
116+
* `MarkdownFilter` - `github-markdown`
117+
* `PlainTextInputFilter` - `escape_utils`
118+
* `SanitizationFilter` - `sanitize`
119+
* `SyntaxHighlightFilter` - `github-linguist`
120+
* `TextileFilter` - `RedCloth`
121+
122+
_Note:_ See [Gemfile](https://github.com/jch/html-pipeline/blob/master/Gemfile) `:test` block for version requirements.
123+
113124
## Examples
114125

115126
We define different pipelines for different parts of our app. Here are a few

html-pipeline.gemspec

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ Gem::Specification.new do |gem|
1515
gem.test_files = gem.files.grep(%r{^test})
1616
gem.require_paths = ["lib"]
1717

18-
gem.add_dependency "gemoji", "~> 1.0"
19-
gem.add_dependency "nokogiri", RUBY_VERSION < "1.9.2" ? [">= 1.4", "< 1.6"] : "~> 1.4"
20-
gem.add_dependency "github-markdown", "~> 0.5"
21-
gem.add_dependency "sanitize", RUBY_VERSION < "1.9.2" ? [">= 2", "< 2.0.4"] : "~> 2.0"
22-
gem.add_dependency "rinku", "~> 1.7"
23-
gem.add_dependency "escape_utils", "~> 0.3"
18+
gem.add_dependency "nokogiri", RUBY_VERSION < "1.9.2" ? [">= 1.4", "< 1.6"] : "~> 1.4"
2419

2520
gem.add_development_dependency "activesupport", RUBY_VERSION < "1.9.3" ? [">= 2", "< 4"] : ">= 2"
26-
gem.add_development_dependency "github-linguist", "~> 2.6.2"
21+
22+
gem.post_install_message = <<msg
23+
----------------------------------------------
24+
Thank you for installing html-pipeline!
25+
Filter gem dependencies are no longer bundled.
26+
You must bundle Filter gem dependencies.
27+
See html-pipeline README.md for more details.
28+
https://github.com/jch/html-pipeline
29+
----------------------------------------------
30+
msg
2731
end

lib/html/pipeline.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
require "nokogiri"
22
require "active_support/xml_mini/nokogiri" # convert Documents to hashes
3-
require "escape_utils"
43

54
module HTML
65
# GitHub HTML processing filters and utilities. This module includes a small

lib/html/pipeline/autolink_filter.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
require 'rinku'
1+
begin
2+
require "rinku"
3+
rescue LoadError => e
4+
missing = HTML::Pipeline::Filter::MissingDependencyException
5+
raise missing, missing::MESSAGE % "rinku", e.backtrace
6+
end
27

38
module HTML
49
class Pipeline

lib/html/pipeline/email_reply_filter.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
begin
2+
require "escape_utils"
3+
rescue LoadError => e
4+
missing = HTML::Pipeline::Filter::MissingDependencyException
5+
raise missing, missing::MESSAGE % "escape_utils", e.backtrace
6+
end
7+
18
module HTML
29
class Pipeline
310
# HTML Filter that converts email reply text into an HTML DocumentFragment.
@@ -53,4 +60,4 @@ def call
5360
end
5461
end
5562
end
56-
end
63+
end

lib/html/pipeline/emoji_filter.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
require 'emoji'
1+
begin
2+
require "gemoji"
3+
rescue LoadError => e
4+
missing = HTML::Pipeline::Filter::MissingDependencyException
5+
raise missing, missing::MESSAGE % "gemoji", e.backtrace
6+
end
27

38
module HTML
49
class Pipeline
@@ -51,4 +56,4 @@ def asset_root
5156
end
5257
end
5358
end
54-
end
59+
end

lib/html/pipeline/filter.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ class Pipeline
2727
# Each filter may define additional options and output values. See the class
2828
# docs for more info.
2929
class Filter
30+
# Public: Custom Exception raised when a Filter dependency is not installed.
31+
#
32+
# Examples
33+
#
34+
# begin
35+
# require "rinku"
36+
# rescue LoadError => e
37+
# missing = HTML::Pipeline::Filter::MissingDependencyException
38+
# raise missing, missing::MESSAGE % "rinku", e.backtrace
39+
# end
40+
class MissingDependencyException < StandardError
41+
# Public: Format String for MissingDependencyException message.
42+
MESSAGE = "Missing html-pipeline dependency: " +
43+
"Please add `%s` to your Gemfile; " +
44+
"see html-pipeline Gemfile for version."
45+
end
46+
3047
class InvalidDocumentException < StandardError; end
3148

3249
def initialize(doc, context = nil, result = nil)

lib/html/pipeline/markdown_filter.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
require 'github/markdown'
1+
begin
2+
require "github/markdown"
3+
rescue LoadError => e
4+
missing = HTML::Pipeline::Filter::MissingDependencyException
5+
raise missing, missing::MESSAGE % "github-markdown", e.backtrace
6+
end
27

38
module HTML
49
class Pipeline
@@ -26,4 +31,4 @@ def call
2631
end
2732
end
2833
end
29-
end
34+
end

lib/html/pipeline/plain_text_input_filter.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
begin
2+
require "escape_utils"
3+
rescue LoadError => e
4+
missing = HTML::Pipeline::Filter::MissingDependencyException
5+
raise missing, missing::MESSAGE % "escape_utils", e.backtrace
6+
end
7+
18
module HTML
29
class Pipeline
310
# Simple filter for plain text input. HTML escapes the text input and wraps it
@@ -8,4 +15,4 @@ def call
815
end
916
end
1017
end
11-
end
18+
end

0 commit comments

Comments
 (0)