| @@ -0,0 +1,87 @@ |
| | 1 | module Docs |
| | 2 | class Python2 |
| | 3 | class EntriesFilter < Docs::EntriesFilter |
| | 4 | REPLACE_TYPES = { |
| | 5 | 'compiler package' => 'Compiler', |
| | 6 | 'Cryptographic' => 'Cryptography', |
| | 7 | 'Custom Interpreters' => 'Interpreters', |
| | 8 | 'Data Compression & Archiving' => 'Data Compression', |
| | 9 | 'Generic Operating System' => 'Operating System', |
| | 10 | 'Graphical User Interfaces with Tk' => 'Tk', |
| | 11 | 'Internet Data Handling' => 'Internet Data', |
| | 12 | 'Internet Protocols & Support' => 'Internet', |
| | 13 | 'Interprocess Communication & Networking' => 'Networking', |
| | 14 | 'MacOSA' => 'Mac OS', |
| | 15 | 'Program Frameworks' => 'Frameworks', |
| | 16 | 'Structured Markup Processing Tools' => 'Structured Markup' } |
| | 17 | |
| | 18 | def get_name |
| | 19 | name = at_css('h1').content |
| | 20 | name.remove! %r{\A[\d\.]+ } # remove list number |
| | 21 | name.remove! "\u{00B6}" # remove pilcrow sign |
| | 22 | name.remove! %r{ [\u{2013}\u{2014}].+\z} # remove text after em/en dash |
| | 23 | name.remove! 'Built-in' |
| | 24 | name.strip! |
| | 25 | name |
| | 26 | end |
| | 27 | |
| | 28 | def get_type |
| | 29 | return 'Logging' if slug.start_with? 'library/logging' |
| | 30 | |
| | 31 | type = at_css('.related a[accesskey="U"]').content |
| | 32 | |
| | 33 | if type == 'The Python Standard Library' |
| | 34 | type = at_css('h1').content |
| | 35 | elsif type.include?('I/O') || %w(select selectors).include?(name) |
| | 36 | type = 'Input/ouput' |
| | 37 | elsif type.start_with? '18' |
| | 38 | type = 'Internet Data Handling' |
| | 39 | elsif type.include? 'Mac' |
| | 40 | type = 'Mac OS' |
| | 41 | end |
| | 42 | |
| | 43 | type.remove! %r{\A\d+\.\s+} # remove list number |
| | 44 | type.remove! "\u{00b6}" # remove paragraph character |
| | 45 | type.sub! ' and ', ' & ' |
| | 46 | [' Services', ' Modules', ' Specific', 'Python '].each { |str| type.remove!(str) } |
| | 47 | |
| | 48 | REPLACE_TYPES[type] || type |
| | 49 | end |
| | 50 | |
| | 51 | def include_default_entry? |
| | 52 | !at_css('.body > .section:only-child > .toctree-wrapper:last-child') && !type.in?(%w(Language Superseded SunOS)) |
| | 53 | end |
| | 54 | |
| | 55 | def additional_entries |
| | 56 | return [] if root_page? || !include_default_entry? || name == 'errno' |
| | 57 | clean_id_attributes |
| | 58 | entries = [] |
| | 59 | |
| | 60 | css('.class > dt[id]', '.exception > dt[id]', '.attribute > dt[id]').each do |node| |
| | 61 | entries << [node['id'], node['id']] |
| | 62 | end |
| | 63 | |
| | 64 | css('.data > dt[id]').each do |node| |
| | 65 | if node['id'].split('.').last.upcase! # skip constants |
| | 66 | entries << [node['id'], node['id']] |
| | 67 | end |
| | 68 | end |
| | 69 | |
| | 70 | css('.function > dt[id]', '.method > dt[id]', '.classmethod > dt[id]').each do |node| |
| | 71 | entries << [node['id'] + '()', node['id']] |
| | 72 | end |
| | 73 | |
| | 74 | entries |
| | 75 | end |
| | 76 | |
| | 77 | def clean_id_attributes |
| | 78 | css('.section > .target[id]').each do |node| |
| | 79 | if dt = node.at_css('+ dl > dt') |
| | 80 | dt['id'] ||= node['id'].remove(/\w+\-/) |
| | 81 | end |
| | 82 | node.remove |
| | 83 | end |
| | 84 | end |
| | 85 | end |
| | 86 | end |
| | 87 | end |