| @@ -11,98 +11,144 @@ module Docs · 10 unmodified lines |
| 11 | 11 | 'System Administration Functions' => 'Administration Functions', |
| 12 | 12 | 'System Information Functions' => 'Information Functions' } |
| 13 | 13 | |
| 14 | | − def get_name |
| 15 | | − name = at_css('h1').content |
| 16 | | − clean_heading_name(name) |
| 14 | + PREPEND_TYPES = [ |
| 15 | + 'Type Conversion', |
| 16 | + 'Full Text Search', |
| 17 | + 'Performance Tips', |
| 18 | + 'Server Configuration', |
| 19 | + 'Monitoring' ] |
| 20 | + |
| 21 | + REPLACE_TYPES = { |
| 22 | + 'Routine Database Maintenance Tasks' => 'Maintenance', |
| 23 | + 'High Availability, Load Balancing, and Replication' => 'High Availability', |
| 24 | + 'Monitoring Database Activity' => 'Monitoring', |
| 25 | + 'Monitoring Disk Usage' => 'Monitoring', |
| 26 | + 'Reliability and the Write-Ahead Log' => 'Write-Ahead Log' } |
| 27 | + |
| 28 | + def base_name |
| 29 | + @base_name ||= clean_heading_name(at_css('h1').content) |
| 30 | + end |
| 17 | 31 | |
| 18 | | − if %w(Overview Introduction).include?(name) |
| 32 | + def get_name |
| 33 | + if %w(Overview Introduction).include?(base_name) |
| 19 | 34 | result[:pg_chapter_name] |
| 35 | + elsif PREPEND_TYPES.include?(type) |
| 36 | + "#{type}: #{base_name}" |
| 20 | 37 | else |
| 21 | | − name.remove! ' (Common Table Expressions)' |
| 22 | | − REPLACE_NAMES[name] || name |
| 38 | + REPLACE_NAMES[base_name] || base_name |
| 23 | 39 | end |
| 24 | 40 | end |
| 25 | 41 | |
| 26 | | − def clean_heading_name(name) |
| 27 | | − name.remove! %r{\A[\d\.\s]+} |
| 28 | | − name.remove! 'Using ' |
| 29 | | − name.remove! %r{\AThe } |
| 30 | | − name |
| 31 | | − end |
| 32 | | − |
| 33 | 42 | def get_type |
| 34 | 43 | return if initial_page? |
| 35 | 44 | |
| 36 | 45 | if result[:pg_up_path] == 'sql-commands.html' |
| 37 | 46 | 'Commands' |
| 38 | | − elsif result[:pg_up_path].start_with? 'reference-' |
| 47 | + elsif result[:pg_up_path].start_with?('reference-') |
| 39 | 48 | 'Applications' |
| 40 | 49 | elsif type = result[:pg_chapter_name] |
| 41 | | − if type.start_with?('Func') && (match = name.match(/\A(?!Form|Seq|Set|Enum)(.+) Func/)) |
| 50 | + if type.start_with?('Func') && (match = base_name.match(/\A(?!Form|Seq|Set|Enum)(.+) Func/)) |
| 42 | 51 | "Functions: #{match[1]}" |
| 43 | 52 | else |
| 44 | | − type.remove 'SQL ' |
| 53 | + type.remove! 'SQL ' |
| 54 | + REPLACE_TYPES[type] || type |
| 45 | 55 | end |
| 46 | 56 | end |
| 47 | 57 | end |
| 48 | 58 | |
| 49 | 59 | def additional_entries |
| 50 | 60 | return [] if skip_additional_entries? |
| 51 | | − return get_config_entries if config_page? |
| 61 | + return config_additional_entries if type && type.include?('Configuration') |
| 62 | + return data_types_additional_entries if type == 'Data Types' |
| 52 | 63 | return get_heading_entries('h3[id]') if slug == 'functions-xml' |
| 53 | 64 | |
| 54 | | − if type == 'Data Types' |
| 55 | | − return get_custom_entries case slug |
| 56 | | − when 'rangetypes' then 'li > p > .TYPE:first-child' |
| 57 | | − when 'datatype-textsearch' then '.SECT2 > .TYPE' |
| 58 | | − else '.CALSTABLE td:first-child > .TYPE' end |
| 59 | | − end |
| 60 | | − |
| 61 | 65 | entries = get_heading_entries('h2[id]') |
| 62 | 66 | |
| 63 | | − if slug == 'queries-union' |
| 67 | + case slug |
| 68 | + when 'queries-union' |
| 64 | 69 | entries.concat get_custom_entries('p > .LITERAL:first-child') |
| 65 | | − elsif slug == 'queries-table-expressions' |
| 70 | + when 'queries-table-expressions' |
| 66 | 71 | entries.concat get_heading_entries('h3[id]') |
| 67 | 72 | entries.concat get_custom_entries('dt > .LITERAL:first-child') |
| 68 | | − elsif slug == 'functions-logical' |
| 73 | + when 'functions-logical' |
| 69 | 74 | entries.concat get_custom_entries('> table td:first-child > code') |
| 70 | | − elsif slug == 'functions-formatting' |
| 75 | + when 'functions-formatting' |
| 71 | 76 | entries.concat get_custom_entries('#FUNCTIONS-FORMATTING-TABLE td:first-child > code') |
| 72 | | − elsif slug == 'functions-admin' |
| 77 | + when 'functions-admin' |
| 73 | 78 | entries.concat get_custom_entries('.TABLE td:first-child > code') |
| 74 | | − elsif slug == 'functions-string' |
| 79 | + when 'functions-string' |
| 75 | 80 | entries.concat get_custom_entries('> div[id^="FUNC"] td:first-child > code') |
| 76 | | − elsif type && type.start_with?('Functions') |
| 77 | | − entries.concat get_custom_entries('> .TABLE td:first-child > code:first-child') |
| 78 | | − entries.concat get_comparison_entries if slug == 'functions-comparison' |
| 81 | + else |
| 82 | + if type && type.start_with?('Functions') |
| 83 | + entries.concat get_custom_entries('> .TABLE td:first-child > code:first-child') |
| 84 | + entries.concat %w(IS NULL BETWEEN DISTINCT\ FROM).map { |name| ["#{self.name}: #{name}"] } if slug == 'functions-comparison' |
| 85 | + end |
| 79 | 86 | end |
| 80 | 87 | |
| 81 | 88 | entries |
| 82 | 89 | end |
| 83 | 90 | |
| 84 | | − def get_config_entries |
| 91 | + def config_additional_entries |
| 85 | 92 | css('.VARIABLELIST dt[id]').map do |node| |
| 86 | 93 | name = node.at_css('.VARNAME').content |
| 87 | 94 | ["Config: #{name}", node['id']] |
| 88 | 95 | end |
| 89 | 96 | end |
| 90 | 97 | |
| 98 | + def data_types_additional_entries |
| 99 | + selector = case slug |
| 100 | + when 'rangetypes' |
| 101 | + 'li > p > .TYPE:first-child' |
| 102 | + when 'datatype-textsearch' |
| 103 | + '.SECT2 > .TYPE' |
| 104 | + else |
| 105 | + '.CALSTABLE td:first-child > .TYPE' |
| 106 | + end |
| 107 | + get_custom_entries(selector) |
| 108 | + end |
| 109 | + |
| 110 | + def include_default_entry? |
| 111 | + !initial_page? && !at_css('.TOC') |
| 112 | + end |
| 113 | + |
| 114 | + SKIP_ENTRIES_SLUGS = [ |
| 115 | + 'config-setting', |
| 116 | + 'applevel-consistency' ] |
| 117 | + |
| 118 | + SKIP_ENTRIES_TYPES = [ |
| 119 | + 'Localization', |
| 120 | + 'Type Conversion', |
| 121 | + 'Full Text Search', |
| 122 | + 'Performance Tips', |
| 123 | + 'Client Authentication', |
| 124 | + 'Managing Databases', |
| 125 | + 'Maintenance', |
| 126 | + 'Backup and Restore', |
| 127 | + 'High Availability', |
| 128 | + 'Monitoring' ] |
| 129 | + |
| 130 | + def skip_additional_entries? |
| 131 | + SKIP_ENTRIES_SLUGS.include?(slug) || SKIP_ENTRIES_TYPES.include?(type) |
| 132 | + end |
| 133 | + |
| 134 | + def clean_heading_name(name) |
| 135 | + name.remove! %r{\A[\d\.\s]+} |
| 136 | + name.remove! 'Using ' |
| 137 | + name.remove! %r{\AThe } |
| 138 | + name.remove! ' (Common Table Expressions)' |
| 139 | + name |
| 140 | + end |
| 141 | + |
| 91 | 142 | def get_heading_entries(selector) |
| 92 | | − css(selector).inject [] do |entries, node| |
| 143 | + css(selector).each_with_object([]) do |node, entries| |
| 93 | 144 | name = node.content |
| 94 | 145 | clean_heading_name(name) |
| 95 | | − |
| 96 | | − unless skip_heading?(name) |
| 97 | | − entries << ["#{additional_entry_prefix}: #{name}", node['id']] |
| 98 | | − end |
| 99 | | − |
| 100 | | − entries |
| 146 | + entries << ["#{additional_entry_prefix}: #{name}", node['id']] unless skip_heading?(name) |
| 101 | 147 | end |
| 102 | 148 | end |
| 103 | 149 | |
| 104 | 150 | def get_custom_entries(selector) |
| 105 | | − css(selector).inject [] do |entries, node| |
| 151 | + css(selector).each_with_object([]) do |node, entries| |
| 106 | 152 | name = node.content |
| 107 | 153 | name.remove! %r{\(.*?\)}m |
| 108 | 154 | name.remove! %r{\[.*?\]}m |
| @@ -117,14 +163,6 @@ module Docs · 8 unmodified lines |
| 117 | 163 | node['id'] = id |
| 118 | 164 | entries << [name, id] |
| 119 | 165 | end |
| 120 | | − |
| 121 | | − entries |
| 122 | | − end |
| 123 | | − end |
| 124 | | − |
| 125 | | − def get_comparison_entries |
| 126 | | − %w(IS NULL BETWEEN DISTINCT\ FROM).map do |name| |
| 127 | | − ["#{self.name}: #{name}"] |
| 128 | 166 | end |
| 129 | 167 | end |
| 130 | 168 | |
| @@ -132,22 +170,10 @@ module Docs · 1 unmodified line |
| 132 | 170 | type.dup.gsub!('Functions: ', '') || self.name |
| 133 | 171 | end |
| 134 | 172 | |
| 135 | | − def skip_additional_entries? |
| 136 | | − slug == 'config-setting' || %w(Concurrency\ Control Localization).include?(type) |
| 137 | | − end |
| 138 | | − |
| 139 | 173 | def skip_heading?(name) |
| 140 | 174 | %w(Usage\ Patterns Portability Caveats Overview).include?(name) || |
| 141 | 175 | (type.start_with?('Functions') && slug != 'functions-xml' && name.split.first.upcase!) |
| 142 | 176 | end |
| 143 | | − |
| 144 | | − def include_default_entry? |
| 145 | | − !(initial_page? || at_css('.TOC') || config_page?) |
| 146 | | − end |
| 147 | | − |
| 148 | | − def config_page? |
| 149 | | − slug.start_with? 'runtime-config' |
| 150 | | − end |
| 151 | 177 | end |
| 152 | 178 | end |
| 153 | 179 | end |