Skip to content

Commit 67b5e3c

Browse files
NicolappsThibaut
authored andcommitted
Add Qt scraper
1 parent d022785 commit 67b5e3c

10 files changed

Lines changed: 352 additions & 0 deletions

File tree

assets/javascripts/templates/pages/about_tmpl.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ credits = [
575575
'2009-2017 Kristopher Michael Kowal',
576576
'MIT',
577577
'https://raw.githubusercontent.com/kriskowal/q/master/LICENSE'
578+
], [
579+
'Qt',
580+
'2012-2018 The Qt Company Ltd',
581+
'GFDL',
582+
'https://doc.qt.io/qt-5/licensing.html'
578583
], [
579584
'Ramda',
580585
'2013-2016 Scott Sauyet and Michael Hurley',

assets/stylesheets/application-dark.css.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
'pages/postgres',
8484
'pages/pug',
8585
'pages/python',
86+
'pages/qt',
8687
'pages/ramda',
8788
'pages/rdoc',
8889
'pages/react_native',

assets/stylesheets/application.css.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
'pages/postgres',
8484
'pages/pug',
8585
'pages/python',
86+
'pages/qt',
8687
'pages/ramda',
8788
'pages/rdoc',
8889
'pages/react_native',

assets/stylesheets/pages/_qt.scss

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
._qt {
2+
@extend %simple;
3+
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+
55+
// Function headers
56+
h3.fn code {
57+
@extend %label;
58+
float: right;
59+
font-size: .8em;
60+
padding: 0;
61+
margin-right: -.5em;
62+
}
63+
}

lib/docs/filters/qt/clean_html.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Docs
2+
class Qt
3+
class CleanHtmlFilter < Filter
4+
def call
5+
# Remove unneeded elements
6+
css('.copy-notice, .navigationbar, .headerNavi, .footerNavi, .sidebar, .toc, #ec_toggle').remove
7+
8+
# QML property/method header
9+
css('.qmlproto').each do |node|
10+
id = node.at_css('tr')['id']
11+
node.inner_html = node.at_css('td').inner_html
12+
node.name = 'h3'
13+
node.add_class '_qml_header'
14+
node['id'] = id
15+
end
16+
17+
doc
18+
end
19+
end
20+
end
21+
end

lib/docs/filters/qt/entries.rb

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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

lib/docs/scrapers/qt.rb

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
module Docs
2+
class Qt < UrlScraper
3+
self.name = 'Qt'
4+
self.type = 'qt'
5+
self.initial_paths = %w(classes.html qmltypes.html)
6+
self.root_path = 'index.html'
7+
self.links = {
8+
home: 'https://www.qt.io',
9+
code: 'https://code.qt.io/cgit/'
10+
}
11+
12+
html_filters.push 'qt/entries', 'qt/clean_html'
13+
14+
options[:container] = '.main'
15+
16+
options[:skip_patterns] = [
17+
# License, copyright attributions
18+
/3rdparty/,
19+
/attribution/,
20+
/license/,
21+
/licensing/,
22+
23+
# Examples, guides, tutorials
24+
/example/,
25+
/guide$/,
26+
/tutorial/,
27+
/porting/,
28+
/usecase/,
29+
/topic/,
30+
/^modelview/,
31+
/deploy(ing|ment)/,
32+
/building/,
33+
34+
# Old versions, changelog
35+
/obsolete/,
36+
/compatibility/,
37+
/^whatsnew/,
38+
/^newclasses/,
39+
40+
# Deprecated modules
41+
/(qtopengl|qgl)/,
42+
/qt?script/,
43+
44+
# Indexes
45+
/members/,
46+
/module/,
47+
/overview/,
48+
/^qopenglfunctions/,
49+
50+
# Tooling
51+
/^(qt)?(linguist|assistant|qdbusviewer)/,
52+
]
53+
54+
options[:skip] = [
55+
"qt5-intro.html",
56+
"compatmap.html",
57+
58+
# Indexes
59+
"classes.html",
60+
"qtmodules.html",
61+
"modules-qml.html",
62+
"modules-cpp.html",
63+
"functions.html",
64+
"namespaces.html",
65+
"qmltypes.html",
66+
"qt3d-qml.html",
67+
"qmlbasictypes.html",
68+
"guibooks.html",
69+
"annotated.html",
70+
"overviews-main.html",
71+
"reference-overview.html",
72+
73+
# Tutorials
74+
"qtvirtualkeyboard-build.html",
75+
76+
# Copyright
77+
"trademarks.html",
78+
"lgpl.html",
79+
"bughowto.html",
80+
81+
# Changelogs
82+
"changes.html",
83+
"qtlocation-changes.html",
84+
"sourcebreaks.html",
85+
86+
# Best practice guides
87+
"accessible.html",
88+
"accessible-qtquick.html",
89+
"sharedlibrary.html",
90+
"exceptionsafety.html",
91+
"scalability.html",
92+
"session.html",
93+
"appicon.html",
94+
"accelerators.html",
95+
96+
# Other
97+
"ecmascript.html",
98+
"qtremoteobjects-interaction.html",
99+
]
100+
101+
options[:attribution] = <<-HTML
102+
&copy; The Qt Company Ltd<br>
103+
Licensed under the GNU Free Documentation License, Version 1.3.
104+
HTML
105+
106+
version '5.11' do
107+
self.release = '5.11'
108+
self.base_url = 'https://doc.qt.io/qt-5/'
109+
end
110+
111+
version '5.9' do
112+
self.release = '5.9'
113+
self.base_url = 'https://doc.qt.io/qt-5.9/'
114+
end
115+
116+
version '5.6' do
117+
self.release = '5.6'
118+
self.base_url = 'https://doc.qt.io/qt-5.6/'
119+
end
120+
end
121+
end

public/icons/docs/qt/16.png

456 Bytes
Loading

public/icons/docs/qt/16@2x.png

986 Bytes
Loading

public/icons/docs/qt/SOURCE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://commons.wikimedia.org/wiki/File:Qt_logo_2016.svg

0 commit comments

Comments
 (0)