Преглед изворни кода

Update and improve RethinkDB documentation

Thibaut Courouble пре 9 година
родитељ
комит
c0179b22ac

BIN
assets/images/docs.png


BIN
assets/images/docs@2x.png


+ 3 - 2
assets/stylesheets/pages/_rethinkdb.scss

@@ -1,6 +1,7 @@
 ._rethinkdb {
-  > h2 { @extend %block-heading; }
-  code { @extend %label; }
+  @extend %simple;
+
+  .infobox-alert { @extend %note-orange; }
 
   .api_command_illustration {
     float: right;

+ 17 - 6
lib/docs/filters/rethinkdb/clean_html.rb

@@ -2,16 +2,13 @@ module Docs
   class Rethinkdb
     class CleanHtmlFilter < Filter
       def call
-        if root_page?
-          doc.inner_html = '<h1>ReQL command reference</h1>'
-          return doc
-        end
+        @doc = at_css('.docs-article')
 
         css('header .title').each do |node|
           node.parent.replace(node)
         end
 
-        css('.lang-selector').remove
+        css('.lang-selector', '.platform-buttons img', 'hr', '#in-this-article').remove
 
         css('.command-syntax').each do |node|
           node.name = 'pre'
@@ -22,19 +19,33 @@ module Docs
           node.content = node.content
         end
 
-        css('.highlight', '> section', '.highlighter-rouge').each do |node|
+        css('.highlight', 'section', 'div.highlighter-rouge', 'a > p', 'li > h1').each do |node|
           node.before(node.children).remove
         end
 
+        css('h2, h3, h4').each do |node|
+          node.name = node.name.sub(/\d/) { |i| i.to_i + 1 }
+        end
+
         css('h1').each do |node|
           next if node['class'].to_s.include?('title')
           node.name = 'h2'
         end
 
+        css('td h2').each do |node|
+          node.name = 'h5'
+        end
+
         css('pre').each do |node|
           node['data-language'] = current_url.path[/\A\/api\/(\w+)\//, 1]
         end
 
+        css('.infobox').each do |node|
+          node.name = 'blockquote'
+        end
+
+        css('> .infobox:last-child:contains("Contribute:")').remove
+
         doc
       end
     end

+ 18 - 4
lib/docs/filters/rethinkdb/entries.rb

@@ -2,20 +2,34 @@ module Docs
   class Rethinkdb
     class EntriesFilter < Docs::EntriesFilter
       def get_name
-        at_css('.title').content.remove('ReQL command:').split(', ').first
+        if subpath.start_with?('api')
+          at_css('.title').content.remove('ReQL command:').split(', ').first
+        else
+          at_css('.docs-nav .active').content
+        end
       end
 
       def get_type
-        link = at_css('a[href^="https://github.com/rethinkdb/docs/blob/master/api/"]')
-        dir = link['href'][/api\/\w+\/([^\/]+)/, 1]
-        dir.titleize.gsub('Rql', 'ReQL').gsub('And', 'and')
+        if subpath.start_with?('api')
+          link = at_css('a[href^="https://github.com/rethinkdb/docs/blob/master/api/"]')
+          dir = link['href'][/api\/\w+\/([^\/]+)/, 1]
+          return 'Reference' if dir == 'index.md'
+          dir.titleize.gsub('Rql', 'ReQL').gsub('And', 'and')
+        else
+          at_css('.docs-nav .expanded').previous_element.content.prepend('Guides: ')
+        end
       end
 
       def additional_entries
+        return [] unless subpath.start_with?('api')
         at_css('.title').content.split(', ')[1..-1].map do |name|
           [name]
         end
       end
+
+      def include_default_entry?
+        at_css('.docs-article p').try(:content) != 'Choose your language:'
+      end
     end
   end
 end

+ 43 - 28
lib/docs/scrapers/rethinkdb.rb

@@ -2,7 +2,9 @@ module Docs
   class Rethinkdb < UrlScraper
     self.name = 'RethinkDB'
     self.type = 'rethinkdb'
-    self.release = '2.3.2'
+    self.base_url = 'https://rethinkdb.com/'
+    self.release = '2.3.5'
+    self.root_path = 'docs/'
     self.links = {
       home: 'https://rethinkdb.com/',
       code: 'https://github.com/rethinkdb/rethinkdb'
@@ -10,44 +12,57 @@ module Docs
 
     html_filters.push 'rethinkdb/entries', 'rethinkdb/clean_html'
 
-    options[:trailing_slash] = false
-    options[:container] = '.docs-article'
+    options[:trailing_slash] = true
+    options[:container] = '.documentation'
+
+    options[:only_patterns] = [/\Adocs/]
+    options[:skip_patterns] = [/docs\/install(\-drivers)?\/./]
+    options[:skip] = %w(
+      docs/build/
+      docs/tutorials/elections/
+      docs/tutorials/superheroes/)
+
+    MULTILANG_DOCS = %w(
+      changefeeds
+      cookbook
+      dates-and-times
+      geo-support
+      guide
+      nested-fields
+      publish-subscribe
+      rabbitmq
+      secondary-indexes
+      sql-to-reql
+      storing-binary)
 
     options[:attribution] = <<-HTML
       &copy; RethinkDB contributors<br>
       Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
     HTML
 
-    version 'JavaScript' do
-      self.base_url = 'https://rethinkdb.com/api/javascript/'
-
-      options[:fix_urls] = ->(url) do
-        url.sub! %r{rethinkdb.com/api/(?!javascript|ruby|python|java)}, 'rethinkdb.com/api/javascript/'
-      end
-    end
-
-    version 'Ruby' do
-      self.base_url = 'https://rethinkdb.com/api/ruby/'
-
-      options[:fix_urls] = ->(url) do
-        url.sub! %r{rethinkdb.com/api/(?!javascript|ruby|python|java)}, 'rethinkdb.com/api/ruby/'
-      end
-    end
+    %w(JavaScript Ruby Python Java).each do |name|
+      path = name.downcase
+      instance_eval <<-CODE
+        version '#{name}' do
+          self.initial_paths = %w(api/#{path}/)
 
-    version 'Python' do
-      self.base_url = 'https://rethinkdb.com/api/python/'
+          options[:only_patterns] += [/\\Aapi\\/#{path}\\//]
 
-      options[:fix_urls] = ->(url) do
-        url.sub! %r{rethinkdb.com/api/(?!javascript|ruby|python|java)}, 'rethinkdb.com/api/python/'
-      end
+          options[:fix_urls] = ->(url) do
+            url.sub! %r{rethinkdb.com/docs/(#{MULTILANG_DOCS.join('|')})\\z}, 'rethinkdb.com/docs/\\1/#{path}/'
+            url.sub! %r{rethinkdb.com/docs/(#{MULTILANG_DOCS.join('|')})/(?!#{path}/).*}, 'rethinkdb.com/docs/\\1/#{path}/'
+            url.sub! %r{rethinkdb.com/api/(?!javascript|ruby|python|java)}, 'rethinkdb.com/api/#{path}/'
+            url
+          end
+        end
+      CODE
     end
 
-    version 'Java' do
-      self.base_url = 'https://rethinkdb.com/api/java/'
+    private
 
-      options[:fix_urls] = ->(url) do
-        url.sub! %r{rethinkdb.com/api/(?!javascript|ruby|python|java)}, 'rethinkdb.com/api/java/'
-      end
+    def process_response?(response)
+      return false unless super
+      response.body !~ /http-equiv="refresh"/i
     end
   end
 end

BIN
public/icons/docs/rethinkdb/16.png


BIN
public/icons/docs/rethinkdb/16@2x.png