History

Update PostgreSQL documentation (10.1)

Thibaut Courouble committed 9 years ago

Commit e7048a81 parent 03428546 files · +105 −43Browse files

Unified · Split

6 files
  1. assets/stylesheets/pages/_postgres.scss +11 −6
  2. lib/docs/filters/postgresql/clean_html.rb +34 −5
  3. lib/docs/filters/postgresql/entries.rb +23 −21
  4. lib/docs/filters/postgresql/extract_metadata.rb +10 −8
  5. lib/docs/filters/postgresql/normalize_class_names.rb +13 −0
  6. lib/docs/scrapers/postgresql.rb +14 −3
assets/stylesheets/pages/_postgres.scss+11−6
@@ -1,19 +1,24 @@
11 ._postgres {
22 padding-left: 1rem;
33
4− h1, h1 ~ p, h1 ~ pre, h1 ~ blockquote, h2, .NAVFOOTER { margin-left: -1rem; }
4+ h1, h1 ~ p, h1 ~ pre, h1 ~ ul, h1 ~ blockquote, h2, .navfooter { margin-left: -1rem; }
55 h2 { @extend %block-heading; }
66
7− .VARIABLELIST dt { @extend %block-label, %label-blue; }
7+ .variablelist dt { @extend %block-label, %label-blue; }
88
9− blockquote.NOTE, blockquote.IMPORTANT, blockquote.TIP, blockquote.CAUTION { @extend %note; }
10− blockquote.TIP { @extend %note-green; }
11− blockquote.CAUTION { @extend %note-orange; }
9+ blockquote.note, blockquote.important, blockquote.tip, blockquote.caution { @extend %note; }
10+ blockquote.tip { @extend %note-green; }
11+ blockquote.caution { @extend %note-orange; }
12+
13+ blockquote > h3 {
14+ font-size: .875rem;
15+ margin: 0 0 .25rem;
16+ }
1217
1318 p > code { @extend %label; }
1419 p.c2 { font-weight: $boldFontWeight; }
1520
16− .NAVFOOTER > table { width: 100%; }
21+ .navfooter > table { width: 100%; }
1722 td[align=center] { text-align: center; }
1823 td[align=right] { text-align: right; }
1924 }
lib/docs/filters/postgresql/clean_html.rb+34−5
@@ -13,18 +13,22 @@ module Docs · 12 unmodified lines
1313 def other
1414 @doc = at_css('#docContent')
1515
16− css('.NAVHEADER', 'hr', '.NAVFOOTER a[accesskey="H"]').remove
16+ css('.navheader', 'hr', '.navfooter a[accesskey="H"]').remove
17+
18+ unless at_css('h1')
19+ at_css('.refnamediv h2, .titlepage h2').name = 'h1'
20+ end
1721
1822 css('a[name]').each do |node|
1923 node.parent['id'] = node['name']
2024 node.before(node.children).remove
2125 end
2226
23− css('div.SECT1', 'pre > kbd', 'tt > code', 'h1 > tt', '> .CHAPTER', 'div.NOTE', '.APPENDIX').each do |node|
27+ css('div.sect1', '.refentry', '.refnamediv', '.refentrytitle', '.refsynopsisdiv', 'pre > kbd', 'tt > code', 'h1 > tt', '> .chapter', '.appendix', '.titlepage', 'div:not([class]):not([id])', 'br', 'a.indexterm', 'acronym', '.productname', 'div.itemizedlist', 'span.sect2', 'span.application', 'em.replaceable', 'span.term').each do |node|
2428 node.before(node.children).remove
2529 end
2630
27− css('div.CAUTION table.CAUTION').each do |node|
31+ css('div.caution table.caution').each do |node|
2832 parent = node.parent
2933 title = node.at_css('.c2, .c3, .c4, .c5').content
3034 node.replace(node.css('p'))
@@ -43,11 +47,27 @@ module Docs · 12 unmodified lines
4347 node.remove_attribute 'valign'
4448 end
4549
50+ css('.sect2 > h3').each do |node|
51+ node.name = 'h2'
52+ end
53+
54+ css('.sect3 > h4').each do |node|
55+ node.name = 'h3'
56+ end
57+
4658 css('tt').each do |node|
4759 node.name = 'code'
4860 end
4961
50− css('.REFSYNOPSISDIV > p').each do |node|
62+ css('div.note', 'div.important', 'div.tip', 'div.caution').each do |node|
63+ if node.at_css('blockquote')
64+ node.before(node.children).remove
65+ else
66+ node.name = 'blockquote'
67+ end
68+ end
69+
70+ css('.refsynopsisdiv > p').each do |node|
5171 node.name = 'pre'
5272 node.content = node.content
5373 end
@@ -56,9 +76,18 @@ module Docs · 2 unmodified lines
5676 node.before(node.children).remove
5777 end
5878
59− css('pre.SYNOPSIS', 'pre.PROGRAMLISTING').each do |node|
79+ css('code').each do |node|
80+ node.inner_html = node.inner_html.gsub(/\s*\n\s*/, ' ')
81+ end
82+
83+ css('pre.synopsis', 'pre.programlisting').each do |node|
6084 node['data-language'] = 'sql'
6185 end
86+
87+ css('h1', 'ul', 'li', 'pre').each do |node|
88+ node.remove_attribute 'class'
89+ node.remove_attribute 'style'
90+ end
6291 end
6392 end
6493 end
lib/docs/filters/postgresql/entries.rb+23−21
@@ -90,33 +90,33 @@ module Docs · 89 unmodified lines
9090 return config_additional_entries if type && type.include?('Configuration')
9191 return data_types_additional_entries if type == 'Data Types'
9292 return command_additional_entries if type == 'Commands'
93− return get_heading_entries('h3[id]') if slug == 'functions-xml'
93+ return get_heading_entries('h3[id], .sect3[id] > h3:first-child') if slug == 'functions-xml'
9494
95− entries = get_heading_entries('h2[id]')
95+ entries = get_heading_entries('h2[id], .sect2[id] > h2:first-child')
9696
9797 case slug
9898 when 'queries-union'
99− entries.concat get_custom_entries('p > .LITERAL:first-child')
99+ entries.concat get_custom_entries('p > .literal:first-child')
100100 when 'queries-table-expressions'
101− entries.concat get_heading_entries('h3[id]')
102− entries.concat get_custom_entries('dt > .LITERAL:first-child')
101+ entries.concat get_heading_entries('h3[id], .sect3[id] > h3:first-child')
102+ entries.concat get_custom_entries('dt > .literal:first-child')
103103 when 'functions-logical'
104104 entries.concat get_custom_entries('> table td:first-child > code')
105105 when 'functions-formatting'
106106 entries.concat get_custom_entries('#FUNCTIONS-FORMATTING-TABLE td:first-child > code')
107107 when 'functions-admin'
108− entries.concat get_custom_entries('.TABLE td:first-child > code')
108+ entries.concat get_custom_entries('.table td:first-child > code')
109109 when 'functions-string'
110110 entries.concat get_custom_entries('> div[id^="FUNC"] td:first-child > code')
111111 entries.concat get_custom_entries('> div[id^="FORMAT"] td:first-child > code')
112112 else
113113 if type && type.start_with?('Functions')
114− entries.concat get_custom_entries('> .TABLE td:first-child > code.LITERAL:first-child')
115− entries.concat get_custom_entries('> .TABLE td:first-child > code.FUNCTION:first-child')
116− entries.concat get_custom_entries('> .TABLE td:first-child > code:not(.LITERAL):first-child + code.LITERAL')
117− entries.concat get_custom_entries('> .TABLE td:first-child > p > code.LITERAL:first-child')
118− entries.concat get_custom_entries('> .TABLE td:first-child > p > code.FUNCTION:first-child')
119− entries.concat get_custom_entries('> .TABLE td:first-child > p > code:not(.LITERAL):first-child + code.LITERAL')
114+ entries.concat get_custom_entries('> .table td:first-child > code.literal:first-child')
115+ entries.concat get_custom_entries('> .table td:first-child > code.function:first-child')
116+ entries.concat get_custom_entries('> .table td:first-child > code:not(.literal):first-child + code.literal')
117+ entries.concat get_custom_entries('> .table td:first-child > p > code.literal:first-child')
118+ entries.concat get_custom_entries('> .table td:first-child > p > code.function:first-child')
119+ entries.concat get_custom_entries('> .table td:first-child > p > code:not(.literal):first-child + code.literal')
120120 if slug == 'functions-comparison' && !at_css('#FUNCTIONS-COMPARISON-PRED-TABLE') # before 9.6
121121 entries.concat %w(IS NULL BETWEEN DISTINCT\ FROM).map { |name| ["#{self.name}: #{name}"] }
122122 end
@@ -127,8 +127,8 @@ module Docs · 4 unmodified lines
127127 end
128128
129129 def config_additional_entries
130− css('.VARIABLELIST dt[id]').map do |node|
131− name = node.at_css('.VARNAME').content
130+ css('.variablelist dt[id]').map do |node|
131+ name = node.at_css('.varname').content
132132 ["Config: #{name}", node['id']]
133133 end
134134 end
@@ -136,27 +136,27 @@ module Docs · 1 unmodified line
136136 def data_types_additional_entries
137137 selector = case slug
138138 when 'rangetypes'
139− 'li > p > .TYPE:first-child'
139+ 'li > p > .type:first-child'
140140 when 'datatype-textsearch'
141− '.SECT2 > .TYPE'
141+ '.title > .type, .sect2 > .type'
142142 else
143− '.CALSTABLE td:first-child > .TYPE'
143+ '.table-contents td:first-child > .type, .calstable td:first-child > .type'
144144 end
145145 get_custom_entries(selector)
146146 end
147147
148148 def command_additional_entries
149− css('.REFSECT2[id^="SQL"]').each_with_object([]) do |node, entries|
149+ css('.refsect2[id^="SQL"]').each_with_object([]) do |node, entries|
150150 next unless heading = node.at_css('h3')
151151 next unless heading.content.strip =~ /[A-Z_\-]+ Clause/
152− name = heading.at_css('.LITERAL').content
152+ name = heading.at_css('.literal').content
153153 name.prepend "#{self.name} ... "
154154 entries << [name, node['id']]
155155 end
156156 end
157157
158158 def include_default_entry?
159− !initial_page? && !at_css('.TOC') && type
159+ !initial_page? && (!at_css('.toc') || at_css('.sect2, .variablelist, .refsect1')) && type
160160 end
161161
162162 SKIP_ENTRIES_SLUGS = [
@@ -199,7 +199,9 @@ module Docs · 36 unmodified lines
199199 css(selector).each_with_object([]) do |node, entries|
200200 name = node.content
201201 clean_heading_name(name)
202− entries << ["#{additional_entry_prefix}: #{name}", node['id']] unless skip_heading?(name)
202+ id = node['id'] || node.parent['id']
203+ raise "missing ids for selector #{selector}" unless id
204+ entries << ["#{additional_entry_prefix}: #{name}", id] unless skip_heading?(name)
203205 end
204206 end
205207
lib/docs/filters/postgresql/extract_metadata.rb+10−8
@@ -8,19 +8,21 @@ module Docs · 7 unmodified lines
88 end
99
1010 def extract_up_path
11− if node = at_css('.NAVHEADER a[accesskey="U"]')
11+ if node = at_css('.navheader a[accesskey="u"], .navheader a[accesskey="U"]')
1212 result[:pg_up_path] = node['href']
1313 end
1414 end
1515
1616 def extract_chapter
17− return unless text = at_css('.NAVHEADER td[align="center"]').content
18− if match = text.match(/\AChapter (\d+)\. (.+)\z/)
19− result[:pg_chapter] = match[1].to_i
20− result[:pg_chapter_name] = match[2].strip
21− elsif match = text.match(/\AAppendix ([A-Z])\. (.+)\z/)
22− result[:pg_appendix] = match[1]
23− result[:pg_appendix_name] = match[2].strip
17+ css('.navheader td[align="center"], .navheader th[align="center"]').each do |node|
18+ text = node.content.strip
19+ if match = text.match(/\AChapter (\d+)\. (.+)\z/)
20+ result[:pg_chapter] = match[1].to_i
21+ result[:pg_chapter_name] = match[2].strip
22+ elsif match = text.match(/\AAppendix ([A-Z])\. (.+)\z/)
23+ result[:pg_appendix] = match[1]
24+ result[:pg_appendix_name] = match[2].strip
25+ end
2426 end
2527 end
2628 end
lib/docs/filters/postgresql/normalize_class_names.rb+13−0
@@ -0,0 +1,13 @@
1+module Docs
2+ class Postgresql
3+ class NormalizeClassNamesFilter < Filter
4+ def call
5+ doc.css('*').each do |node|
6+ node['class'] = node['class'].downcase if node['class'].present?
7+ end
8+
9+ doc
10+ end
11+ end
12+ end
13+end
lib/docs/scrapers/postgresql.rb+14−3
@@ -55,19 +55,30 @@ module Docs · 54 unmodified lines
5555 Licensed under the PostgreSQL License.
5656 HTML
5757
58+ version '10' do
59+ self.release = '10.1'
60+ self.base_url = 'https://www.postgresql.org/docs/10/static/'
61+ end
62+
5863 version '9.6' do
59− self.release = '9.6.5'
64+ self.release = '9.6.6'
6065 self.base_url = 'https://www.postgresql.org/docs/9.6/static/'
66+
67+ html_filters.insert_before 'postgresql/extract_metadata', 'postgresql/normalize_class_names'
6168 end
6269
6370 version '9.5' do
64− self.release = '9.5.9'
71+ self.release = '9.5.10'
6572 self.base_url = 'https://www.postgresql.org/docs/9.5/static/'
73+
74+ html_filters.insert_before 'postgresql/extract_metadata', 'postgresql/normalize_class_names'
6675 end
6776
6877 version '9.4' do
69− self.release = '9.4.14'
78+ self.release = '9.4.15'
7079 self.base_url = 'https://www.postgresql.org/docs/9.4/static/'
80+
81+ html_filters.insert_before 'postgresql/extract_metadata', 'postgresql/normalize_class_names'
7182 end
7283 end
7384 end