History

Merge pull request #1393 from MasterEnoc/chef

Add Chef version 16

Simon Legner committed 5 years ago

Commit e2f1e202 parents 2313e7a 3797d9e5 files · +177 −81Browse files

Unified · Split

5 files
  1. lib/docs/filters/chef/clean_html.rb +11 −20
  2. lib/docs/filters/chef/clean_html_old.rb +37 −0
  3. lib/docs/filters/chef/entries.rb +19 −53
  4. lib/docs/filters/chef/entries_old.rb +68 −0
  5. lib/docs/scrapers/chef.rb +42 −8
lib/docs/filters/chef/clean_html.rb+11−20
@@ -2,33 +2,24 @@ module Docs · 1 unmodified line
2 class Chef2 class Chef
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 @doc = at_css('div[role="main"]')5 @doc = at_css('#main-content-col')
6 6
7 css('.headerlink').remove7 if root_page?
8 8 css('img').remove
9 css('em', 'div.align-center', 'a[href$=".svg"]').each do |node|
10 node.before(node.children).remove
11 end9 end
12 10
13 css('.section').each do |node|11 css('pre').each do |node|
14 node.first_element_child['id'] = node['id'] if node['id']12 node.remove_attribute('style')
15 node.before(node.children).remove
16 end
17 13
18 css('tt').each do |node|14 if !(node.classes.include?('highlight'))
19 node.content = node.content.strip15 node.add_class('highlight')
20 node.name = 'code'16 node['data-language'] = 'ruby'
17 end
21 end18 end
22 19
23 css('table[border]').each do |node|20 css('#feedback').remove
24 node.remove_attribute('border')
25 end
26 21
27 css('div[class*="highlight-"]').each do |node|22 css('.mini-toc-header', '.TOC-button').remove
28 node.content = node.content.strip
29 node.name = 'pre'
30 node['data-language'] = node['class'][/highlight\-(\w+)/, 1]
31 end
32 23
33 doc24 doc
34 end25 end
lib/docs/filters/chef/clean_html_old.rb+37−0
@@ -0,0 +1,37 @@
1module Docs
2 class Chef
3 class CleanHtmlOldFilter < Filter
4 def call
5 @doc = at_css('div[role="main"]')
6
7 css('.headerlink').remove
8
9 css('em', 'div.align-center', 'a[href$=".svg"]').each do |node|
10 node.before(node.children).remove
11 end
12
13 css('.section').each do |node|
14 node.first_element_child['id'] = node['id'] if node['id']
15 node.before(node.children).remove
16 end
17
18 css('tt').each do |node|
19 node.content = node.content.strip
20 node.name = 'code'
21 end
22
23 css('table[border]').each do |node|
24 node.remove_attribute('border')
25 end
26
27 css('div[class*="highlight-"]').each do |node|
28 node.content = node.content.strip
29 node.name = 'pre'
30 node['data-language'] = node['class'][/highlight\-(\w+)/, 1]
31 end
32
33 doc
34 end
35 end
36 end
37end
lib/docs/filters/chef/entries.rb+19−53
@@ -1,68 +1,34 @@
1module Docs1module Docs
2 class Chef2 class Chef
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4
4 def get_name5 def get_name
5 name = at_css('.body h1').content6 at_css('h1').content
6 name.remove! "\u{00b6}"
7 name.remove! 'About the '
8 name.remove! 'About '
9 name
10 end7 end
11 8
12 CLIENT_TYPE_BY_SLUG_END_WITH = {
13 'knife_common_options' => 'Workflow Tools',
14 'knife_using' => 'Workflow Tools',
15 'resource_common' => 'Cookbooks',
16 'config_rb_knife_optional_settings' => 'Workflow Tools',
17 'knife_index_rebuild' => 'Workflow Tools',
18 'handlers' => 'Extend Chef',
19 'dsl_recipe' => 'Extend Chef',
20 'resource' => 'Extend Chef'
21 }
22
23 SERVER_TYPE_BY_SLUG_END_WITH = {
24 'auth' => 'Theory & Concepts',
25 'install_server' => 'Setup & Config',
26 'install_server_pre' => 'Setup & Config',
27 'config_rb_server_optional_settings' => 'Manage the Server',
28 'ctl_chef_server' => 'Manage the Server'
29 }
30
31 def get_type9 def get_type
32 if server_page?10
33 SERVER_TYPE_BY_SLUG_END_WITH.each do |key, value|11 case slug
34 return "Chef Server / #{value}" if slug.end_with?(key)12 when /automate/
35 end13 'Chef Automate'
14 when /compliance/
15 'Chef Compliance'
16 when /desktop/
17 'Chef Desktop'
18 when /habitat/
19 'Chef Habitat'
20 when /inspec/
21 'Chef InSpec'
22 when /workstation/
23 'Chef Workstation'
24 when /effortless/
25 'Effortless Pattern'
36 else26 else
37 CLIENT_TYPE_BY_SLUG_END_WITH.each do |key, value|27 'Chef Infra'
38 return value if slug.end_with?(key)
39 end
40 end28 end
41 29
42 path = nav_path
43 path.delete('Reference')
44 path = path[0..0]
45 path.unshift('Chef Server') if server_page?
46
47 type = path.join(' / ')
48 type.sub 'Cookbooks / Cookbook', 'Cookbooks /'
49 type
50 end30 end
51 31
52 def server_page?
53 slug.start_with?(context[:server_path])
54 end
55
56 def nav_path
57 node = at_css(".nav-docs a[href='#{result[:path].split('/').last}']")
58 path = []
59 until node['class'] && node['class'].include?('main-item')
60 path.unshift(node.first_element_child.content.strip) if node['class'] && node['class'].include?('has-sub-items')
61 node = node.parent
62 end
63 path.unshift(node.first_element_child.content.strip)
64 path
65 end
66 end32 end
67 end33 end
68end34end
lib/docs/filters/chef/entries_old.rb+68−0
@@ -0,0 +1,68 @@
1module Docs
2 class Chef
3 class EntriesOldFilter < Docs::EntriesFilter
4 def get_name
5 name = at_css('.body h1').content
6 name.remove! "\u{00b6}"
7 name.remove! 'About the '
8 name.remove! 'About '
9 name
10 end
11
12 CLIENT_TYPE_BY_SLUG_END_WITH = {
13 'knife_common_options' => 'Workflow Tools',
14 'knife_using' => 'Workflow Tools',
15 'resource_common' => 'Cookbooks',
16 'config_rb_knife_optional_settings' => 'Workflow Tools',
17 'knife_index_rebuild' => 'Workflow Tools',
18 'handlers' => 'Extend Chef',
19 'dsl_recipe' => 'Extend Chef',
20 'resource' => 'Extend Chef'
21 }
22
23 SERVER_TYPE_BY_SLUG_END_WITH = {
24 'auth' => 'Theory & Concepts',
25 'install_server' => 'Setup & Config',
26 'install_server_pre' => 'Setup & Config',
27 'config_rb_server_optional_settings' => 'Manage the Server',
28 'ctl_chef_server' => 'Manage the Server'
29 }
30
31 def get_type
32 if server_page?
33 SERVER_TYPE_BY_SLUG_END_WITH.each do |key, value|
34 return "Chef Server / #{value}" if slug.end_with?(key)
35 end
36 else
37 CLIENT_TYPE_BY_SLUG_END_WITH.each do |key, value|
38 return value if slug.end_with?(key)
39 end
40 end
41
42 path = nav_path
43 path.delete('Reference')
44 path = path[0..0]
45 path.unshift('Chef Server') if server_page?
46
47 type = path.join(' / ')
48 type.sub 'Cookbooks / Cookbook', 'Cookbooks /'
49 type
50 end
51
52 def server_page?
53 slug.start_with?(context[:server_path])
54 end
55
56 def nav_path
57 node = at_css(".nav-docs a[href='#{result[:path].split('/').last}']")
58 path = []
59 until node['class'] && node['class'].include?('main-item')
60 path.unshift(node.first_element_child.content.strip) if node['class'] && node['class'].include?('has-sub-items')
61 node = node.parent
62 end
63 path.unshift(node.first_element_child.content.strip)
64 path
65 end
66 end
67 end
68end
lib/docs/scrapers/chef.rb+42−8
@@ -1,20 +1,16 @@
1module Docs1module Docs
2 class Chef < UrlScraper2 class Chef < UrlScraper
3 self.type = 'sphinx_simple'3 self.type = 'sphinx_simple'
4 self.base_url = 'https://docs-archive.chef.io/release/'4 self.base_url = 'https://docs.chef.io'
5 self.links = {5 self.links = {
6 home: 'https://www.chef.io/',6 home: 'https://www.chef.io/',
7 code: 'https://github.com/chef/chef'7 code: 'https://github.com/chef/chef'
8 }8 }
9 9
10 html_filters.push 'chef/entries', 'chef/clean_html'
11
12 options[:skip_patterns] = [10 options[:skip_patterns] = [
13 /\A[^\/]+\/\z/,11 /release_notes/,
14 /\A[^\/]+\/index\.html\z/,12 /feedback/
15 /\A[^\/]+\/release_notes\.html\z/,13 ]
16 /\Aserver[^\/]+\/chef_overview\.html\z/,
17 /\A[\d\-]+\/server_components\.html\z/ ]
18 14
19 options[:attribution] = <<-HTML15 options[:attribution] = <<-HTML
20 &copy; Chef Software, Inc.<br>16 &copy; Chef Software, Inc.<br>
@@ -24,12 +20,38 @@ module Docs · 3 unmodified lines
24 We are not affiliated with, endorsed or sponsored by Chef Inc.20 We are not affiliated with, endorsed or sponsored by Chef Inc.
25 HTML21 HTML
26 22
23 version '16' do
24 self.release = '16.7.61'
25
26 options[:container] = '.off-canvas-wrapper'
27
28 options[:skip] = [
29 '/automate/api/',
30 '/habitat/supervisor_api/',
31 '/habitat/builder_api/'
32 ]
33
34 html_filters.push 'chef/entries', 'chef/clean_html'
35
36 end
37
27 version '12' do38 version '12' do
28 self.release = '12.13'39 self.release = '12.13'
40 self.base_url = 'https://docs-archive.chef.io/release/'
41
42 html_filters.push 'chef/entries_old', 'chef/clean_html_old'
29 43
30 options[:client_path] = client_path = '12-13'44 options[:client_path] = client_path = '12-13'
31 options[:server_path] = server_path = 'server_12-8'45 options[:server_path] = server_path = 'server_12-8'
32 46
47 options[:skip_patterns] = [
48 /\A[^\/]+\/\z/,
49 /\A[^\/]+\/index\.html\z/,
50 /\A[^\/]+\/release_notes\.html\z/,
51 /\Aserver[^\/]+\/chef_overview\.html\z/,
52 /\A[\d\-]+\/server_components\.html\z/
53 ]
54
33 self.root_path = "#{client_path}/chef_overview.html"55 self.root_path = "#{client_path}/chef_overview.html"
34 self.initial_paths = ["#{server_path}/server_components.html"]56 self.initial_paths = ["#{server_path}/server_components.html"]
35 57
@@ -38,10 +60,21 @@ module Docs · 2 unmodified lines
38 60
39 version '11' do61 version '11' do
40 self.release = '11.18'62 self.release = '11.18'
63 self.base_url = 'https://docs-archive.chef.io/release/'
64
65 html_filters.push 'chef/entries_old', 'chef/clean_html_old'
41 66
42 options[:client_path] = client_path = '11-18'67 options[:client_path] = client_path = '11-18'
43 options[:server_path] = server_path = 'server_12-8'68 options[:server_path] = server_path = 'server_12-8'
44 69
70 options[:skip_patterns] = [
71 /\A[^\/]+\/\z/,
72 /\A[^\/]+\/index\.html\z/,
73 /\A[^\/]+\/release_notes\.html\z/,
74 /\Aserver[^\/]+\/chef_overview\.html\z/,
75 /\A[\d\-]+\/server_components\.html\z/
76 ]
77
45 self.root_path = "#{client_path}/chef_overview.html"78 self.root_path = "#{client_path}/chef_overview.html"
46 self.initial_paths = ["#{server_path}/server_components.html"]79 self.initial_paths = ["#{server_path}/server_components.html"]
47 80
@@ -52,5 +85,6 @@ module Docs · 4 unmodified lines
52 doc = fetch_doc('https://downloads.chef.io/products/infra', opts)85 doc = fetch_doc('https://downloads.chef.io/products/infra', opts)
53 doc.at_css('#versions > option').content.strip86 doc.at_css('#versions > option').content.strip
54 end87 end
88
55 end89 end
56end90end