nanoc-html-pipeline 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +49 -0
- data/README.md +36 -0
- data/Rakefile +13 -0
- data/lib/nanoc-html-pipeline/filter.rb +45 -0
- data/lib/nanoc-html-pipeline/version.rb +4 -0
- data/lib/nanoc-html-pipeline.rb +2 -0
- data/nanoc-html-pipeline.gemspec +30 -0
- data/test/nanoc_html_pipeline_test.rb +52 -0
- metadata +152 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nanoc-html-pipeline (0.2.0)
|
5
|
+
html-pipeline (>= 1.0.0)
|
6
|
+
nanoc (>= 3.1.6)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (4.0.1)
|
12
|
+
i18n (~> 0.6, >= 0.6.4)
|
13
|
+
minitest (~> 4.2)
|
14
|
+
multi_json (~> 1.3)
|
15
|
+
thread_safe (~> 0.1)
|
16
|
+
tzinfo (~> 0.3.37)
|
17
|
+
atomic (1.1.14)
|
18
|
+
colored (1.2)
|
19
|
+
cri (2.4.0)
|
20
|
+
colored (>= 1.2)
|
21
|
+
gemoji (1.5.0)
|
22
|
+
github-markdown (0.6.3)
|
23
|
+
html-pipeline (1.1.0)
|
24
|
+
activesupport (>= 2)
|
25
|
+
nokogiri (~> 1.4)
|
26
|
+
i18n (0.6.5)
|
27
|
+
mini_portile (0.5.2)
|
28
|
+
minitest (4.7.5)
|
29
|
+
multi_json (1.8.2)
|
30
|
+
nanoc (3.6.6)
|
31
|
+
cri (~> 2.3)
|
32
|
+
nokogiri (1.6.0)
|
33
|
+
mini_portile (~> 0.5.0)
|
34
|
+
rinku (1.7.3)
|
35
|
+
sanitize (2.0.6)
|
36
|
+
nokogiri (>= 1.4.4)
|
37
|
+
thread_safe (0.1.3)
|
38
|
+
atomic
|
39
|
+
tzinfo (0.3.38)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
gemoji (~> 1.5.0)
|
46
|
+
github-markdown (~> 0.6.3)
|
47
|
+
nanoc-html-pipeline!
|
48
|
+
rinku (~> 1.7.3)
|
49
|
+
sanitize (~> 2.0.6)
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
HTML::Pipeline for Nanoc
|
2
|
+
========================
|
3
|
+
|
4
|
+
An [HTML::Pipeline](https://github.com/jch/html-pipeline) filter for [Nanoc](http://nanoc.stoneship.org/).
|
5
|
+
|
6
|
+
Status
|
7
|
+
------
|
8
|
+
|
9
|
+
Still under development.
|
10
|
+
|
11
|
+
Installation
|
12
|
+
------------
|
13
|
+
|
14
|
+
HTML::Pipeline requires ICU.
|
15
|
+
|
16
|
+
```bash
|
17
|
+
brew install icu4c
|
18
|
+
bundle config build.charlock_holmes --with-icu-dir=/usr/local/opt/icu4c
|
19
|
+
```
|
20
|
+
|
21
|
+
In the near future, you'll be able to add this your Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'nanoc-html-pipeline'
|
25
|
+
```
|
26
|
+
|
27
|
+
Usage
|
28
|
+
-----
|
29
|
+
|
30
|
+
In your nanoc Rules file, use an `:html_pipeline` filter to run content through a pipeline.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
filter :html_pipeline,
|
34
|
+
:pipeline => [:mardownfilter, :emojifilter, :syntaxhighlightfilter],
|
35
|
+
:asset_root => "http://your-domain.com/where/your/emoji/live"
|
36
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift 'lib'
|
6
|
+
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
t.libs << "test"
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
10
|
+
t.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :test
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'nanoc3'
|
4
|
+
require 'html/pipeline'
|
5
|
+
|
6
|
+
module NanocHtmlPipeline
|
7
|
+
class Filter < Nanoc::Filter
|
8
|
+
|
9
|
+
def self.filter_key(s)
|
10
|
+
s.to_s.downcase.to_sym
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.is_filter(f)
|
14
|
+
f < HTML::Pipeline::Filter
|
15
|
+
rescue LoadError, ArgumentError
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
# Runs the content through [HTML::Pipline](https://github.com/jch/html-pipeline).
|
20
|
+
# Takes a `:pipeline` option as well as any additional context options.
|
21
|
+
|
22
|
+
# @param [String] content The content to filter
|
23
|
+
#
|
24
|
+
# @return [String] The filtered content
|
25
|
+
def run(content, params={})
|
26
|
+
# Get options
|
27
|
+
options = {:pipeline => []}.merge(params)
|
28
|
+
|
29
|
+
filters = options.delete(:pipeline).map do |f|
|
30
|
+
if self.class.is_filter(f)
|
31
|
+
f
|
32
|
+
else
|
33
|
+
key = self.class.filter_key(f)
|
34
|
+
filter = HTML::Pipeline.constants.find { |c| c.downcase == key }
|
35
|
+
HTML::Pipeline.const_get(filter)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
HTML::Pipeline.new(filters, options).to_html(content)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
Nanoc::Filter.register 'NanocHtmlPipeline::Filter', :html_pipeline
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib/', __FILE__)
|
3
|
+
$:.unshift lib unless $:.include?(lib)
|
4
|
+
|
5
|
+
require "nanoc-html-pipeline/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "nanoc-html-pipeline"
|
9
|
+
s.version = NanocHtmlPipeline::VERSION
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = ["Brent Fitzgerlad"]
|
12
|
+
s.email = ["b@brentfitzgerald.com"]
|
13
|
+
s.summary = "nanoc filter for html-pipeline"
|
14
|
+
s.description = ""
|
15
|
+
|
16
|
+
s.rubyforge_project = "nanoc-html-pipeline"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_runtime_dependency('nanoc', '>= 3.1.6')
|
24
|
+
s.add_runtime_dependency('html-pipeline', '>= 1.0.0')
|
25
|
+
|
26
|
+
s.add_development_dependency('rinku', '~> 1.7.3')
|
27
|
+
s.add_development_dependency('github-markdown', '~> 0.6.3')
|
28
|
+
s.add_development_dependency('gemoji', '~> 1.5.0')
|
29
|
+
s.add_development_dependency('sanitize', '~> 2.0.6')
|
30
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'active_support/core_ext/object/try'
|
4
|
+
require "nanoc-html-pipeline"
|
5
|
+
|
6
|
+
URL = "http://www.ruby-lang.org/"
|
7
|
+
CONTEXT = {
|
8
|
+
:asset_root => "http://foo.com/icons",
|
9
|
+
:base_url => "http://foo.com"
|
10
|
+
}
|
11
|
+
|
12
|
+
class NanocHtmlPipelineTest < Test::Unit::TestCase
|
13
|
+
|
14
|
+
def test_single_filter
|
15
|
+
input = "<p>a link is #{URL}</p>"
|
16
|
+
assert_equal HTML::Pipeline::AutolinkFilter.to_html(input),
|
17
|
+
NanocHtmlPipeline::Filter.new.run(input, :pipeline => [:autolinkfilter])
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_filter_class
|
21
|
+
input = "<p>a link is #{URL}</p>"
|
22
|
+
assert_equal NanocHtmlPipeline::Filter.new.run(input, :pipeline => [HTML::Pipeline::AutolinkFilter]),
|
23
|
+
NanocHtmlPipeline::Filter.new.run(input, :pipeline => [:autolinkfilter])
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_params
|
27
|
+
asset_root = "https://a248.e.akamai.net/assets.github.com/images/icons/"
|
28
|
+
expected = "<p>an emoji <img class=\"emoji\" title=\":smile:\" alt=\":smile:\" src=\"#{asset_root}emoji/smile.png\" height=\"20\" width=\"20\" align=\"absmiddle\"></p>"
|
29
|
+
assert_equal expected,
|
30
|
+
NanocHtmlPipeline::Filter.new.run("<p>an emoji :smile:</p>", :pipeline => [:emojifilter], :asset_root => asset_root)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_multiple_filters
|
34
|
+
assert_equal "<p>a link is <a href=\"#{URL}\">#{URL}</a></p>",
|
35
|
+
NanocHtmlPipeline::Filter.new.run("a link is #{URL}", :pipeline => [:markdownfilter, :autolinkfilter])
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_pipeline
|
39
|
+
input = "a link is #{URL}"
|
40
|
+
|
41
|
+
filters = [
|
42
|
+
HTML::Pipeline::MarkdownFilter,
|
43
|
+
HTML::Pipeline::SanitizationFilter,
|
44
|
+
HTML::Pipeline::ImageMaxWidthFilter,
|
45
|
+
HTML::Pipeline::HttpsFilter,
|
46
|
+
HTML::Pipeline::MentionFilter
|
47
|
+
]
|
48
|
+
pipeline = HTML::Pipeline.new(filters, CONTEXT.merge(:gfm => true))
|
49
|
+
assert_equal pipeline.to_html(input),
|
50
|
+
NanocHtmlPipeline::Filter.new.run(input, :pipeline => filters)
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nanoc-html-pipeline
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brent Fitzgerlad
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nanoc
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.6
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.1.6
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: html-pipeline
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.0.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rinku
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.7.3
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.7.3
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: github-markdown
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.6.3
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.6.3
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: gemoji
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.5.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.5.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: sanitize
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.0.6
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.0.6
|
110
|
+
description: ''
|
111
|
+
email:
|
112
|
+
- b@brentfitzgerald.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- Gemfile
|
119
|
+
- Gemfile.lock
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- lib/nanoc-html-pipeline.rb
|
123
|
+
- lib/nanoc-html-pipeline/filter.rb
|
124
|
+
- lib/nanoc-html-pipeline/version.rb
|
125
|
+
- nanoc-html-pipeline.gemspec
|
126
|
+
- test/nanoc_html_pipeline_test.rb
|
127
|
+
homepage:
|
128
|
+
licenses: []
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project: nanoc-html-pipeline
|
147
|
+
rubygems_version: 1.8.23
|
148
|
+
signing_key:
|
149
|
+
specification_version: 3
|
150
|
+
summary: nanoc filter for html-pipeline
|
151
|
+
test_files:
|
152
|
+
- test/nanoc_html_pipeline_test.rb
|