History

Convert the `decode_cloudflare_email` helper to a dedicated filter class

Jed Fox committed 9 years ago

Commit 608853b1 parent 68b80bc17 files · +29 −49Browse files

Unified · Split

17 files
  1. lib/docs/core/filter.rb +0 −11
  2. lib/docs/filters/ansible/clean_html.rb +0 −4
  3. lib/docs/filters/bootstrap/clean_html_v3.rb +0 −4
  4. lib/docs/filters/bootstrap/clean_html_v4.rb +0 −4
  5. lib/docs/filters/core/parse_cf_email.rb +21 −0
  6. lib/docs/filters/flow/clean_html.rb +0 −4
  7. lib/docs/filters/laravel/clean_html.rb +0 −4
  8. lib/docs/filters/node/clean_html.rb +0 −4
  9. lib/docs/filters/vue/clean_html.rb +0 −4
  10. lib/docs/filters/yarn/clean_html.rb +0 −4
  11. lib/docs/scrapers/ansible.rb +1 −1
  12. lib/docs/scrapers/bootstrap.rb +2 −0
  13. lib/docs/scrapers/flow.rb +1 −1
  14. lib/docs/scrapers/laravel.rb +1 −1
  15. lib/docs/scrapers/node.rb +1 −1
  16. lib/docs/scrapers/vue.rb +1 −1
  17. lib/docs/scrapers/yarn.rb +1 −1
lib/docs/core/filter.rb+0−11
@@ -91,17 +91,6 @@ module Docs · 90 unmodified lines
91 super91 super
92 end92 end
93 93
94 def decode_cloudflare_email(str)
95 mask = "0x#{str[0..1]}".hex | 0
96 result = ''
97
98 str.chars.drop(2).each_slice(2) do |slice|
99 result += "%" + "0#{("0x#{slice.join}".hex ^ mask).to_s(16)}"[-2..-1]
100 end
101
102 URI.decode(result)
103 end
104
105 def clean_path(path)94 def clean_path(path)
106 path = path.gsub %r{[!;:]}, '-'95 path = path.gsub %r{[!;:]}, '-'
107 path = path.gsub %r{\+}, '_plus_'96 path = path.gsub %r{\+}, '_plus_'
lib/docs/filters/ansible/clean_html.rb+0−4
@@ -4,10 +4,6 @@ module Docs · 3 unmodified lines
4 def call4 def call
5 @doc = at_css('#page-content')5 @doc = at_css('#page-content')
6 6
7 css('.__cf_email__').each do |node|
8 node.replace(decode_cloudflare_email(node['data-cfemail']))
9 end
10
11 doc7 doc
12 end8 end
13 end9 end
lib/docs/filters/bootstrap/clean_html_v3.rb+0−4
@@ -39,10 +39,6 @@ module Docs · 38 unmodified lines
39 node['class'] = 'col'39 node['class'] = 'col'
40 end40 end
41 41
42 css('.__cf_email__').each do |node|
43 node.replace(decode_cloudflare_email(node['data-cfemail']))
44 end
45
46 css('figure.highlight').each do |node|42 css('figure.highlight').each do |node|
47 code = node.at_css('code')43 code = node.at_css('code')
48 node['data-language'] = code['data-lang']44 node['data-language'] = code['data-lang']
lib/docs/filters/bootstrap/clean_html_v4.rb+0−4
@@ -40,10 +40,6 @@ module Docs · 39 unmodified lines
40 node['class'] = 'col'40 node['class'] = 'col'
41 end41 end
42 42
43 css('.__cf_email__').each do |node|
44 node.replace(decode_cloudflare_email(node['data-cfemail']))
45 end
46
47 css('.highlight').each do |node|43 css('.highlight').each do |node|
48 code = node.at_css('code')44 code = node.at_css('code')
49 node['data-language'] = code['data-lang']45 node['data-language'] = code['data-lang']
lib/docs/filters/core/parse_cf_email.rb+21−0
@@ -0,0 +1,21 @@
1# frozen_string_literal: true
2
3module Docs
4 class ParseCfEmailFilter < Filter
5 def call
6 css('.__cf_email__').each do |node|
7 str = node['data-cfemail']
8 mask = "0x#{str[0..1]}".hex | 0
9 result = ''
10
11 str.chars.drop(2).each_slice(2) do |slice|
12 result += "%" + "0#{("0x#{slice.join}".hex ^ mask).to_s(16)}"[-2..-1]
13 end
14
15 node.replace(URI.decode(result))
16 end
17
18 doc
19 end
20 end
21end
lib/docs/filters/flow/clean_html.rb+0−4
@@ -45,10 +45,6 @@ module Docs · 44 unmodified lines
45 end45 end
46 end46 end
47 47
48 css('.__cf_email__').each do |node|
49 node.replace(decode_cloudflare_email(node['data-cfemail']))
50 end
51
52 css('.editor').each do |node|48 css('.editor').each do |node|
53 pre = node.at_css('.editor-code > pre')49 pre = node.at_css('.editor-code > pre')
54 pre['data-language'] = 'javascript'50 pre['data-language'] = 'javascript'
lib/docs/filters/laravel/clean_html.rb+0−4
@@ -8,10 +8,6 @@ module Docs · 7 unmodified lines
8 other8 other
9 end9 end
10 10
11 css('a.__cf_email__').each do |node|
12 node.replace(decode_cloudflare_email(node['data-cfemail']))
13 end
14
15 # Remove code highlighting11 # Remove code highlighting
16 css('pre').each do |node|12 css('pre').each do |node|
17 node.content = node.content13 node.content = node.content
lib/docs/filters/node/clean_html.rb+0−4
@@ -22,10 +22,6 @@ module Docs · 21 unmodified lines
22 node.content = node.content22 node.content = node.content
23 end23 end
24 24
25 css('.__cf_email__').each do |node|
26 node.replace(decode_cloudflare_email(node['data-cfemail']))
27 end
28
29 doc25 doc
30 end26 end
31 end27 end
lib/docs/filters/vue/clean_html.rb+0−4
@@ -9,10 +9,6 @@ module Docs · 8 unmodified lines
9 9
10 css('.demo', '.guide-links', '.footer', '#ad').remove10 css('.demo', '.guide-links', '.footer', '#ad').remove
11 11
12 css('.__cf_email__').each do |node|
13 node.replace(decode_cloudflare_email(node['data-cfemail']))
14 end
15
16 # Remove code highlighting12 # Remove code highlighting
17 css('figure').each do |node|13 css('figure').each do |node|
18 node.name = 'pre'14 node.name = 'pre'
lib/docs/filters/yarn/clean_html.rb+0−4
@@ -43,10 +43,6 @@ module Docs · 42 unmodified lines
43 end43 end
44 end44 end
45 45
46 css('.__cf_email__').each do |node|
47 node.replace(decode_cloudflare_email(node['data-cfemail']))
48 end
49
50 css('div.highlighter-rouge').each do |node|46 css('div.highlighter-rouge').each do |node|
51 node['data-language'] = node['class'][/language-(\w+)/, 1] if node['class']47 node['data-language'] = node['class'][/language-(\w+)/, 1] if node['class']
52 node.content = node.content.strip48 node.content = node.content.strip
lib/docs/scrapers/ansible.rb+1−1
@@ -7,7 +7,7 @@ module Docs · 6 unmodified lines
7 code: 'https://github.com/ansible/ansible'7 code: 'https://github.com/ansible/ansible'
8 }8 }
9 9
10 html_filters.push 'ansible/entries', 'ansible/clean_html', 'sphinx/clean_html'10 html_filters.push 'ansible/entries', 'sphinx/clean_html', 'parse_cf_email'
11 11
12 options[:skip] = %w(12 options[:skip] = %w(
13 glossary.html13 glossary.html
lib/docs/scrapers/bootstrap.rb+2−0
@@ -15,6 +15,8 @@ module Docs · 14 unmodified lines
15 Documentation licensed under the Creative Commons Attribution License v3.0.15 Documentation licensed under the Creative Commons Attribution License v3.0.
16 HTML16 HTML
17 17
18 html_filters.push 'parse_cf_email'
19
18 version '4' do20 version '4' do
19 self.release = '4.0.0'21 self.release = '4.0.0'
20 self.base_url = 'https://getbootstrap.com/docs/4.0/'22 self.base_url = 'https://getbootstrap.com/docs/4.0/'
lib/docs/scrapers/flow.rb+1−1
@@ -8,7 +8,7 @@ module Docs · 7 unmodified lines
8 code: 'https://github.com/facebook/flow'8 code: 'https://github.com/facebook/flow'
9 }9 }
10 10
11 html_filters.push 'flow/entries', 'flow/clean_html', 'title'11 html_filters.push 'flow/entries', 'flow/clean_html', 'title', 'parse_cf_email'
12 12
13 options[:trailing_slash] = false13 options[:trailing_slash] = false
14 options[:root_title] = 'Flow'14 options[:root_title] = 'Flow'
lib/docs/scrapers/laravel.rb+1−1
@@ -7,7 +7,7 @@ module Docs · 6 unmodified lines
7 code: 'https://github.com/laravel/laravel'7 code: 'https://github.com/laravel/laravel'
8 }8 }
9 9
10 html_filters.push 'laravel/entries', 'laravel/clean_html'10 html_filters.push 'laravel/entries', 'laravel/clean_html', 'parse_cf_email'
11 11
12 options[:container] = ->(filter) {12 options[:container] = ->(filter) {
13 filter.subpath.start_with?('/api') ? '#content' : '.docs-wrapper'13 filter.subpath.start_with?('/api') ? '#content' : '.docs-wrapper'
lib/docs/scrapers/node.rb+1−1
@@ -8,7 +8,7 @@ module Docs · 7 unmodified lines
8 code: 'https://github.com/nodejs/node'8 code: 'https://github.com/nodejs/node'
9 }9 }
10 10
11 html_filters.push 'node/clean_html', 'node/entries', 'title'11 html_filters.push 'node/clean_html', 'node/entries', 'title', 'parse_cf_email'
12 12
13 options[:title] = false13 options[:title] = false
14 options[:root_title] = 'Node.js'14 options[:root_title] = 'Node.js'
lib/docs/scrapers/vue.rb+1−1
@@ -8,7 +8,7 @@ module Docs · 7 unmodified lines
8 code: 'https://github.com/vuejs/vue'8 code: 'https://github.com/vuejs/vue'
9 }9 }
10 10
11 html_filters.push 'vue/entries', 'vue/clean_html'11 html_filters.push 'vue/entries', 'vue/clean_html', 'parse_cf_email'
12 12
13 options[:only_patterns] = [/guide\//, /api\//]13 options[:only_patterns] = [/guide\//, /api\//]
14 options[:skip] = %w(guide/team.html)14 options[:skip] = %w(guide/team.html)
lib/docs/scrapers/yarn.rb+1−1
@@ -8,7 +8,7 @@ module Docs · 7 unmodified lines
8 code: 'https://github.com/yarnpkg/yarn'8 code: 'https://github.com/yarnpkg/yarn'
9 }9 }
10 10
11 html_filters.push 'yarn/entries', 'yarn/clean_html', 'title'11 html_filters.push 'yarn/entries', 'yarn/clean_html', 'title', 'parse_cf_email'
12 12
13 options[:root_title] = 'Yarn'13 options[:root_title] = 'Yarn'
14 options[:trailing_slash] = false14 options[:trailing_slash] = false