|
| 1 | +module Docs |
| 2 | + class Qt |
| 3 | + class EntriesFilter < Docs::EntriesFilter |
| 4 | + def get_name |
| 5 | + header = at_css('h1.title + .small-subtitle a') || at_css('h1.title') || at_css('.context h2') |
| 6 | + name = header.content |
| 7 | + name.sub! %r{ Class$}, ' (class)' |
| 8 | + name.sub! %r{ QML Type$}, ' (QML type)' |
| 9 | + name.sub! %r{ QML Basic Type$}, ' (QML basic type)' |
| 10 | + |
| 11 | + # Add '(class)' to the class pages where the subtitle name is used (e.g. qset-const-iterator.html) |
| 12 | + if at_css('h1.title').content.strip.end_with?(' Class') and !name.include?('(class)') |
| 13 | + name = "#{name} (class) " |
| 14 | + end |
| 15 | + |
| 16 | + name |
| 17 | + end |
| 18 | + |
| 19 | + def get_type |
| 20 | + breadcrumb = css('#main_title_bar + ul li') |
| 21 | + category = if breadcrumb.length < 3 |
| 22 | + then 'Qt' |
| 23 | + else breadcrumb.at(1).content |
| 24 | + end |
| 25 | + |
| 26 | + if category == 'Qt' |
| 27 | + return 'Qt Platforms' if name.include? ' for ' or name == 'Qt Platform Abstraction' |
| 28 | + return 'Qt Quick' if name == 'Qt Quick Test' or name == 'Qt Quick Test Reference Documentation' |
| 29 | + |
| 30 | + alwaysInQt = ["Qt Configure Options", "Qt Image Formats"] |
| 31 | + category = name if name.start_with?('Qt ') && !alwaysInQt.include?(name) |
| 32 | + end |
| 33 | + |
| 34 | + qtPlatformsTypes = ['Qt Platform Headers', 'Qt Android Extras', 'Qt Mac Extras', 'Qt Windows Extras', 'Qt X11 Extras'] |
| 35 | + return 'Qt Platforms' if qtPlatformsTypes.include? category |
| 36 | + |
| 37 | + category.sub! ' Manual', '' |
| 38 | + category |
| 39 | + end |
| 40 | + |
| 41 | + def include_default_entry? |
| 42 | + name != 'All Classes' and name != 'All QML Types' |
| 43 | + end |
| 44 | + |
| 45 | + def additional_entries |
| 46 | + entries = [] |
| 47 | + titles = [] |
| 48 | + |
| 49 | + className = at_css('h1.title').content.strip.sub ' Class', '' |
| 50 | + displayedClassName = className |
| 51 | + alternativeClassName = at_css('h1.title + .small-subtitle a') |
| 52 | + displayedClassName = alternativeClassName.content if alternativeClassName |
| 53 | + |
| 54 | + # Functions signatures |
| 55 | + css('h3.fn').each do |node| |
| 56 | + header = node.clone |
| 57 | + |
| 58 | + # Skip typenames |
| 59 | + next if header.content.strip.start_with? 'typename ' |
| 60 | + |
| 61 | + # Remove leading <a name=""> |
| 62 | + header.children.css('a[name]').remove |
| 63 | + |
| 64 | + # Remove leading <code> tag (virtual/static/… attributes) |
| 65 | + code = header.children.first |
| 66 | + code.remove if code.name == 'code' |
| 67 | + |
| 68 | + # Remove leading ‘const’ |
| 69 | + header.children.first.remove if header.content.strip.start_with? 'const ' |
| 70 | + |
| 71 | + # Remove return type |
| 72 | + returnType = header.children.first |
| 73 | + returnType.remove if returnType['class'] == 'type' |
| 74 | + |
| 75 | + title = header.content.strip |
| 76 | + |
| 77 | + # Remove leading '&'/'*' |
| 78 | + title[0] = '' if title[0] == '&' || title[0] == '*' |
| 79 | + |
| 80 | + # Ignore operator overloads |
| 81 | + next if title.start_with? 'operator' |
| 82 | + |
| 83 | + # Remove function parameters |
| 84 | + title.sub! %r{\(.*\)}, '()' |
| 85 | + |
| 86 | + # Remove template generics |
| 87 | + title.sub! %r{^<.*> }, '' |
| 88 | + |
| 89 | + # Remove ‘const’ at the end |
| 90 | + title.sub! %r{ const$}, '' |
| 91 | + |
| 92 | + # Enum/typedef formatting |
| 93 | + title.sub! %r{(enum|typedef) (.*)}, '\2 (\1)' |
| 94 | + |
| 95 | + # Remove property type |
| 96 | + title = "#{displayedClassName}::#{title}" if title.sub! %r{ : .*$}, '' |
| 97 | + |
| 98 | + # Replace the class name by the alternative class name if available |
| 99 | + title.sub! className, displayedClassName if alternativeClassName |
| 100 | + |
| 101 | + unless titles.include? title # Remove duplicates (function overloading) |
| 102 | + entries << [title, header['id']] |
| 103 | + titles.push title |
| 104 | + end |
| 105 | + end |
| 106 | + |
| 107 | + # QML properties/functions |
| 108 | + qmlTypeName = at_css('h1.title').content.sub ' QML Type', '' |
| 109 | + css('.qmlproto').each do |node| |
| 110 | + title = node.content.strip |
| 111 | + id = node.at_css('tr')['id'] |
| 112 | + |
| 113 | + # Remove options |
| 114 | + title.sub! %r{^\[.*\] }, '' |
| 115 | + |
| 116 | + # Remove function parameters |
| 117 | + title.sub! %r{\(.*\)}, '()' |
| 118 | + |
| 119 | + # Remove property type |
| 120 | + title.sub! %r{ : .*$}, '' |
| 121 | + |
| 122 | + # Remove return type |
| 123 | + title.sub! %r{.* }, '' |
| 124 | + |
| 125 | + # Remove return type |
| 126 | + title.sub! %r{.* }, '' |
| 127 | + |
| 128 | + title = "#{qmlTypeName}.#{title.strip}" |
| 129 | + unless titles.include? title # Remove duplicates (function overloading) |
| 130 | + entries << [title, id] |
| 131 | + titles.push title |
| 132 | + end |
| 133 | + end |
| 134 | + |
| 135 | + entries |
| 136 | + end |
| 137 | + end |
| 138 | + end |
| 139 | +end |
0 commit comments