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
22 class Chef
33 class CleanHtmlFilter < Filter
44 def call
5− @doc = at_css('div[role="main"]')
5+ @doc = at_css('#main-content-col')
66
7− css('.headerlink').remove
8−
9− css('em', 'div.align-center', 'a[href$=".svg"]').each do |node|
10− node.before(node.children).remove
7+ if root_page?
8+ css('img').remove
119 end
1210
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
11+ css('pre').each do |node|
12+ node.remove_attribute('style')
1713
18− css('tt').each do |node|
19− node.content = node.content.strip
20− node.name = 'code'
14+ if !(node.classes.include?('highlight'))
15+ node.add_class('highlight')
16+ node['data-language'] = 'ruby'
17+ end
2118 end
2219
23− css('table[border]').each do |node|
24− node.remove_attribute('border')
25− end
20+ css('#feedback').remove
2621
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
22+ css('.mini-toc-header', '.TOC-button').remove
3223
3324 doc
3425 end
lib/docs/filters/chef/clean_html_old.rb+37−0
@@ -0,0 +1,37 @@
1+module 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
37+end
lib/docs/filters/chef/entries.rb+19−53
@@ -1,68 +1,34 @@
11 module Docs
22 class Chef
33 class EntriesFilter < Docs::EntriesFilter
4+
45 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
6+ at_css('h1').content
107 end
118
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−
319 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
10+
11+ case slug
12+ when /automate/
13+ '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'
3626 else
37− CLIENT_TYPE_BY_SLUG_END_WITH.each do |key, value|
38− return value if slug.end_with?(key)
39− end
27+ 'Chef Infra'
4028 end
4129
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
5030 end
5131
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
6632 end
6733 end
6834 end
lib/docs/filters/chef/entries_old.rb+68−0
@@ -0,0 +1,68 @@
1+module 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
68+end
lib/docs/scrapers/chef.rb+42−8
@@ -1,20 +1,16 @@
11 module Docs
22 class Chef < UrlScraper
33 self.type = 'sphinx_simple'
4− self.base_url = 'https://docs-archive.chef.io/release/'
4+ self.base_url = 'https://docs.chef.io'
55 self.links = {
66 home: 'https://www.chef.io/',
77 code: 'https://github.com/chef/chef'
88 }
99
10− html_filters.push 'chef/entries', 'chef/clean_html'
11−
1210 options[:skip_patterns] = [
13− /\A[^\/]+\/\z/,
14− /\A[^\/]+\/index\.html\z/,
15− /\A[^\/]+\/release_notes\.html\z/,
16− /\Aserver[^\/]+\/chef_overview\.html\z/,
17− /\A[\d\-]+\/server_components\.html\z/ ]
11+ /release_notes/,
12+ /feedback/
13+ ]
1814
1915 options[:attribution] = <<-HTML
2016 &copy; Chef Software, Inc.<br>
@@ -24,12 +20,38 @@ module Docs · 3 unmodified lines
2420 We are not affiliated with, endorsed or sponsored by Chef Inc.
2521 HTML
2622
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+
2738 version '12' do
2839 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'
2943
3044 options[:client_path] = client_path = '12-13'
3145 options[:server_path] = server_path = 'server_12-8'
3246
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+
3355 self.root_path = "#{client_path}/chef_overview.html"
3456 self.initial_paths = ["#{server_path}/server_components.html"]
3557
@@ -38,10 +60,21 @@ module Docs · 2 unmodified lines
3860
3961 version '11' do
4062 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'
4166
4267 options[:client_path] = client_path = '11-18'
4368 options[:server_path] = server_path = 'server_12-8'
4469
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+
4578 self.root_path = "#{client_path}/chef_overview.html"
4679 self.initial_paths = ["#{server_path}/server_components.html"]
4780
@@ -52,5 +85,6 @@ module Docs · 4 unmodified lines
5285 doc = fetch_doc('https://downloads.chef.io/products/infra', opts)
5386 doc.at_css('#versions > option').content.strip
5487 end
88+
5589 end
5690 end