From 0948b5882ed140968d2545db63941ea16c6bf4a8 Mon Sep 17 00:00:00 2001 From: doertedev Date: Thu, 22 Oct 2015 13:43:31 +0200 Subject: [PATCH] Add Chef documentation --- assets/stylesheets/application-dark.css.scss | 1 + assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_chef.scss | 4 ++ lib/docs/filters/chef/clean_html.rb | 10 +++ lib/docs/filters/chef/entries.rb | 10 +++ lib/docs/filters/chefclient/clean_html.rb | 11 ++++ lib/docs/filters/chefclient/entries.rb | 63 +++++++++++++++++++ lib/docs/scrapers/chef.rb | 27 ++++++++ lib/docs/scrapers/chefclient.rb | 28 +++++++++ public/icons/docs/chef/16.png | Bin 0 -> 749 bytes public/icons/docs/chef/16@2x.png | Bin 0 -> 1600 bytes public/icons/docs/chef/SOURCE | 1 + 12 files changed, 156 insertions(+) create mode 100644 assets/stylesheets/pages/_chef.scss create mode 100644 lib/docs/filters/chef/clean_html.rb create mode 100644 lib/docs/filters/chef/entries.rb create mode 100644 lib/docs/filters/chefclient/clean_html.rb create mode 100644 lib/docs/filters/chefclient/entries.rb create mode 100644 lib/docs/scrapers/chef.rb create mode 100644 lib/docs/scrapers/chefclient.rb create mode 100644 public/icons/docs/chef/16.png create mode 100644 public/icons/docs/chef/16@2x.png create mode 100644 public/icons/docs/chef/SOURCE diff --git a/assets/stylesheets/application-dark.css.scss b/assets/stylesheets/application-dark.css.scss index c9e466e9..99cb1ada 100644 --- a/assets/stylesheets/application-dark.css.scss +++ b/assets/stylesheets/application-dark.css.scss @@ -35,6 +35,7 @@ 'pages/c', 'pages/cakephp', 'pages/chai', + 'pages/chef', 'pages/clojure', 'pages/coffeescript', 'pages/d3', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index 66a0e359..2352df26 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -35,6 +35,7 @@ 'pages/c', 'pages/cakephp', 'pages/chai', + 'pages/chef', 'pages/clojure', 'pages/coffeescript', 'pages/d3', diff --git a/assets/stylesheets/pages/_chef.scss b/assets/stylesheets/pages/_chef.scss new file mode 100644 index 00000000..42c15758 --- /dev/null +++ b/assets/stylesheets/pages/_chef.scss @@ -0,0 +1,4 @@ +._chef { + @extend %simple; + +} \ No newline at end of file diff --git a/lib/docs/filters/chef/clean_html.rb b/lib/docs/filters/chef/clean_html.rb new file mode 100644 index 00000000..5d79623b --- /dev/null +++ b/lib/docs/filters/chef/clean_html.rb @@ -0,0 +1,10 @@ +module Docs + class Chef + class CleanHtmlFilter < Filter + def call + css('h1 a', 'h2 a', 'h3 a','div.footer').remove + doc + end + end + end +end diff --git a/lib/docs/filters/chef/entries.rb b/lib/docs/filters/chef/entries.rb new file mode 100644 index 00000000..0c52fcf9 --- /dev/null +++ b/lib/docs/filters/chef/entries.rb @@ -0,0 +1,10 @@ +module Docs + class Chef + class EntriesFilter < Docs::EntriesFilter + def get_name + at_css('div.body h1 a').remove + at_css('div.body h1').content + end + end + end +end diff --git a/lib/docs/filters/chefclient/clean_html.rb b/lib/docs/filters/chefclient/clean_html.rb new file mode 100644 index 00000000..58726cc7 --- /dev/null +++ b/lib/docs/filters/chefclient/clean_html.rb @@ -0,0 +1,11 @@ +module Docs + class Chefclient + class CleanHtmlFilter < Filter + def call + css('h1 a, h2 a, h3 a').remove + doc = at_css('div.body[role="main"]') + doc + end + end + end +end diff --git a/lib/docs/filters/chefclient/entries.rb b/lib/docs/filters/chefclient/entries.rb new file mode 100644 index 00000000..af1f62f2 --- /dev/null +++ b/lib/docs/filters/chefclient/entries.rb @@ -0,0 +1,63 @@ +module Docs + class Chefclient + class EntriesFilter < Docs::EntriesFilter + + ADDITIONAL_URLS = [ + { + slug: 'knife_common_options', + type: 'Miscellaneous/Knife', + name: 'Common options' + }, + { + slug: 'knife_using', + type: 'Miscellaneous/Knife', + name: 'Using knife' + }, + { + slug: 'config_rb_knife_optional_settings', + type: 'Miscellaneous/Knife', + name: 'Optional settings' + }, + { + slug: 'resource_common', + name: 'About resources' + } + ] + + def get_name + ADDITIONAL_URLS.each do |url| + next unless slug == url[:slug] + return url[:name] + end + + css('.main-item a').map do |node| + next unless node.attributes['href'].to_s == slug + + return node.attributes['title'].to_s + end + #css('h1').try(:content) + return 'adsf' + end + + def get_type + ADDITIONAL_URLS.each do |url| + next unless slug == url[:slug] + next unless url[:type].nil? + return url[:type] + end + + css('.main-item a').map do |node| + next unless node.attributes['href'].to_s == slug + if node.ancestors('.sub-items')[0].attributes['class'].to_s.include? 'level-2' + level2 = node.ancestors('.sub-items')[0].previous_element['title'].to_s + level1 = node.ancestors('.sub-items')[0].ancestors('.sub-items')[0].previous_element['title'].to_s + return "#{level1}/#{level2}" + end + + return node.ancestors('.sub-items')[0].previous_element['title'].to_s + end + 'Miscellaneous' + end + end + end +end diff --git a/lib/docs/scrapers/chef.rb b/lib/docs/scrapers/chef.rb new file mode 100644 index 00000000..9ed4ae3c --- /dev/null +++ b/lib/docs/scrapers/chef.rb @@ -0,0 +1,27 @@ +module Docs + class Chef < UrlScraper + self.name = 'Chef' + self.slug = 'chef' + self.type = 'chef' + self.version = '12.5' + self.base_url = 'https://docs.chef.io/' + self.links = { + home: 'https://www.chef.io/', + docs: 'https://docs.chef.io/' + } + + html_filters.push 'chef/entries', 'chef/clean_html' + + options[:container] = '.bodywrapper' + + options[:only_patterns] = [/resource_.*.html/] + options[:skip_patterns] = [/resource_common\.html/] + + options[:trailing_slash] = false + + options[:attribution] = <<-HTML + © 2015 Chef Software, Inc.
+ Creative Commons Attribution 3.0 Unported License. + HTML + end +end diff --git a/lib/docs/scrapers/chefclient.rb b/lib/docs/scrapers/chefclient.rb new file mode 100644 index 00000000..8eff8b68 --- /dev/null +++ b/lib/docs/scrapers/chefclient.rb @@ -0,0 +1,28 @@ +module Docs + class Chefclient < UrlScraper + self.name = 'Chef Client' + self.slug = 'chefclient' + self.type = 'chefclient' + self.version = '12.5' + self.base_url = "https://docs.chef.io/release/#{version.sub '.', '-'}/" + self.links = { + home: 'https://www.chef.io/', + docs: 'https://docs.chef.io/' + } + + html_filters.push 'chefclient/entries', 'chefclient/clean_html' + + options[:fix_urls] = ->(url) do + url.remove! %r{/release/[0-9\-+]/} + url + end + + options[:skip_patterns] = [/_images\//] + options[:trailing_slash] = false + + options[:attribution] = <<-HTML + © 2015 Chef Software, Inc.
+ Creative Commons Attribution 3.0 Unported License. + HTML + end +end diff --git a/public/icons/docs/chef/16.png b/public/icons/docs/chef/16.png new file mode 100644 index 0000000000000000000000000000000000000000..e7792f94e32ee852d24fec54dc48a25c5289ddc1 GIT binary patch literal 749 zcmVeiR8bVifA7uc%s4vQB#nrsG^mp(NSYsI3!5-fu*e~jHZBH=h!*L9kwHsI zgO(x>T9~_6*@r>Jt2Ck7h?V6c!BHzUG{=vu8E4*YGXs;lXwh%=zn6Rd_ndprk%+R= znH!V#1X;f-1hwlCV``$TuK@Re4x7)v$|mHPu=)G|X~4H0zw1cNaD8^&>!ZEhldcj8 z>VYHxx5xXJfgvsfg9L%IqXz>cf%G+#tY?|zNcF_e)b_F+3ybNd-}x`BP3EDyJ)gGC zz${0^Y|wIUK4_UU8zO0HxhDF`25$gT%UFeTc_Z;mVaigk+vBa+V&L|8No<+X^V`R7 zMTGq2a^5?eEQ#}uwh13lBOy+_TFhuHNM1fIU}=kirYaovc(06JD<00atX0U8SW2<xnke2FUdY%f;KPP4?@y5R5wjtjd8hn& zlDTEtv26)4bRiioImc2ui{9qxLV9SBgxO*KW$7y&%nj-Cq0N0@WGmG`ztg%pe!J`? z0^Z83wI&0m(oSa0;l6UTW1;#U0%n zkz@0qsY)n%APh7Bd*goU7*G{mJKP>`8&IdI3Pzya?eR_nL7)(@01A*94KM+%(P=CI f7Bp4qh`qrdYOUhSj$eeM00000NkvXXu0mjf`)yMc literal 0 HcmV?d00001 diff --git a/public/icons/docs/chef/16@2x.png b/public/icons/docs/chef/16@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..5c8d5c30a8fabd1bf4a66ade007e04c4f126fd66 GIT bin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