Jelajahi Sumber

Finish Chef documentation

Thibaut Courouble 9 tahun lalu
induk
melakukan
1fa82430b0

TEMPAT SAMPAH
assets/images/icons.png


TEMPAT SAMPAH
assets/images/icons@2x.png


+ 2 - 2
assets/javascripts/news.json

@@ -1,7 +1,7 @@
 [
   [
-    "2016-02-14",
-    "New documentation: <a href=\"/cakephp/\">CakePHP</a>"
+    "2016-02-15",
+    "New documentations: <a href=\"/cakephp/\">CakePHP</a> and <a href=\"/chef/\">Chef</a>"
   ], [
     "2016-01-31",
     "New documentations: <a href=\"/erlang/\">Erlang</a> and <a href=\"/tcl_tk/\">Tcl/Tk</a>"

+ 5 - 0
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -109,6 +109,11 @@ credits = [
     '2011-2015 Jake Luer',
     'MIT',
     'https://github.com/chaijs/chai/blob/master/README.md#license'
+  ], [
+    'Chef&trade;',
+    'Chef Software, Inc.',
+    'CC BY',
+    'https://raw.githubusercontent.com/chef/chef-web-docs-2016/master/LICENSE'
   ], [
     'Clojure',
     'Rich Hickey',

+ 7 - 0
assets/javascripts/views/pages/sphinx_simple.coffee

@@ -0,0 +1,7 @@
+#= require views/pages/base
+
+class app.views.SphinxSimplePage extends app.views.BasePage
+  prepare: ->
+    @highlightCode @findAll('pre.highlight-ruby'), 'ruby'
+    @highlightCode @findAll('pre.highlight-javascript'), 'javascript'
+    return

+ 1 - 2
assets/stylesheets/application-dark.css.scss

@@ -35,7 +35,6 @@
         'pages/c',
         'pages/cakephp',
         'pages/chai',
-        'pages/chef',
         'pages/clojure',
         'pages/coffeescript',
         'pages/d3',
@@ -59,7 +58,6 @@
         'pages/nginx',
         'pages/node',
         'pages/npm',
-        'pages/opentsdb',
         'pages/phalcon',
         'pages/phaser',
         'pages/php',
@@ -75,6 +73,7 @@
         'pages/rust',
         'pages/socketio',
         'pages/sphinx',
+        'pages/sphinx_simple',
         'pages/tcl_tk',
         'pages/underscore',
         'pages/vagrant',

+ 1 - 2
assets/stylesheets/application.css.scss

@@ -35,7 +35,6 @@
         'pages/c',
         'pages/cakephp',
         'pages/chai',
-        'pages/chef',
         'pages/clojure',
         'pages/coffeescript',
         'pages/d3',
@@ -59,7 +58,6 @@
         'pages/nginx',
         'pages/node',
         'pages/npm',
-        'pages/opentsdb',
         'pages/phalcon',
         'pages/phaser',
         'pages/php',
@@ -75,6 +73,7 @@
         'pages/rust',
         'pages/socketio',
         'pages/sphinx',
+        'pages/sphinx_simple',
         'pages/tcl_tk',
         'pages/underscore',
         'pages/vagrant',

+ 1 - 0
assets/stylesheets/global/_icons.scss

@@ -124,3 +124,4 @@
 ._icon-phoenix:before       { background-position: -9rem -9rem; }
 ._icon-tcl_tk:before        { background-position: 0 -10rem; }
 ._icon-erlang:before        { background-position: -1rem -10rem; }
+._icon-chef:before          { background-position: -2rem -10rem; }

+ 5 - 1
assets/stylesheets/pages/_chef.scss

@@ -1,4 +1,8 @@
 ._chef {
   @extend %simple;
 
-}
+  .note, .warning { @extend %note; }
+  .warning { @extend %note, %note-red; }
+
+  code { @extend %label; }
+}

+ 3 - 1
assets/stylesheets/pages/_opentsdb.scss → assets/stylesheets/pages/_sphinx_simple.scss

@@ -1,4 +1,4 @@
-._opentsdb {
+._sphinx_simple {
   @extend %simple;
 
   .admonition { @extend %note; }
@@ -7,4 +7,6 @@
     margin: 0 0 .25rem;
     font-weight: bold;
   }
+
+  code { @extend %label; }
 }

+ 1 - 1
lib/docs/core/response.rb

@@ -5,7 +5,7 @@ module Docs
     end
 
     def error?
-      code != 404 && code >= 400 && code <= 599
+      code != 404 && code != 403 && code >= 400 && code <= 599
     end
 
     def empty?

+ 1 - 0
lib/docs/core/scraper.rb

@@ -13,6 +13,7 @@ module Docs
           autoload_all "docs/filters/#{to_s.demodulize.underscore}", 'filter'
         end
 
+        subclass.base_url = base_url
         subclass.root_path = root_path
         subclass.initial_paths = initial_paths.dup
         subclass.options = options.deep_dup

+ 27 - 1
lib/docs/filters/chef/clean_html.rb

@@ -2,7 +2,33 @@ module Docs
   class Chef
     class CleanHtmlFilter < Filter
       def call
-        css('h1 a', 'h2 a', 'h3 a','div.footer').remove
+        @doc = at_css('div[role="main"]')
+
+        css('.headerlink').remove
+
+        css('em', 'div.align-center', 'a[href$=".svg"]').each do |node|
+          node.before(node.children).remove
+        end
+
+        css('.section').each do |node|
+          node.first_element_child['id'] = node['id'] if node['id']
+          node.before(node.children).remove
+        end
+
+        css('tt').each do |node|
+          node.content = node.content.strip
+          node.name = 'code'
+        end
+
+        css('table[border]').each do |node|
+          node.remove_attribute('border')
+        end
+
+        css('div[class^="highlight-"]').each do |node|
+          node.content = node.content.strip
+          node.name = 'pre'
+        end
+
         doc
       end
     end

+ 54 - 2
lib/docs/filters/chef/entries.rb

@@ -2,8 +2,60 @@ module Docs
   class Chef
     class EntriesFilter < Docs::EntriesFilter
       def get_name
-        at_css('div.body h1 a').remove
-        at_css('div.body h1').content
+        name = at_css('.body h1').content
+        name.remove! "\u{00b6}"
+        name.remove! 'About the '
+        name.remove! 'About '
+        name
+      end
+
+      CLIENT_TYPE_BY_SLUG_END_WITH = {
+        'knife_common_options'               => 'Knife Commands',
+        'knife_using'                        => 'Knife Commands',
+        'resource_common'                    => 'Chef Resources',
+        'config_rb_knife_optional_settings'  => 'Config Files'
+      }
+
+      SERVER_TYPE_BY_SLUG_END_WITH = {
+        'auth'                               => 'Theory & Concepts',
+        'install_server_pre'                 => 'Setup & Config',
+        'config_rb_server_optional_settings' => 'Config Files'
+      }
+
+      def get_type
+        if server_page?
+          SERVER_TYPE_BY_SLUG_END_WITH.each do |key, value|
+            return "Chef Server / #{value}" if slug.end_with?(key)
+          end
+        else
+          CLIENT_TYPE_BY_SLUG_END_WITH.each do |key, value|
+            return value if slug.end_with?(key)
+          end
+        end
+
+        path = nav_path
+        path.delete('Reference')
+        path = path[0..0]
+        path.unshift('Chef Server') if server_page?
+
+        type = path.join(' / ')
+        type.sub 'Cookbooks / Cookbook', 'Cookbooks /'
+        type
+      end
+
+      def server_page?
+        slug.start_with?(context[:server_path])
+      end
+
+      def nav_path
+        node = at_css(".nav-docs a[href='#{result[:path].split('/').last}']")
+        path = []
+        until node['class'] && node['class'].include?('main-item')
+          path.unshift(node.first_element_child.content.strip) if node['class'] && node['class'].include?('has-sub-items')
+          node = node.parent
+        end
+        path.unshift(node.first_element_child.content.strip)
+        path
       end
     end
   end

+ 37 - 14
lib/docs/scrapers/chef.rb

@@ -1,27 +1,50 @@
 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.type = 'sphinx_simple'
+    self.base_url = 'https://docs.chef.io/release/'
     self.links = {
       home: 'https://www.chef.io/',
-      docs: 'https://docs.chef.io/'
+      code: 'https://github.com/chef/chef'
     }
 
     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[:skip_patterns] = [
+      /\A[^\/]+\/\z/,
+      /\A[^\/]+\/index\.html\z/,
+      /\A[^\/]+\/release_notes\.html\z/,
+      /\Aserver[^\/]+\/chef_overview\.html\z/ ]
 
     options[:attribution] = <<-HTML
-      &copy; 2015 Chef Software, Inc.<br>
-      Creative Commons Attribution 3.0 Unported License.
+      &copy; Chef Software, Inc.<br>
+      Licensed under the Creative Commons Attribution 3.0 Unported License.<br>
+      The Chef&trade; Mark and Chef Logo are either registered trademarks/service marks or trademarks/service
+      marks of Chef, in the United States and other countries and are used with Chef Inc's permission.<br>
+      We are not affiliated with, endorsed or sponsored by Chef Inc.
     HTML
+
+    version '12' do
+      self.release = '12.7'
+
+      options[:client_path] = client_path = '12-7'
+      options[:server_path] = server_path = 'server_12-4'
+
+      self.root_path = "#{client_path}/chef_overview.html"
+      self.initial_paths = ["#{server_path}/server_components.html"]
+
+      options[:only_patterns] = [/\A#{client_path}\//, /\A#{server_path}\//]
+    end
+
+    version '11' do
+      self.release = '11.18'
+
+      options[:client_path] = client_path = '11-18'
+      options[:server_path] = server_path = 'server_12-4'
+
+      self.root_path = "#{client_path}/chef_overview.html"
+      self.initial_paths = ["#{server_path}/server_components.html"]
+
+      options[:only_patterns] = [/\A#{client_path}\//, /\A#{server_path}\//]
+    end
   end
 end

TEMPAT SAMPAH
public/icons/docs/chef/16.png


TEMPAT SAMPAH
public/icons/docs/chef/16@2x.png


+ 1 - 1
public/icons/docs/chef/SOURCE

@@ -1 +1 @@
-http://style.chef.io/assets/images/downloads/Chef_Regular.png
+https://www.chef.io/