History

Finish Qt scraper

Thibaut Courouble committed 8 years ago

Commit e35298c1 parent 67b5e3c12 files · +38 −79Browse files

Unified · Split

12 files
  1. assets/images/docs-2.png +0 −0
  2. assets/images/docs-2@2x.png +0 −0
  3. assets/javascripts/news.json +2 −2
  4. assets/stylesheets/global/_icons.scss +1 −0
  5. assets/stylesheets/pages/_qt.scss +2 −56
  6. lib/docs/filters/qt/clean_html.rb +12 −2
  7. lib/docs/filters/qt/entries.rb +26 −24
  8. lib/docs/scrapers/qt.rb +1 −1
  9. public/icons/docs-2.pxm +0 −0
  10. public/icons/docs-2@2x.pxm +0 −0
  11. public/icons/docs/qt/16.png +0 −0
  12. public/icons/docs/qt/16@2x.png +0 −0
assets/images/docs-2.png+0−0

Binary file not shown.

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

Binary file not shown.

assets/javascripts/news.json+2−2
@@ -1,7 +1,7 @@
11 [
22 [
3− "2018-08-06",
4− "New documentation: <a href=\"/dart/\">Dart</a>"
3+ "2018-08-12",
4+ "New documentations: <a href=\"/dart/\">Dart</a> and <a href=\"/qt/\">Qt</a>"
55 ], [
66 "2018-07-29",
77 "New documentations: <a href=\"/bash/\">Bash</a>, <a href=\"/graphite/\">Graphite</a> and <a href=\"/pygame/\">Pygame</a>"
assets/stylesheets/global/_icons.scss+1−0
@@ -177,3 +177,4 @@ · 176 unmodified lines
177177 ._icon-pygame:before { background-position: -5rem -3rem; @extend %doc-icon-2; }
178178 ._icon-bash:before { background-position: -6rem -3rem; @extend %doc-icon-2; }
179179 ._icon-dart:before { background-position: -7rem -3rem; @extend %doc-icon-2; }
180+._icon-qt:before { background-position: -8rem -3rem; @extend %doc-icon-2; }
assets/stylesheets/pages/_qt.scss+2−56
@@ -1,63 +1,9 @@
11 ._qt {
22 @extend %simple;
33
4− h1 {
5− margin-top: 0;
6− @extend %lined-heading;
7− }
8−
9− // Home page
10− .landingicons {
11− .icons1of3 {
12− display: flex;
13− flex-wrap: wrap;
14− align-items: center;
15− margin: 1em 0;
16−
17− @if $style == 'dark' {
18− &:nth-child(3) img {
19− filter: invert(1) hue-rotate(180deg) brightness(1.5)
20− }
21− }
22− }
23−
24− h2 {
25− flex: 1;
26− margin: 0;
27− margin-left: 10px;
28− }
29−
30− h2 + p {
31− width: 100%;
32− padding-left: 70px;
33− }
34−
35− .centerAlign,
36− .centerAlign img { // Icon
37− width: 60px;
38− height: 60px;
39− margin: 0;
40− }
41− }
42−
43− // Syntax highlighting
44− .pre {
45− .operator { @extend .token, .operator; }
46− .number { @extend .token, .number; }
47− .keyword { @extend .token, .keyword; }
48− .type { @extend .token, .function; }
49− .type a { color: inherit; }
50− .pun, .comment { @extend .token, .punctuation; }
51− .kwd, .preprocessor { @extend .token, .keyword; }
52− .str, .string { @extend .token, .string; }
53− }
54−
554 // Function headers
56− h3.fn code {
57− @extend %label;
5+ h3.fn > code {
586 float: right;
59− font-size: .8em;
60− padding: 0;
61− margin-right: -.5em;
7+ color: $textColorLight;
628 }
639 }
lib/docs/filters/qt/clean_html.rb+12−2
@@ -3,17 +3,27 @@ module Docs · 2 unmodified lines
33 class CleanHtmlFilter < Filter
44 def call
55 # Remove unneeded elements
6− css('.copy-notice, .navigationbar, .headerNavi, .footerNavi, .sidebar, .toc, #ec_toggle').remove
6+ css('.copy-notice, .navigationbar, .headerNavi, .footerNavi, .sidebar, .toc, #ec_toggle', '.landingicons img', 'br').remove
77
88 # QML property/method header
99 css('.qmlproto').each do |node|
1010 id = node.at_css('tr')['id']
1111 node.inner_html = node.at_css('td').inner_html
1212 node.name = 'h3'
13− node.add_class '_qml_header'
1413 node['id'] = id
1514 end
1615
16+ css('.main-rounded', '.content', '.line', '.context', '.descr', '.types', '.func', '.table', 'div:not([class])', '.landing', '.col-1', '.heading', '.qmlitem', '.qmldoc', 'div.pre').each do |node|
17+ node.before(node.children).remove
18+ end
19+
20+ css('pre').each do |node|
21+ node.content = node.content
22+ node['data-language'] = 'cpp' if node['class'].include?('cpp')
23+ node['data-language'] = 'qml' if node['class'].include?('qml')
24+ node.remove_attribute('class')
25+ end
26+
1727 doc
1828 end
1929 end
lib/docs/filters/qt/entries.rb+26−24
@@ -1,3 +1,5 @@
1+# frozen_string_literal: true
2+
13 module Docs
24 class Qt
35 class EntriesFilter < Docs::EntriesFilter
@@ -9,7 +11,7 @@ module Docs · 5 unmodified lines
911 name.sub! %r{ QML Basic Type$}, ' (QML basic type)'
1012
1113 # 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)')
14+ if at_css('h1.title').content.strip.end_with?(' Class') && !name.include?('(class)')
1315 name = "#{name} (class) "
1416 end
1517
@@ -19,34 +21,34 @@ module Docs · 3 unmodified lines
1921 def get_type
2022 breadcrumb = css('#main_title_bar + ul li')
2123 category = if breadcrumb.length < 3
22− then 'Qt'
24+ then 'Qt'.dup
2325 else breadcrumb.at(1).content
2426 end
2527
2628 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+ return 'Qt Platforms' if name.include?(' for ') || name == 'Qt Platform Abstraction'
30+ return 'Qt Quick' if name == 'Qt Quick Test' || name == 'Qt Quick Test Reference Documentation'
2931
30− alwaysInQt = ["Qt Configure Options", "Qt Image Formats"]
32+ alwaysInQt = ['Qt Configure Options', 'Qt Image Formats']
3133 category = name if name.start_with?('Qt ') && !alwaysInQt.include?(name)
3234 end
3335
3436 qtPlatformsTypes = ['Qt Platform Headers', 'Qt Android Extras', 'Qt Mac Extras', 'Qt Windows Extras', 'Qt X11 Extras']
35− return 'Qt Platforms' if qtPlatformsTypes.include? category
37+ return 'Qt Platforms' if qtPlatformsTypes.include?(category)
3638
37− category.sub! ' Manual', ''
39+ category.remove!(' Manual')
3840 category
3941 end
4042
4143 def include_default_entry?
42− name != 'All Classes' and name != 'All QML Types'
44+ name != 'All Classes' && name != 'All QML Types'
4345 end
4446
4547 def additional_entries
4648 entries = []
4749 titles = []
4850
49− className = at_css('h1.title').content.strip.sub ' Class', ''
51+ className = at_css('h1.title').content.strip.remove(' Class')
5052 displayedClassName = className
5153 alternativeClassName = at_css('h1.title + .small-subtitle a')
5254 displayedClassName = alternativeClassName.content if alternativeClassName
@@ -56,7 +58,7 @@ module Docs · 3 unmodified lines
5658 header = node.clone
5759
5860 # Skip typenames
59− next if header.content.strip.start_with? 'typename '
61+ next if header.content.strip.start_with?('typename ')
6062
6163 # Remove leading <a name="">
6264 header.children.css('a[name]').remove
@@ -66,7 +68,7 @@ module Docs · 3 unmodified lines
6668 code.remove if code.name == 'code'
6769
6870 # Remove leading ‘const’
69− header.children.first.remove if header.content.strip.start_with? 'const '
71+ header.children.first.remove if header.content.strip.start_with?('const ')
7072
7173 # Remove return type
7274 returnType = header.children.first
@@ -78,57 +80,57 @@ module Docs · 5 unmodified lines
7880 title[0] = '' if title[0] == '&' || title[0] == '*'
7981
8082 # Ignore operator overloads
81− next if title.start_with? 'operator'
83+ next if title.start_with?('operator')
8284
8385 # Remove function parameters
8486 title.sub! %r{\(.*\)}, '()'
8587
8688 # Remove template generics
87− title.sub! %r{^<.*> }, ''
89+ title.remove!(%r{^<.*> })
8890
8991 # Remove ‘const’ at the end
90− title.sub! %r{ const$}, ''
92+ title.remove!(%r{ const$})
9193
9294 # Enum/typedef formatting
9395 title.sub! %r{(enum|typedef) (.*)}, '\2 (\1)'
9496
9597 # Remove property type
96− title = "#{displayedClassName}::#{title}" if title.sub! %r{ : .*$}, ''
98+ title = "#{displayedClassName}::#{title}" if title.sub!(%r{ : .*$}, '')
9799
98100 # Replace the class name by the alternative class name if available
99− title.sub! className, displayedClassName if alternativeClassName
101+ title = title.sub(className, displayedClassName) if alternativeClassName
100102
101− unless titles.include? title # Remove duplicates (function overloading)
103+ unless titles.include?(title) # Remove duplicates (function overloading)
102104 entries << [title, header['id']]
103105 titles.push title
104106 end
105107 end
106108
107109 # QML properties/functions
108− qmlTypeName = at_css('h1.title').content.sub ' QML Type', ''
110+ qmlTypeName = at_css('h1.title').content.remove(' QML Type', '')
109111 css('.qmlproto').each do |node|
110112 title = node.content.strip
111113 id = node.at_css('tr')['id']
112114
113115 # Remove options
114− title.sub! %r{^\[.*\] }, ''
116+ title.remove!(%r{^\[.*\] })
115117
116118 # Remove function parameters
117119 title.sub! %r{\(.*\)}, '()'
118120
119121 # Remove property type
120− title.sub! %r{ : .*$}, ''
122+ title.remove!(%r{ : .*$})
121123
122124 # Remove return type
123− title.sub! %r{.* }, ''
125+ title.remove!(%r{.* })
124126
125127 # Remove return type
126− title.sub! %r{.* }, ''
128+ title.remove!(%r{.* })
127129
128130 title = "#{qmlTypeName}.#{title.strip}"
129− unless titles.include? title # Remove duplicates (function overloading)
131+ unless titles.include?(title) # Remove duplicates (function overloading)
130132 entries << [title, id]
131− titles.push title
133+ titles.push(title)
132134 end
133135 end
134136
lib/docs/scrapers/qt.rb+1−1
@@ -12,7 +12,7 @@ module Docs · 11 unmodified lines
1212 html_filters.push 'qt/entries', 'qt/clean_html'
1313
1414 options[:container] = '.main'
15−
15+ options[:max_image_size] = 156_000
1616 options[:skip_patterns] = [
1717 # License, copyright attributions
1818 /3rdparty/,
public/icons/docs-2.pxm+0−0

Binary file not shown.

public/icons/docs-2@2x.pxm+0−0

Binary file not shown.

public/icons/docs/qt/16.png+0−0

Binary file not shown.

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

Binary file not shown.