content-pipeline 1.3.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 991fd8e8b431cb824d231a1b1fe560d787265c85
4
- data.tar.gz: 6fe340c02196d5f801c2f2e192ddc05949f1430b
3
+ metadata.gz: bba12870b71565c1fea769e7d42efdc24e6c81c6
4
+ data.tar.gz: 5790bc5e711b6fd67ab6bfa5b2d0db3a902c8331
5
5
  SHA512:
6
- metadata.gz: a1e6a1ed2fe1fdc8166f000b9e77f700bdfa554d0b2abcdbfbb398d40acfa5c2731eac8da6e2bd96dbc3afbe5557b0585fc901ddfb9aecbe931de0d84b5c679e
7
- data.tar.gz: c5525d697339e39b0aa98d7f0d963ef02fceed5109dd9958a92331b55ded6591202b46a403a397aa2fb2465c5ee7183ee97aaa8a223b18690632e73c9a000b03
6
+ metadata.gz: 5412086ab63a43647abcf2a0f8da42718dd6ab735957b890a3c851def70531398a8edaa72489177536a6581d1befc2a5622a0d0c8fded8615f218302b8ffecd5
7
+ data.tar.gz: 3d4b8f9616ad5f9ffea5f369f17e657722587cb0d2c15ca3bb84527fe242760671cec73eec751355cb481d93b0e4f0c4c742a5e023605bfdad8f6b0995ee042b
data/Readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Content Pipeline.
2
2
 
3
- [![Build Status](https://travis-ci.org/envygeeks/content-pipeline.png?branch=master)](https://travis-ci.org/envygeeks/content-pipeline) [![Coverage Status](https://coveralls.io/repos/envygeeks/content-pipeline/badge.png)](https://coveralls.io/r/envygeeks/content-pipeline) [![Code Climate](https://codeclimate.com/github/envygeeks/content-pipeline.png)](https://codeclimate.com/github/envygeeks/content-pipeline) [![Dependency Status](https://gemnasium.com/envygeeks/content-pipeline.png)](https://gemnasium.com/envygeeks/content-pipeline)
3
+ [![Build Status](https://travis-ci.org/envygeeks/ruby-content-pipeline.png?branch=master)](https://travis-ci.org/envygeeks/ruby-content-pipeline) [![Coverage Status](https://coveralls.io/repos/envygeeks/content-pipeline/badge.png)](https://coveralls.io/r/envygeeks/content-pipeline) [![Code Climate](https://codeclimate.com/github/envygeeks/content-pipeline.png)](https://codeclimate.com/github/envygeeks/content-pipeline) [![Dependency Status](https://gemnasium.com/envygeeks/content-pipeline.png)](https://gemnasium.com/envygeeks/content-pipeline)
4
4
 
5
5
 
6
6
  Content pipeline is like `html-pipeline` except it's less restrictive.
@@ -81,7 +81,7 @@ Options:
81
81
  *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
82
82
  better than the other, it's done so that people can remain agnostic.*
83
83
 
84
- ### Content::Pipeline::Filters::CodeHighlight
84
+ ### Content::Pipeline::Filters::Code
85
85
 
86
86
  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.
87
87
 
@@ -0,0 +1,51 @@
1
+ unless jruby?
2
+ require "pygments"
3
+ end
4
+
5
+ class Content::Pipeline::Filters::Code < Content::Pipeline::Filter
6
+ add_filter({
7
+ :highlight => :nokogiri
8
+ })
9
+
10
+ Matcher = /<pre>(.+)<\/pre>/m
11
+ Templates = {
12
+ :numb => %Q{<span class="line-number">%s</span>\n},
13
+ :line => '<span class="line">%s</span>',
14
+ :wrap => <<-HTML,
15
+ <figure class="highlight">
16
+ <pre>
17
+ <code class="%s">
18
+ %s
19
+ </code>
20
+ </pre>
21
+ </figure>
22
+ HTML
23
+ }
24
+
25
+ def initialize(*args)
26
+ super(
27
+ *args
28
+ )
29
+ end
30
+
31
+ private
32
+ def highlight
33
+ @str = @str.to_nokogiri_fragment
34
+ @str.search("pre > code").each do |node|
35
+ lang = node[:class] || node.parent[:lang] || \
36
+ @opts[:default] || "ruby"
37
+
38
+ node.parent.replace(
39
+ Templates[:wrap] % [
40
+ lang, pygments(node.inner_text, lang)
41
+ ]
42
+ )
43
+ end
44
+ end
45
+
46
+ private
47
+ def pygments(str, lang)
48
+ return str if jruby? || !Pygments::Lexer[lang]
49
+ Pygments::Lexer[lang].highlight(str) =~ Matcher ? $1 : str
50
+ end
51
+ end
@@ -11,23 +11,25 @@ class Content::Pipeline::Filters::Gemoji < Content::Pipeline::Filter
11
11
 
12
12
  def initialize(*args)
13
13
  super(*args)
14
- # I should make this an addon.
15
- @opts[:asset_path] ||= "/assets"
14
+ @opts[:asset_path] ||= \
15
+ "/assets"
16
16
  end
17
17
 
18
18
  private
19
19
  def gemoji
20
20
  @str = @str.to_nokogiri_fragment
21
- [:xpath, :search].each do |t|
22
- @str.send(t, "text()").each do |n|
23
- parse_node(n)
24
- end
21
+ @str.xpath(".//child::text()").each do |n|
22
+ parse_node(
23
+ n
24
+ )
25
25
  end
26
26
  end
27
27
 
28
28
  def parse_node(node)
29
29
  return node if node.ancestors.any? do |n|
30
- n.node_name == "code" || n.node_name == "pre"
30
+ ["pre", "code"].include?(
31
+ n.node_name
32
+ )
31
33
  end
32
34
 
33
35
  node.replace(node.to_html.gsub(EmojiPattern) do
@@ -37,10 +39,14 @@ class Content::Pipeline::Filters::Gemoji < Content::Pipeline::Filter
37
39
  if ! @opts[:tag] && ! @opts[:tag].is_a?(Proc)
38
40
  if @opts[:as_liquid_asset]
39
41
  then EmojiLiquidTag % [ep, en]
40
- else EmojiTag % [ep, en]
42
+ else EmojiTag % [
43
+ ep, en
44
+ ]
41
45
  end
42
46
  else
43
- @opts[:tag].call(ep, en)
47
+ @opts[:tag].call(
48
+ ep, en
49
+ )
44
50
  end
45
51
  end)
46
52
  end
@@ -0,0 +1,15 @@
1
+ class Content::Pipeline::Filters::Https < Content::Pipeline::Filter
2
+ HttpRegexp = /\A(\/\/|http:\/\/)/
3
+ add_filter({
4
+ :https => :nokogiri
5
+ })
6
+
7
+ def https
8
+ @str = @str.to_nokogiri_fragment
9
+ @str.xpath(".//a").select { |v| v[:href] =~ HttpRegexp }.each do |v|
10
+ v[:href] = v[:href].gsub(
11
+ HttpRegexp, "https://"
12
+ )
13
+ end
14
+ end
15
+ end
@@ -72,7 +72,7 @@ class Content::Pipeline::Filters::Markdown < Content::Pipeline::Filter
72
72
  @str = @str.to_nokogiri_fragment
73
73
  private_methods(false).keep_if { |m| m =~ /\Astrip_/ }.each do |m|
74
74
  unless m == :strip_html
75
- send(m)
75
+ then send(m)
76
76
  end
77
77
  end
78
78
  end
@@ -80,15 +80,21 @@ class Content::Pipeline::Filters::Markdown < Content::Pipeline::Filter
80
80
 
81
81
  private
82
82
  def strip_links
83
- @str.search("a").each do |n|
84
- n.replace(n[:href])
83
+ @str.xpath(".//a").each do |n|
84
+ n.replace(
85
+ n[
86
+ :href
87
+ ]
88
+ )
85
89
  end
86
90
  end
87
91
 
88
92
  private
89
93
  def strip_image
90
- @str.search("img").each do |n|
91
- n.parent.children.count == 1 ? n.parent.remove : n.remove
94
+ @str.xpath(".//img").each do |n|
95
+ if n.parent.children.count == 1
96
+ then n.parent.remove else n.remove
97
+ end
92
98
  end
93
99
  end
94
100
 
@@ -99,7 +105,8 @@ class Content::Pipeline::Filters::Markdown < Content::Pipeline::Filter
99
105
 
100
106
  private
101
107
  def normalize_kramdown(str)
102
- str.gsub(/<pre><code class="language-([A-Za-z0-9]+)">/, \
103
- '<pre lang="\\1"><code>')
108
+ str.gsub(
109
+ /<pre><code class="language-([A-Za-z0-9]+)">/, '<pre lang="\\1"><code>'
110
+ )
104
111
  end
105
112
  end
@@ -1,5 +1,5 @@
1
1
  module Content
2
2
  class Pipeline
3
- VERSION = "1.3.6"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -35,10 +35,9 @@ module Content
35
35
  private
36
36
  def to_opt(cls)
37
37
  cls = cls.name.split(/::/).last
38
-
39
- [
40
- cls.downcase,
41
- underscore_cls(cls) ].uniq.map(&:to_sym)
38
+ [cls.downcase, underscore_cls(cls) ].uniq.map(
39
+ &:to_sym
40
+ )
42
41
  end
43
42
 
44
43
  private
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: 1.3.6
4
+ version: 2.0.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: 2014-12-24 00:00:00.000000000 Z
11
+ date: 2015-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '3.0'
33
+ version: '3.2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '3.0'
40
+ version: '3.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: envygeeks-coveralls
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.2'
47
+ version: '0.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.2'
54
+ version: '0.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-collection_matchers
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1'
75
+ version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '1'
82
+ version: '3.0'
83
83
  description: A less restrictive version of html-pipeline for content.
84
84
  email: envygeeks@gmail.com
85
85
  executables: []
@@ -94,8 +94,9 @@ files:
94
94
  - lib/content/pipeline/core_extensions/hash_ext.rb
95
95
  - lib/content/pipeline/core_extensions/object_ext.rb
96
96
  - lib/content/pipeline/filters.rb
97
- - lib/content/pipeline/filters/code_highlight.rb
97
+ - lib/content/pipeline/filters/code.rb
98
98
  - lib/content/pipeline/filters/gemoji.rb
99
+ - lib/content/pipeline/filters/https.rb
99
100
  - lib/content/pipeline/filters/markdown.rb
100
101
  - lib/content/pipeline/jekyll/converter.rb
101
102
  - lib/content/pipeline/version.rb
@@ -119,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  version: '0'
120
121
  requirements: []
121
122
  rubyforge_project:
122
- rubygems_version: 2.2.2
123
+ rubygems_version: 2.4.7
123
124
  signing_key:
124
125
  specification_version: 4
125
126
  summary: Adds a pipeline for your content.
@@ -1,80 +0,0 @@
1
- require "pygments" unless jruby?
2
-
3
- class Content::Pipeline::Filters::CodeHighlight < Content::Pipeline::Filter
4
- add_filter({
5
- :highlight => :nokogiri
6
- })
7
-
8
- Matcher = /<pre>(.+)<\/pre>/m
9
- Templates = {
10
- :numb => %Q{<span class="line-number">%s</span>\n},
11
- :line => '<span class="line">%s</span>',
12
- :wrap => <<-HTML,
13
- <figure class="code">
14
- <div class="highlight">
15
- <table>
16
- <tbody>
17
- <tr>
18
- %s
19
- <td class="code">
20
- <pre><code class="%s">%s</code></pre>
21
- </td>
22
- </tr>
23
- </tbody>
24
- </table>
25
- </div>
26
- </figure>
27
- HTML
28
-
29
- :gutter => <<-HTML
30
- <td class="gutter">
31
- <pre>%s</pre>
32
- </td>
33
- HTML
34
- }
35
-
36
- def initialize(*args)
37
- super(*args)
38
- @opts[:gutter] = true if @opts[:gutter].nil?
39
- end
40
-
41
- private
42
- def highlight
43
- @str = @str.to_nokogiri_fragment
44
- @str.search("pre>code").each do |node|
45
- lang = node[:class] || node.parent[:lang] || @opts[:default] || "ruby"
46
- node.parent.replace(
47
- Templates[:wrap] % wrap(pygments(node.inner_text, lang), lang)
48
- )
49
- end
50
- end
51
-
52
- private
53
- def wrap(str, lang)
54
- lines, numbs = "", ""
55
-
56
- str.each_line.with_index(1) do |l, n|
57
- lines+= Templates[:line] % l
58
-
59
- if @opts[:gutter]
60
- numbs+= Templates[:numb] % n
61
- end
62
- end
63
-
64
- if ! @opts[:gutter]
65
- [
66
- numbs, lang, lines
67
- ]
68
- else
69
- [
70
- Templates[:gutter] % numbs, lang, lines
71
- ]
72
- end
73
- end
74
-
75
- private
76
- def pygments(str, lang)
77
- return str if jruby? || ! Pygments::Lexer[lang]
78
- Pygments::Lexer[lang].highlight(str) =~ Matcher ? $1 : str
79
- end
80
- end