content-pipeline 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +12 -6
- data/Readme.md +50 -0
- data/lib/content/pipeline/core_extensions/object_ext.rb +2 -17
- data/lib/content/pipeline/filters/code_highlight.rb +3 -3
- data/lib/content/pipeline/filters/markdown.rb +7 -7
- data/lib/content/pipeline/filters.rb +2 -2
- data/lib/content/pipeline/version.rb +1 -1
- data/lib/content/pipeline.rb +4 -6
- metadata +10 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82e18bcc2d6c061a7b0ea5a7d1e2a2557718bbf1
|
4
|
+
data.tar.gz: f6aaedc35707c3d056556a0a890f25867392a353
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7303628384ea53a2854832749a465a08721861dbe9f48a36361f4577e6635d6c03538b988aed7ecfc8cea62311be285ed217add4ad38c81403ea47ee767e9aad
|
7
|
+
data.tar.gz: 06f12ee5b5df5aa9b69b8ff4129f5b0ec99ce1e628db1184402b5e0195671965f6497c2913b66d626273d5a074ea4378be606e5b6339e1d6556d6dd39327406f
|
data/Gemfile
CHANGED
@@ -1,12 +1,18 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
group :development do
|
5
|
-
|
6
|
-
|
5
|
+
unless ENV["CI"]
|
6
|
+
gem "pry"
|
7
|
+
end
|
8
|
+
|
9
|
+
gem "envygeeks-coveralls"
|
10
|
+
gem "kramdown"
|
11
|
+
gem "rake"
|
12
|
+
gem "luna-rspec-formatters"
|
7
13
|
|
8
|
-
unless RbConfig::CONFIG[
|
9
|
-
gem
|
10
|
-
gem
|
14
|
+
unless RbConfig::CONFIG["ruby_install_name"] == "jruby"
|
15
|
+
gem "pygments.rb"
|
16
|
+
gem "github-markdown"
|
11
17
|
end
|
12
18
|
end
|
data/Readme.md
CHANGED
@@ -4,3 +4,53 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
Content pipeline is like `html-pipeline` except it's less restrictive.
|
7
|
+
|
8
|
+
## Installing
|
9
|
+
|
10
|
+
```
|
11
|
+
gem install content-pipeline
|
12
|
+
```
|
13
|
+
|
14
|
+
```
|
15
|
+
gem 'content-pipeline', '~> <VERSION>'
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Content Pipeline is extremely simple to use out of the box:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
pipeline = Content::Pipeline.new([ MyFilter ], :my_filter => { :o1 => true })
|
24
|
+
pipeline.filter('# Markdown', :my_filter => { :o1 => false })
|
25
|
+
```
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Content::Pipeline.new.filter('# Markdown')
|
29
|
+
```
|
30
|
+
|
31
|
+
* Supports multiple Markdowns.
|
32
|
+
* Supports global options with overrides.
|
33
|
+
* By default uses both `CodeHighlight` and `Markdown`.
|
34
|
+
|
35
|
+
*It should be noted that if you send a list of filters you wish to use, it will not use the default filters at all. So where you see `[ MyFilter ]` that will be the only filter that is ran, since it automatically assumes this is the pipeline you wish to use.*
|
36
|
+
|
37
|
+
### Filter Options
|
38
|
+
|
39
|
+
Filter options are set globally and can be overriden each time the filter is ran, this allows for you to setup a single pipeline and then adjust it on the fly on a per-content basis, for example if you wish to run `Markdown` `:safe` on user comments but not on posts, then you would simply setup the global pipeline and then each time you parse a user comment send the content with the hash `{ :markdown => { :safe => true }}`.
|
40
|
+
|
41
|
+
*All options are keyed based on their class name, so `MyFilter` would have the option key `:my_filter`*
|
42
|
+
|
43
|
+
### Content::Pipeline::Filters::Markdown
|
44
|
+
|
45
|
+
The Markdown filter allows you to choose between `github-markdown` and `kramdown`, and by default will use `kramdown` on jRuby and `github-markdown` on any other Ruby that supports it. **These dependencies are loose, which means you must install the one you wish to use.**
|
46
|
+
|
47
|
+
Options:
|
48
|
+
* `:type` => [`:gfm`, `:markdown`, `:kramdown`] - The Markdown filter you wish to use.
|
49
|
+
* `:safe` => [`true`, `false`] - Does basic filtering, removes images and strips autolinked anchors.
|
50
|
+
|
51
|
+
*You should not need to adjust any of your "\`\`\`" because the `Markdown` filter will automatically convert those to `~~~` if you choose Kramdown. This is not done because one way is
|
52
|
+
better than the other, it's done so that people can remain agnostic.*
|
53
|
+
|
54
|
+
### Content::Pipeline::Filters::CodeHighlight
|
55
|
+
|
56
|
+
The code highlight filter allows you to highlight code, with or without Pygments. If Pygments is supported it will require it and syntax highlight, otherwise it will simply wrap your code in the normal code style and not syntax highlight it. You will still have the line numbers, just not the fancy syntax highlight.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "nokogiri"
|
2
2
|
|
3
3
|
module CoreExtensions
|
4
4
|
|
@@ -9,7 +9,7 @@ module CoreExtensions
|
|
9
9
|
module ObjectExt
|
10
10
|
|
11
11
|
def jruby?
|
12
|
-
RbConfig::CONFIG[
|
12
|
+
RbConfig::CONFIG["ruby_install_name"] == "jruby"
|
13
13
|
end
|
14
14
|
|
15
15
|
# ------------------------------------------------------------------------
|
@@ -20,21 +20,6 @@ module CoreExtensions
|
|
20
20
|
return self if Nokogiri::HTML::DocumentFragment === self
|
21
21
|
Nokogiri::HTML.fragment(respond_to?(:to_html) ? to_html : to_s)
|
22
22
|
end
|
23
|
-
|
24
|
-
# ------------------------------------------------------------------------
|
25
|
-
# Require a file with a fallback and if all else fails send an error.
|
26
|
-
# ------------------------------------------------------------------------
|
27
|
-
|
28
|
-
def require_or_fail(a, b, msg)
|
29
|
-
require a
|
30
|
-
rescue LoadError
|
31
|
-
begin
|
32
|
-
require b
|
33
|
-
rescue LoadError => error
|
34
|
-
# Try to keep the call chain proper.
|
35
|
-
raise LoadError, msg, error.backtrace[3...-1]
|
36
|
-
end
|
37
|
-
end
|
38
23
|
end
|
39
24
|
end
|
40
25
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "pygments" unless jruby?
|
2
2
|
|
3
3
|
# ----------------------------------------------------------------------------
|
4
4
|
# A filter that discovers pre tags and then syntax highlights them, also
|
@@ -41,7 +41,7 @@ class Content::Pipeline::Filters::CodeHighlight < Content::Pipeline::Filter
|
|
41
41
|
@str = @str.to_nokogiri_fragment
|
42
42
|
@str.search('pre').each do |node|
|
43
43
|
node.replace Templates[:wrap] %
|
44
|
-
wrap(pygments(node.inner_text, node[:lang]), node[:lang] ||
|
44
|
+
wrap(pygments(node.inner_text, node[:lang]), node[:lang] || "text")
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -51,7 +51,7 @@ class Content::Pipeline::Filters::CodeHighlight < Content::Pipeline::Filter
|
|
51
51
|
|
52
52
|
private
|
53
53
|
def wrap(str, lang)
|
54
|
-
lines, numbs =
|
54
|
+
lines, numbs = "", ""; str.each_line.with_index(1) do |line, numb|
|
55
55
|
lines+= Templates[:line] % line
|
56
56
|
numbs+= Templates[:numb] % numb
|
57
57
|
end
|
@@ -16,12 +16,12 @@ class Content::Pipeline::Filters::Markdown < Content::Pipeline::Filter
|
|
16
16
|
|
17
17
|
@str = case
|
18
18
|
when type =~ /\Amarkdown|gfm\Z/
|
19
|
-
require
|
20
|
-
GitHub::Markdown.to_html(@str, @opts.fetch(:type, :gfm))
|
19
|
+
require "github/markdown"
|
20
|
+
GitHub::Markdown.to_html(@str, @opts.fetch(:type, :gfm)).strip
|
21
21
|
else
|
22
|
-
require
|
22
|
+
require "kramdown"
|
23
23
|
fix_kramdown_wraps(Kramdown::Document.
|
24
|
-
new(convert_backtick(@str), :enable_coderay => false).to_html)
|
24
|
+
new(convert_backtick(@str), :enable_coderay => false).to_html).strip
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -52,7 +52,7 @@ class Content::Pipeline::Filters::Markdown < Content::Pipeline::Filter
|
|
52
52
|
|
53
53
|
private
|
54
54
|
def strip_links
|
55
|
-
@str.search(
|
55
|
+
@str.search("a").each do |node|
|
56
56
|
node.replace(node[:href])
|
57
57
|
end
|
58
58
|
end
|
@@ -63,7 +63,7 @@ class Content::Pipeline::Filters::Markdown < Content::Pipeline::Filter
|
|
63
63
|
|
64
64
|
private
|
65
65
|
def strip_image
|
66
|
-
@str.search(
|
66
|
+
@str.search("img").each do |node|
|
67
67
|
# Tries to cover single line images wrapped in a paragraph.
|
68
68
|
node.parent.children.count == 1 ? node.parent.remove : node.remove
|
69
69
|
end
|
@@ -75,7 +75,7 @@ class Content::Pipeline::Filters::Markdown < Content::Pipeline::Filter
|
|
75
75
|
|
76
76
|
private
|
77
77
|
def convert_backtick(str)
|
78
|
-
str.gsub(/^`{3}(\s?[a-zA-Z0-9]+)?$/,
|
78
|
+
str.gsub(/^`{3}(\s?[a-zA-Z0-9]+)?$/, "~~~\\1")
|
79
79
|
end
|
80
80
|
|
81
81
|
# --------------------------------------------------------------------------
|
@@ -47,8 +47,8 @@ class Content::Pipeline
|
|
47
47
|
# --------------------------------------------------------------------------
|
48
48
|
|
49
49
|
module Filters
|
50
|
-
require_relative
|
51
|
-
require_relative
|
50
|
+
require_relative "filters/code_highlight"
|
51
|
+
require_relative "filters/markdown"
|
52
52
|
|
53
53
|
# ------------------------------------------------------------------------
|
54
54
|
# A set of default filters that we use if the user does not supply their
|
data/lib/content/pipeline.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
3
|
-
$:.unshift(File.expand_path(
|
1
|
+
require_relative "pipeline/core_extensions/object_ext"
|
2
|
+
require_relative "pipeline/core_extensions/hash_ext"
|
3
|
+
$:.unshift(File.expand_path("../../", __FILE__))
|
4
4
|
|
5
5
|
module Content
|
6
6
|
|
@@ -11,15 +11,13 @@ module Content
|
|
11
11
|
# --------------------------------------------------------------------------
|
12
12
|
|
13
13
|
class Pipeline
|
14
|
-
require_relative
|
14
|
+
require_relative "pipeline/filters"
|
15
15
|
attr_reader :filters, :opts
|
16
16
|
|
17
17
|
# ------------------------------------------------------------------------
|
18
18
|
# Allows the user to initialize with a custom set of filters or to auto
|
19
19
|
# load our filters and use them, the base filters we provider are
|
20
20
|
# redcarpet and pygments.
|
21
|
-
#
|
22
|
-
# @opt filters [Array] a list of filters to use.
|
23
21
|
# ------------------------------------------------------------------------
|
24
22
|
|
25
23
|
def initialize(filters = Filters::DEFAULT_FILTERS, opts = nil)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: content-pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordon Bedwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -25,61 +25,33 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.6.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.6.7
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ~>
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.6.7
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
28
|
+
name: rspec
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - ~>
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
33
|
+
version: '2.14'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - ~>
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 2.14.0.rc1
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 2.14.0.rc1
|
40
|
+
version: '2.14'
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
42
|
+
name: rspec-expect_error
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
72
44
|
requirements:
|
73
|
-
- - '
|
45
|
+
- - '='
|
74
46
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.0.
|
47
|
+
version: 0.0.2
|
76
48
|
type: :development
|
77
49
|
prerelease: false
|
78
50
|
version_requirements: !ruby/object:Gem::Requirement
|
79
51
|
requirements:
|
80
|
-
- - '
|
52
|
+
- - '='
|
81
53
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.0.
|
54
|
+
version: 0.0.2
|
83
55
|
description: A less restrictive version of html-pipeline for content.
|
84
56
|
email: envygeeks@gmail.com
|
85
57
|
executables: []
|