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 @@
1[1[
2 [2 [
3 "2018-08-06",3 "2018-08-12",
4 "New documentation: <a href=\"/dart/\">Dart</a>"4 "New documentations: <a href=\"/dart/\">Dart</a> and <a href=\"/qt/\">Qt</a>"
5 ], [5 ], [
6 "2018-07-29",6 "2018-07-29",
7 "New documentations: <a href=\"/bash/\">Bash</a>, <a href=\"/graphite/\">Graphite</a> and <a href=\"/pygame/\">Pygame</a>"7 "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
177._icon-pygame:before { background-position: -5rem -3rem; @extend %doc-icon-2; }177._icon-pygame:before { background-position: -5rem -3rem; @extend %doc-icon-2; }
178._icon-bash:before { background-position: -6rem -3rem; @extend %doc-icon-2; }178._icon-bash:before { background-position: -6rem -3rem; @extend %doc-icon-2; }
179._icon-dart:before { background-position: -7rem -3rem; @extend %doc-icon-2; }179._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 @@
1._qt {1._qt {
2 @extend %simple;2 @extend %simple;
3 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 headers4 // Function headers
56 h3.fn code {5 h3.fn > code {
57 @extend %label;
58 float: right;6 float: right;
59 font-size: .8em;7 color: $textColorLight;
60 padding: 0;
61 margin-right: -.5em;
62 }8 }
63}9}
lib/docs/filters/qt/clean_html.rb+12−2
@@ -3,17 +3,27 @@ module Docs · 2 unmodified lines
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 # Remove unneeded elements5 # Remove unneeded elements
6 css('.copy-notice, .navigationbar, .headerNavi, .footerNavi, .sidebar, .toc, #ec_toggle').remove6 css('.copy-notice, .navigationbar, .headerNavi, .footerNavi, .sidebar, .toc, #ec_toggle', '.landingicons img', 'br').remove
7 7
8 # QML property/method header8 # QML property/method header
9 css('.qmlproto').each do |node|9 css('.qmlproto').each do |node|
10 id = node.at_css('tr')['id']10 id = node.at_css('tr')['id']
11 node.inner_html = node.at_css('td').inner_html11 node.inner_html = node.at_css('td').inner_html
12 node.name = 'h3'12 node.name = 'h3'
13 node.add_class '_qml_header'
14 node['id'] = id13 node['id'] = id
15 end14 end
16 15
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
17 doc27 doc
18 end28 end
19 end29 end
lib/docs/filters/qt/entries.rb+26−24
@@ -1,3 +1,5 @@
1# frozen_string_literal: true
2
1module Docs3module Docs
2 class Qt4 class Qt
3 class EntriesFilter < Docs::EntriesFilter5 class EntriesFilter < Docs::EntriesFilter
@@ -9,7 +11,7 @@ module Docs · 5 unmodified lines
9 name.sub! %r{ QML Basic Type$}, ' (QML basic type)'11 name.sub! %r{ QML Basic Type$}, ' (QML basic type)'
10 12
11 # Add '(class)' to the class pages where the subtitle name is used (e.g. qset-const-iterator.html)13 # 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)')
13 name = "#{name} (class) "15 name = "#{name} (class) "
14 end16 end
15 17
@@ -19,34 +21,34 @@ module Docs · 3 unmodified lines
19 def get_type21 def get_type
20 breadcrumb = css('#main_title_bar + ul li')22 breadcrumb = css('#main_title_bar + ul li')
21 category = if breadcrumb.length < 323 category = if breadcrumb.length < 3
22 then 'Qt'24 then 'Qt'.dup
23 else breadcrumb.at(1).content25 else breadcrumb.at(1).content
24 end26 end
25 27
26 if category == 'Qt'28 if category == 'Qt'
27 return 'Qt Platforms' if name.include? ' for ' or name == 'Qt Platform Abstraction'29 return 'Qt Platforms' if name.include?(' for ') || name == 'Qt Platform Abstraction'
28 return 'Qt Quick' if name == 'Qt Quick Test' or name == 'Qt Quick Test Reference Documentation'30 return 'Qt Quick' if name == 'Qt Quick Test' || name == 'Qt Quick Test Reference Documentation'
29 31
30 alwaysInQt = ["Qt Configure Options", "Qt Image Formats"]32 alwaysInQt = ['Qt Configure Options', 'Qt Image Formats']
31 category = name if name.start_with?('Qt ') && !alwaysInQt.include?(name)33 category = name if name.start_with?('Qt ') && !alwaysInQt.include?(name)
32 end34 end
33 35
34 qtPlatformsTypes = ['Qt Platform Headers', 'Qt Android Extras', 'Qt Mac Extras', 'Qt Windows Extras', 'Qt X11 Extras']36 qtPlatformsTypes = ['Qt Platform Headers', 'Qt Android Extras', 'Qt Mac Extras', 'Qt Windows Extras', 'Qt X11 Extras']
35 return 'Qt Platforms' if qtPlatformsTypes.include? category37 return 'Qt Platforms' if qtPlatformsTypes.include?(category)
36 38
37 category.sub! ' Manual', ''39 category.remove!(' Manual')
38 category40 category
39 end41 end
40 42
41 def include_default_entry?43 def include_default_entry?
42 name != 'All Classes' and name != 'All QML Types'44 name != 'All Classes' && name != 'All QML Types'
43 end45 end
44 46
45 def additional_entries47 def additional_entries
46 entries = []48 entries = []
47 titles = []49 titles = []
48 50
49 className = at_css('h1.title').content.strip.sub ' Class', ''51 className = at_css('h1.title').content.strip.remove(' Class')
50 displayedClassName = className52 displayedClassName = className
51 alternativeClassName = at_css('h1.title + .small-subtitle a')53 alternativeClassName = at_css('h1.title + .small-subtitle a')
52 displayedClassName = alternativeClassName.content if alternativeClassName54 displayedClassName = alternativeClassName.content if alternativeClassName
@@ -56,7 +58,7 @@ module Docs · 3 unmodified lines
56 header = node.clone58 header = node.clone
57 59
58 # Skip typenames60 # Skip typenames
59 next if header.content.strip.start_with? 'typename '61 next if header.content.strip.start_with?('typename ')
60 62
61 # Remove leading <a name="">63 # Remove leading <a name="">
62 header.children.css('a[name]').remove64 header.children.css('a[name]').remove
@@ -66,7 +68,7 @@ module Docs · 3 unmodified lines
66 code.remove if code.name == 'code'68 code.remove if code.name == 'code'
67 69
68 # Remove leading ‘const’70 # 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 ')
70 72
71 # Remove return type73 # Remove return type
72 returnType = header.children.first74 returnType = header.children.first
@@ -78,57 +80,57 @@ module Docs · 5 unmodified lines
78 title[0] = '' if title[0] == '&' || title[0] == '*'80 title[0] = '' if title[0] == '&' || title[0] == '*'
79 81
80 # Ignore operator overloads82 # Ignore operator overloads
81 next if title.start_with? 'operator'83 next if title.start_with?('operator')
82 84
83 # Remove function parameters85 # Remove function parameters
84 title.sub! %r{\(.*\)}, '()'86 title.sub! %r{\(.*\)}, '()'
85 87
86 # Remove template generics88 # Remove template generics
87 title.sub! %r{^<.*> }, ''89 title.remove!(%r{^<.*> })
88 90
89 # Remove ‘const’ at the end91 # Remove ‘const’ at the end
90 title.sub! %r{ const$}, ''92 title.remove!(%r{ const$})
91 93
92 # Enum/typedef formatting94 # Enum/typedef formatting
93 title.sub! %r{(enum|typedef) (.*)}, '\2 (\1)'95 title.sub! %r{(enum|typedef) (.*)}, '\2 (\1)'
94 96
95 # Remove property type97 # Remove property type
96 title = "#{displayedClassName}::#{title}" if title.sub! %r{ : .*$}, ''98 title = "#{displayedClassName}::#{title}" if title.sub!(%r{ : .*$}, '')
97 99
98 # Replace the class name by the alternative class name if available100 # Replace the class name by the alternative class name if available
99 title.sub! className, displayedClassName if alternativeClassName101 title = title.sub(className, displayedClassName) if alternativeClassName
100 102
101 unless titles.include? title # Remove duplicates (function overloading)103 unless titles.include?(title) # Remove duplicates (function overloading)
102 entries << [title, header['id']]104 entries << [title, header['id']]
103 titles.push title105 titles.push title
104 end106 end
105 end107 end
106 108
107 # QML properties/functions109 # QML properties/functions
108 qmlTypeName = at_css('h1.title').content.sub ' QML Type', ''110 qmlTypeName = at_css('h1.title').content.remove(' QML Type', '')
109 css('.qmlproto').each do |node|111 css('.qmlproto').each do |node|
110 title = node.content.strip112 title = node.content.strip
111 id = node.at_css('tr')['id']113 id = node.at_css('tr')['id']
112 114
113 # Remove options115 # Remove options
114 title.sub! %r{^\[.*\] }, ''116 title.remove!(%r{^\[.*\] })
115 117
116 # Remove function parameters118 # Remove function parameters
117 title.sub! %r{\(.*\)}, '()'119 title.sub! %r{\(.*\)}, '()'
118 120
119 # Remove property type121 # Remove property type
120 title.sub! %r{ : .*$}, ''122 title.remove!(%r{ : .*$})
121 123
122 # Remove return type124 # Remove return type
123 title.sub! %r{.* }, ''125 title.remove!(%r{.* })
124 126
125 # Remove return type127 # Remove return type
126 title.sub! %r{.* }, ''128 title.remove!(%r{.* })
127 129
128 title = "#{qmlTypeName}.#{title.strip}"130 title = "#{qmlTypeName}.#{title.strip}"
129 unless titles.include? title # Remove duplicates (function overloading)131 unless titles.include?(title) # Remove duplicates (function overloading)
130 entries << [title, id]132 entries << [title, id]
131 titles.push title133 titles.push(title)
132 end134 end
133 end135 end
134 136
lib/docs/scrapers/qt.rb+1−1
@@ -12,7 +12,7 @@ module Docs · 11 unmodified lines
12 html_filters.push 'qt/entries', 'qt/clean_html'12 html_filters.push 'qt/entries', 'qt/clean_html'
13 13
14 options[:container] = '.main'14 options[:container] = '.main'
15 15 options[:max_image_size] = 156_000
16 options[:skip_patterns] = [16 options[:skip_patterns] = [
17 # License, copyright attributions17 # License, copyright attributions
18 /3rdparty/,18 /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.