History

Update and improve RethinkDB documentation

Thibaut Courouble committed 10 years ago

Commit c0179b21 parent 190d95c8 files · +77 −36Browse files

Unified · Split

8 files
  1. assets/images/docs.png +0 −0
  2. assets/images/docs@2x.png +0 −0
  3. assets/stylesheets/pages/_rethinkdb.scss +3 −2
  4. lib/docs/filters/rethinkdb/clean_html.rb +17 −6
  5. lib/docs/filters/rethinkdb/entries.rb +18 −4
  6. lib/docs/scrapers/rethinkdb.rb +43 −28
  7. public/icons/docs/rethinkdb/16.png +0 −0
  8. public/icons/docs/rethinkdb/16@2x.png +0 −0
assets/images/docs.png+0−0

Binary file not shown.

assets/images/docs@2x.png+0−0

Binary file not shown.

assets/stylesheets/pages/_rethinkdb.scss+3−2
@@ -1,6 +1,7 @@
11 ._rethinkdb {
2− > h2 { @extend %block-heading; }
3− code { @extend %label; }
2+ @extend %simple;
3+
4+ .infobox-alert { @extend %note-orange; }
45
56 .api_command_illustration {
67 float: right;
lib/docs/filters/rethinkdb/clean_html.rb+17−6
@@ -2,16 +2,13 @@ module Docs · 1 unmodified line
22 class Rethinkdb
33 class CleanHtmlFilter < Filter
44 def call
5− if root_page?
6− doc.inner_html = '<h1>ReQL command reference</h1>'
7− return doc
8− end
5+ @doc = at_css('.docs-article')
96
107 css('header .title').each do |node|
118 node.parent.replace(node)
129 end
1310
14− css('.lang-selector').remove
11+ css('.lang-selector', '.platform-buttons img', 'hr', '#in-this-article').remove
1512
1613 css('.command-syntax').each do |node|
1714 node.name = 'pre'
@@ -22,19 +19,33 @@ module Docs · 4 unmodified lines
2219 node.content = node.content
2320 end
2421
25− css('.highlight', '> section', '.highlighter-rouge').each do |node|
22+ css('.highlight', 'section', 'div.highlighter-rouge', 'a > p', 'li > h1').each do |node|
2623 node.before(node.children).remove
2724 end
2825
26+ css('h2, h3, h4').each do |node|
27+ node.name = node.name.sub(/\d/) { |i| i.to_i + 1 }
28+ end
29+
2930 css('h1').each do |node|
3031 next if node['class'].to_s.include?('title')
3132 node.name = 'h2'
3233 end
3334
35+ css('td h2').each do |node|
36+ node.name = 'h5'
37+ end
38+
3439 css('pre').each do |node|
3540 node['data-language'] = current_url.path[/\A\/api\/(\w+)\//, 1]
3641 end
3742
43+ css('.infobox').each do |node|
44+ node.name = 'blockquote'
45+ end
46+
47+ css('> .infobox:last-child:contains("Contribute:")').remove
48+
3849 doc
3950 end
4051 end
lib/docs/filters/rethinkdb/entries.rb+18−4
@@ -2,20 +2,34 @@ module Docs · 1 unmodified line
22 class Rethinkdb
33 class EntriesFilter < Docs::EntriesFilter
44 def get_name
5− at_css('.title').content.remove('ReQL command:').split(', ').first
5+ if subpath.start_with?('api')
6+ at_css('.title').content.remove('ReQL command:').split(', ').first
7+ else
8+ at_css('.docs-nav .active').content
9+ end
610 end
711
812 def get_type
9− link = at_css('a[href^="https://github.com/rethinkdb/docs/blob/master/api/"]')
10− dir = link['href'][/api\/\w+\/([^\/]+)/, 1]
11− dir.titleize.gsub('Rql', 'ReQL').gsub('And', 'and')
13+ if subpath.start_with?('api')
14+ link = at_css('a[href^="https://github.com/rethinkdb/docs/blob/master/api/"]')
15+ dir = link['href'][/api\/\w+\/([^\/]+)/, 1]
16+ return 'Reference' if dir == 'index.md'
17+ dir.titleize.gsub('Rql', 'ReQL').gsub('And', 'and')
18+ else
19+ at_css('.docs-nav .expanded').previous_element.content.prepend('Guides: ')
20+ end
1221 end
1322
1423 def additional_entries
24+ return [] unless subpath.start_with?('api')
1525 at_css('.title').content.split(', ')[1..-1].map do |name|
1626 [name]
1727 end
1828 end
29+
30+ def include_default_entry?
31+ at_css('.docs-article p').try(:content) != 'Choose your language:'
32+ end
1933 end
2034 end
2135 end
lib/docs/scrapers/rethinkdb.rb+43−28
@@ -2,7 +2,9 @@ module Docs · 1 unmodified line
22 class Rethinkdb < UrlScraper
33 self.name = 'RethinkDB'
44 self.type = 'rethinkdb'
5− self.release = '2.3.2'
5+ self.base_url = 'https://rethinkdb.com/'
6+ self.release = '2.3.5'
7+ self.root_path = 'docs/'
68 self.links = {
79 home: 'https://rethinkdb.com/',
810 code: 'https://github.com/rethinkdb/rethinkdb'
@@ -10,44 +12,57 @@ module Docs · 1 unmodified line
1012
1113 html_filters.push 'rethinkdb/entries', 'rethinkdb/clean_html'
1214
13− options[:trailing_slash] = false
14− options[:container] = '.docs-article'
15+ options[:trailing_slash] = true
16+ options[:container] = '.documentation'
17+
18+ options[:only_patterns] = [/\Adocs/]
19+ options[:skip_patterns] = [/docs\/install(\-drivers)?\/./]
20+ options[:skip] = %w(
21+ docs/build/
22+ docs/tutorials/elections/
23+ docs/tutorials/superheroes/)
24+
25+ MULTILANG_DOCS = %w(
26+ changefeeds
27+ cookbook
28+ dates-and-times
29+ geo-support
30+ guide
31+ nested-fields
32+ publish-subscribe
33+ rabbitmq
34+ secondary-indexes
35+ sql-to-reql
36+ storing-binary)
1537
1638 options[:attribution] = <<-HTML
1739 &copy; RethinkDB contributors<br>
1840 Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
1941 HTML
2042
21− version 'JavaScript' do
22− self.base_url = 'https://rethinkdb.com/api/javascript/'
23−
24− options[:fix_urls] = ->(url) do
25− url.sub! %r{rethinkdb.com/api/(?!javascript|ruby|python|java)}, 'rethinkdb.com/api/javascript/'
26− end
27− end
28−
29− version 'Ruby' do
30− self.base_url = 'https://rethinkdb.com/api/ruby/'
31−
32− options[:fix_urls] = ->(url) do
33− url.sub! %r{rethinkdb.com/api/(?!javascript|ruby|python|java)}, 'rethinkdb.com/api/ruby/'
34− end
35− end
43+ %w(JavaScript Ruby Python Java).each do |name|
44+ path = name.downcase
45+ instance_eval <<-CODE
46+ version '#{name}' do
47+ self.initial_paths = %w(api/#{path}/)
3648
37− version 'Python' do
38− self.base_url = 'https://rethinkdb.com/api/python/'
49+ options[:only_patterns] += [/\\Aapi\\/#{path}\\//]
3950
40− options[:fix_urls] = ->(url) do
41− url.sub! %r{rethinkdb.com/api/(?!javascript|ruby|python|java)}, 'rethinkdb.com/api/python/'
42− end
51+ options[:fix_urls] = ->(url) do
52+ url.sub! %r{rethinkdb.com/docs/(#{MULTILANG_DOCS.join('|')})\\z}, 'rethinkdb.com/docs/\\1/#{path}/'
53+ url.sub! %r{rethinkdb.com/docs/(#{MULTILANG_DOCS.join('|')})/(?!#{path}/).*}, 'rethinkdb.com/docs/\\1/#{path}/'
54+ url.sub! %r{rethinkdb.com/api/(?!javascript|ruby|python|java)}, 'rethinkdb.com/api/#{path}/'
55+ url
56+ end
57+ end
58+ CODE
4359 end
4460
45− version 'Java' do
46− self.base_url = 'https://rethinkdb.com/api/java/'
61+ private
4762
48− options[:fix_urls] = ->(url) do
49− url.sub! %r{rethinkdb.com/api/(?!javascript|ruby|python|java)}, 'rethinkdb.com/api/java/'
50− end
63+ def process_response?(response)
64+ return false unless super
65+ response.body !~ /http-equiv="refresh"/i
5166 end
5267 end
5368 end
public/icons/docs/rethinkdb/16.png+0−0

Binary file not shown.

public/icons/docs/rethinkdb/16@2x.png+0−0

Binary file not shown.