Skip to content

Commit 42f013f

Browse files
committed
Merge pull request #80 from simeonwillbanks/simple-dependency-management
Filters Manage Dependencies
2 parents 8ef9c5e + a0acb69 commit 42f013f

13 files changed

+98
-40
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: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +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+
## Dependencies
102+
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,
105+
`SyntaxHighlightFilter` uses [github-linguist](https://github.com/github/linguist)
106+
to detect and highlight languages. For example, to use the `SyntaxHighlightFilter`,
107+
add the following to your Gemfile:
108+
109+
```ruby
110+
gem 'github-linguist'
111+
```
112+
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](/Gemfile) `:test` block for version requirements.
123+
101124
## 3rd Party Extensions
102125

103126
If you have an idea for a filter, propose it as
@@ -107,19 +130,6 @@ built as an external gem.
107130

108131
* [html-pipeline-asciidoc_filter](https://github.com/asciidoctor/html-pipeline-asciidoc_filter) - asciidoc support
109132

110-
111-
## Syntax highlighting
112-
113-
`SyntaxHighlightFilter` uses [github-linguist](https://github.com/github/linguist)
114-
to detect and highlight languages. It isn't included as a dependency by default
115-
because it's a large dependency and
116-
[a hassle to build on heroku](https://github.com/jch/html-pipeline/issues/33).
117-
To use the filter, add the following to your Gemfile:
118-
119-
```ruby
120-
gem 'github-linguist'
121-
```
122-
123133
## Examples
124134

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

bin/html-pipeline

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ else
5454
case name
5555
when "Text"
5656
raise NameError # Text filter doesn't work, no call method
57-
when "Textile"
58-
require "RedCloth" # Textile filter doesn't require RedCloth
5957
end
6058

6159
HTML::Pipeline.const_get("#{name}Filter")
@@ -77,4 +75,4 @@ context = {
7775
:gfm => true
7876
}
7977

80-
puts HTML::Pipeline.new(filters, context).call(ARGF.read)[:output]
78+
puts HTML::Pipeline.new(filters, context).call(ARGF.read)[:output]

html-pipeline.gemspec

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ 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"
24-
gem.add_dependency "activesupport", RUBY_VERSION < "1.9.3" ? [">= 2", "< 4"] : ">= 2"
18+
gem.add_dependency "nokogiri", RUBY_VERSION < "1.9.2" ? [">= 1.4", "< 1.6"] : "~> 1.4"
19+
gem.add_dependency "activesupport", RUBY_VERSION < "1.9.3" ? [">= 2", "< 4"] : ">= 2"
2520

26-
gem.add_development_dependency "github-linguist", "~> 2.6.2"
21+
gem.post_install_message = <<msg
22+
-------------------------------------------------
23+
Thank you for installing html-pipeline!
24+
You must bundle Filter gem dependencies.
25+
See html-pipeline README.md for more details.
26+
https://github.com/jch/html-pipeline#dependencies
27+
-------------------------------------------------
28+
msg
2729
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
require 'rinku'
1+
begin
2+
require "rinku"
3+
rescue LoadError => _
4+
abort "Missing dependency 'rinku' for AutolinkFilter. See README.md for details."
5+
end
26

37
module HTML
48
class Pipeline

lib/html/pipeline/email_reply_filter.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
begin
2+
require "escape_utils"
3+
rescue LoadError => _
4+
abort "Missing dependency 'escape_utils' for EmailReplyFilter. See README.md for details."
5+
end
6+
17
module HTML
28
class Pipeline
39
# HTML Filter that converts email reply text into an HTML DocumentFragment.
@@ -53,4 +59,4 @@ def call
5359
end
5460
end
5561
end
56-
end
62+
end

lib/html/pipeline/emoji_filter.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
require 'emoji'
1+
begin
2+
require "gemoji"
3+
rescue LoadError => _
4+
abort "Missing dependency 'gemoji' for EmojiFilter. See README.md for details."
5+
end
26

37
module HTML
48
class Pipeline
@@ -51,4 +55,4 @@ def asset_root
5155
end
5256
end
5357
end
54-
end
58+
end

lib/html/pipeline/markdown_filter.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
require 'github/markdown'
1+
begin
2+
require "github/markdown"
3+
rescue LoadError => _
4+
abort "Missing dependency 'github-markdown' for MarkdownFilter. See README.md for details."
5+
end
26

37
module HTML
48
class Pipeline
@@ -26,4 +30,4 @@ def call
2630
end
2731
end
2832
end
29-
end
33+
end

lib/html/pipeline/plain_text_input_filter.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
begin
2+
require "escape_utils"
3+
rescue LoadError => _
4+
abort "Missing dependency 'escape_utils' for PlainTextInputFilter. See README.md for details."
5+
end
6+
17
module HTML
28
class Pipeline
39
# Simple filter for plain text input. HTML escapes the text input and wraps it
@@ -8,4 +14,4 @@ def call
814
end
915
end
1016
end
11-
end
17+
end

0 commit comments

Comments
 (0)