jekyll-html-pipeline 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 79b3b2da5b06f5577b46805ae5db216d0c0b68dd
4
+ data.tar.gz: 58961e54bff495fe738d057a8d7ba4e103473021
5
+ SHA512:
6
+ metadata.gz: e75a188072a3f649dc68915d7d9e6102582ea0583076f0e5937c4b0c6e46226c3c5309c5630e0998b74cf34d848d2ea52b508dce319350128a030e99a23e7fe3
7
+ data.tar.gz: 731abf81870e6bf86d126587a628e8148a48e0d115e4be8a89634d50b9a2facee80a5ed4b50ef25e4c9e5f7a9d106e67496d07087fb22f23ac3790feec328892
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyll-html-pipeline.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Garen Torikian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ [![Build Status](https://travis-ci.org/gjtorikian/jekyll-html-pipeline.svg?branch=master)](https://travis-ci.org/gjtorikian/jekyll-html-pipeline)
2
+
3
+ jekyll-html-pipeline
4
+ ====================
5
+
6
+ An [HTML::Pipeline](https://github.com/jch/html-pipeline), for Jekyll.
7
+
8
+
9
+ ## Installation
10
+
11
+ In your *_config.yml* file, add this gem:
12
+
13
+ ``` yaml
14
+ gems:
15
+ - jekyll-html-pipeline
16
+ ```
17
+
18
+ ## Configuration
19
+
20
+ You'll need to be running a Jekyll version after 2.0.0, which is when custom
21
+ Markdown filters were introduced. In your *_config.yml* file, indicate that you
22
+ want to use `html_pipeline`:
23
+
24
+ ``` yaml
25
+ markdown: HTMLPipeline
26
+ ```
27
+
28
+ Next, create an `html_pipeline` key, and indicate which filters you want to include:
29
+
30
+ ``` yaml
31
+ markdown: HTMLPipeline
32
+ html_pipeline:
33
+ filters:
34
+ - "markdownfilter"
35
+ - "sanitizationfilter"
36
+ - "emojifilter"
37
+ - "mentionfilter"
38
+ ```
39
+
40
+ Finally, some filters require a context object. You can define these next:
41
+
42
+ ``` yaml
43
+ markdown: HTMLPipeline
44
+ html_pipeline:
45
+ filters:
46
+ - "markdownfilter"
47
+ - "sanitizationfilter"
48
+ - "emojifilter"
49
+ - "mentionfilter"
50
+ context:
51
+ asset_root: "http://foo.com/icons"
52
+ base_url: "https://github.com/"
53
+ ```
54
+
55
+ Keep in mind that [filter dependencies are not bundled](https://github.com/jch/html-pipeline#dependencies),
56
+ so you'll need to add these in yourself.
57
+
58
+ ## Custom filters
59
+
60
+ Custom filters can be designed [the same as in HTML::Pipeline](https://github.com/jch/html-pipeline#extending).
61
+
62
+ Check out [the test filter](./test/support/new_pipeline.rb) for an example.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => [:test]
4
+
5
+ require 'rake/testtask'
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.pattern = 'test/**/test_*.rb'
9
+ test.verbose = true
10
+ end
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "jekyll-html-pipeline"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Garen Torikian"]
5
+ spec.email = ["gjtorikian@gmail.com"]
6
+ spec.summary = %q{Use GitHub's HTML::Pipeline, in Jekyll!}
7
+ spec.description = %q{This is a custom Markdown processor for Jekyll 2.0 and above. It allows you to use GitHub's HTML::Pipeline in your Jekyll projects. }
8
+ spec.homepage = ""
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files`.split($/)
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_dependency "jekyll", "~> 2.0.0.alpha.1 "
17
+ spec.add_dependency('html-pipeline', "~> 1.0.0")
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.4"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency('shoulda', "~> 3.5")
22
+ spec.add_development_dependency('github-markdown', "~> 0.6.3")
23
+ spec.add_development_dependency('sanitize', "~> 2.0.6")
24
+ spec.add_development_dependency('gemoji', "~> 1.5.0")
25
+ spec.add_development_dependency "rouge"
26
+ end
@@ -0,0 +1,76 @@
1
+ module Jekyll
2
+ module Converters
3
+ class Markdown::HTMLPipeline
4
+ def initialize(config)
5
+ require 'html/pipeline'
6
+ @config = config
7
+ @errors = []
8
+ end
9
+
10
+ def filter_key(s)
11
+ s.to_s.downcase.to_sym
12
+ end
13
+
14
+ def is_filter?(f)
15
+ f < HTML::Pipeline::Filter
16
+ rescue LoadError, ArgumentError
17
+ false
18
+ end
19
+
20
+ def symbolize_keys(hash)
21
+ hash.inject({}){|result, (key, value)|
22
+ new_key = case key
23
+ when String then key.to_sym
24
+ else key
25
+ end
26
+ new_value = case value
27
+ when Hash then symbolize_keys(value)
28
+ else value
29
+ end
30
+ result[new_key] = new_value
31
+ result
32
+ }
33
+ end
34
+
35
+ def ensure_default_opts
36
+ @config['html_pipeline']['filters'] ||= ['markdownfilter']
37
+ @config['html_pipeline']['context'] ||= {'gfm' => true}
38
+ # symbolize strings as keys, which is what HTML::Pipeline wants
39
+ @config['html_pipeline']['context'] = symbolize_keys(@config['html_pipeline']['context'])
40
+ end
41
+
42
+ def setup
43
+ unless @setup
44
+ ensure_default_opts
45
+
46
+ filters = @config['html_pipeline']['filters'].map do |f|
47
+ if is_filter?(f)
48
+ f
49
+ else
50
+ key = filter_key(f)
51
+ begin
52
+ filter = HTML::Pipeline.constants.find { |c| c.downcase == key }
53
+ # probably a custom filter
54
+ if filter.nil?
55
+ Jekyll::Converters.const_get(f)
56
+ else
57
+ HTML::Pipeline.const_get(filter)
58
+ end
59
+ rescue Exception => e
60
+ raise LoadError.new(e)
61
+ end
62
+ end
63
+ end
64
+
65
+ @parser = HTML::Pipeline.new(filters, @config['html_pipeline']['context'])
66
+ @setup = true
67
+ end
68
+ end
69
+
70
+ def convert(content)
71
+ setup
72
+ @parser.to_html(content)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,48 @@
1
+ require "rubygems"
2
+
3
+ require "jekyll"
4
+ require "liquid"
5
+
6
+ require 'test/unit'
7
+ require 'shoulda'
8
+
9
+ require "html/pipeline"
10
+
11
+ require "jekyll-html-pipeline"
12
+
13
+ # Send STDERR into the void to suppress program output messages
14
+ # STDERR.reopen(test(?e, '/dev/null') ? '/dev/null' : 'NUL:')
15
+
16
+ class Test::Unit::TestCase
17
+ def dest_dir(*subdirs)
18
+ test_dir('dest', *subdirs)
19
+ end
20
+
21
+ def source_dir(*subdirs)
22
+ test_dir('source', *subdirs)
23
+ end
24
+
25
+ def clear_dest
26
+ FileUtils.rm_rf(dest_dir)
27
+ end
28
+
29
+ def test_dir(*subdirs)
30
+ File.join(File.dirname(__FILE__), *subdirs)
31
+ end
32
+
33
+ def directory_with_contents(path)
34
+ FileUtils.rm_rf(path)
35
+ FileUtils.mkdir(path)
36
+ File.open("#{path}/index.html", "w"){ |f| f.write("I was previously generated.") }
37
+ end
38
+
39
+ def capture_stdout
40
+ $old_stdout = $stdout
41
+ $stdout = StringIO.new
42
+ yield
43
+ $stdout.rewind
44
+ return $stdout.string
45
+ ensure
46
+ $stdout = $old_stdout
47
+ end
48
+ end
@@ -0,0 +1,15 @@
1
+ require "html/pipeline"
2
+
3
+ class HelpMarkdownFilter < HTML::Pipeline::MarkdownFilter
4
+
5
+ def call
6
+ html = super
7
+
8
+ format_callout!(html)
9
+ end
10
+
11
+ def format_callout!(html)
12
+ html.gsub!(/(?:<p>)?{{#(tip|warning|error)}}(?:<\/p>)?/, '<div class="alert \1">')
13
+ html.gsub!(/(?:<p>)?{{\/(tip|warning|error)}}(?:<\/p>)?/, '</div>')
14
+ end
15
+ end
@@ -0,0 +1,50 @@
1
+ require "helper"
2
+
3
+ class HTMLPipeline < Test::Unit::TestCase
4
+ context "html_pipeline" do
5
+ setup do
6
+ @config = {
7
+ 'html_pipeline' => {
8
+ 'filters' => ['markdownfilter', 'sanitizationfilter', 'emojifilter', 'mentionfilter'],
9
+ 'context' => { 'asset_root' => "http://foo.com/icons", 'base_url' => "https://github.com/"}},
10
+ 'markdown' => 'HTMLPipeline'
11
+ }
12
+ @markdown = Jekyll::Converters::Markdown.new @config
13
+ end
14
+
15
+ should "pass regular options" do
16
+ assert_equal "<h1>Some Header</h1>", @markdown.convert('# Some Header #').strip
17
+ end
18
+
19
+ should "pass rendering emoji" do
20
+ assert_equal "<p><img class=\"emoji\" title=\":trollface:\" alt=\":trollface:\" src=\"http://foo.com/icons/emoji/trollface.png\" height=\"20\" width=\"20\" align=\"absmiddle\"></p>", @markdown.convert(':trollface:').strip
21
+ end
22
+
23
+ should "pass rendering mentions" do
24
+ assert_equal "<p><strong>Hey, <a href=\"https://github.com/mojombo\" class=\"user-mention\">@mojombo</a></strong>!</p>", @markdown.convert('**Hey, @mojombo**!').strip
25
+ end
26
+
27
+ should "fail when a library dependency is not met" do
28
+ override = @config.dup
29
+ override['html_pipeline']['filters'] << 'AutolinkFilter'
30
+ markdown = Jekyll::Converters::Markdown.new override
31
+ assert_raise(LoadError) { markdown.convert('http://www.github.com') }
32
+ end
33
+
34
+ should "fail when a context dependency is not met" do
35
+ override = @config.dup
36
+ override['html_pipeline'].delete 'context'
37
+ markdown = Jekyll::Converters::Markdown.new override
38
+ assert_raise(ArgumentError) { markdown.convert(':trollface:') }
39
+ end
40
+
41
+ should "work for custom filters" do
42
+ require 'support/new_pipeline'
43
+ override = @config.dup
44
+ override['html_pipeline']['filters'] = ['HelpMarkdownFilter']
45
+ markdown = Jekyll::Converters::Markdown.new override
46
+ text = "\n {{#tip}}\n **Tip**: Wow! \n {{/tip}}"
47
+ assert_equal "<div class=\"alert tip\"><br>\n <strong>Tip</strong>: Wow! <br>\n </div>", markdown.convert(text)
48
+ end
49
+ end
50
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-html-pipeline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Garen Torikian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0.alpha.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0.alpha.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: html-pipeline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: shoulda
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '3.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '3.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: github-markdown
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.6.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.6.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: sanitize
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 2.0.6
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 2.0.6
111
+ - !ruby/object:Gem::Dependency
112
+ name: gemoji
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.5.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 1.5.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rouge
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: 'This is a custom Markdown processor for Jekyll 2.0 and above. It allows
140
+ you to use GitHub''s HTML::Pipeline in your Jekyll projects. '
141
+ email:
142
+ - gjtorikian@gmail.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - .gitignore
148
+ - .travis.yml
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - jekyll-html-pipeline.gemspec
154
+ - lib/jekyll-html-pipeline.rb
155
+ - test/helper.rb
156
+ - test/support/new_pipeline.rb
157
+ - test/test_jekyll_html_pipeline.rb
158
+ homepage: ''
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.0.3
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: Use GitHub's HTML::Pipeline, in Jekyll!
182
+ test_files:
183
+ - test/helper.rb
184
+ - test/support/new_pipeline.rb
185
+ - test/test_jekyll_html_pipeline.rb