Skip to content

Commit 17964b6

Browse files
committed
Finish Dart scraper
1 parent e8a20a8 commit 17964b6

12 files changed

Lines changed: 44 additions & 38 deletions

File tree

assets/images/docs-2.png

407 Bytes
Loading

assets/images/docs-2@2x.png

690 Bytes
Loading

assets/javascripts/news.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
[
22
[
3+
"2018-08-06",
4+
"New documentation: <a href=\"/dart/\">Dart</a>"
5+
], [
36
"2018-07-29",
47
"New documentations: <a href=\"/bash/\">Bash</a>, <a href=\"/graphite/\">Graphite</a> and <a href=\"/pygame/\">Pygame</a>"
58
], [

assets/stylesheets/global/_icons.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,4 @@
176176
._icon-terraform:before { background-position: -4rem -3rem; @extend %doc-icon-2; }
177177
._icon-pygame:before { background-position: -5rem -3rem; @extend %doc-icon-2; }
178178
._icon-bash:before { background-position: -6rem -3rem; @extend %doc-icon-2; }
179+
._icon-dart:before { background-position: -7rem -3rem; @extend %doc-icon-2; }

assets/stylesheets/pages/_dart.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
@extend %simple;
33

44
dl:not(.dl-horizontal) dt, .multi-line-signature {
5-
@extend %note, %note-blue;
6-
padding: 1px 0.5rem 2px 0.5rem;
5+
@extend %block-label;
76

87
.features {
98
float: right;
9+
color: $textColorLight;
1010
}
1111
}
1212
}

lib/docs/filters/dart/clean_html.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class CleanHtmlFilter < Filter
44
def call
55
# Move the title into the main content node in the v1 docs
66
title = at_css('h1.title')
7-
unless title.nil?
7+
if title
88
name = title.children.last.content.strip
99
kind = title.at_css('.kind').content
1010
at_css('.main-content').prepend_child("<h1>#{name} #{kind}</h1>")
@@ -39,11 +39,26 @@ def call
3939
header.add_child node unless header.nil?
4040
end
4141

42+
css('section').each do |node|
43+
if node['id'] && node.first_element_child
44+
node.first_element_child['id'] ||= node['id']
45+
end
46+
47+
node.before(node.children).remove
48+
end
49+
50+
css('span').each do |node|
51+
node.before(node.children).remove
52+
end
53+
4254
# Make code blocks detectable by Prism
4355
css('pre').each do |node|
4456
node['data-language'] = 'dart'
57+
node.content = node.content
4558
end
4659

60+
css('.properties', '.property', '.callables', '.callable').remove_attr('class')
61+
4762
doc
4863
end
4964
end

lib/docs/filters/dart/entries.rb

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ module Docs
22
class Dart
33
class EntriesFilter < Docs::EntriesFilter
44
def get_name
5-
title = get_title
6-
kind = get_kind
5+
title = at_css('h1.title')
6+
if title # v1
7+
name = title.element_children.last.content.strip
8+
kind = title.at_css('.kind').content
9+
else # v2
10+
title = at_css('.main-content > h1')
11+
name = title.content[/(.*)( )/, 1].split(' top-level')[0]
12+
kind = title.content[/(.*)( )(.+)/, 3]
13+
end
714

815
breadcrumbs = at_css('.breadcrumbs').css('li:not(.self-crumb) > a')
916
first_part = ''
@@ -15,6 +22,7 @@ def get_name
1522
end
1623

1724
separator = ''
25+
1826
unless first_part.empty?
1927
if kind.include?('class')
2028
separator = ':'
@@ -23,36 +31,12 @@ def get_name
2331
end
2432
end
2533

26-
first_part + separator + title
34+
"#{first_part}#{separator}#{name}"
2735
end
2836

2937
def get_type
3038
at_css('.breadcrumbs > li:nth-child(2)').content.split(' ')[0]
3139
end
32-
33-
def get_title
34-
title = at_css('h1.title')
35-
36-
if not title.nil?
37-
# v1
38-
title.children.last.content.strip
39-
else
40-
# v2
41-
at_css('.main-content > h1').content[/(.*)( )/, 1].split(' top-level')[0]
42-
end
43-
end
44-
45-
def get_kind
46-
title = at_css('h1.title')
47-
48-
if not title.nil?
49-
# v1
50-
title.at_css('.kind').content
51-
else
52-
# v2
53-
at_css('.main-content > h1').content[/(.*)( )(.+)/, 3]
54-
end
55-
end
5640
end
5741
end
5842
end

lib/docs/scrapers/dart.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,27 @@ class Dart < FileScraper
1111

1212
options[:fix_urls] = ->(url) do
1313
# localhost/dart-web_audio/..dart-io/dart-io-library.html > localhost/dart-io/dart-io-library.html
14-
url.sub(/(([^\/]+)\/\.\.)/, '')
14+
url.remove!(/[^\/]+\/\.\./)
15+
url
1516
end
1617

1718
options[:attribution] = <<-HTML
18-
&copy; 2012, the Dart project authors<br>
19+
&copy; 2012 the Dart project authors<br>
1920
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
2021
HTML
2122

2223
# Download the documentation from https://www.dartlang.org/tools/sdk/archive
2324

24-
version '1' do
25-
self.release = '1.24.3'
26-
self.dir = '/home/jasper/Documents/dart-docs-1.24.3'
25+
version '2' do
26+
self.release = '2.0.0'
27+
self.dir = '/Users/Thibaut/DevDocs/Docs/Dart2'
28+
self.base_url = "https://api.dartlang.org/stable/#{release}/"
2729
end
2830

29-
version '2' do
30-
self.release = '2.0.0-dev.68.0'
31-
self.dir = '/home/jasper/Documents/dart-docs-2.0.0-dev.68.0'
31+
version '1' do
32+
self.release = '1.24.3'
33+
self.dir = '/Users/Thibaut/DevDocs/Docs/Dart1'
34+
self.base_url = "https://api.dartlang.org/stable/#{release}/"
3235
end
3336
end
3437
end

public/icons/docs-2.pxm

30.1 KB
Binary file not shown.

public/icons/docs-2@2x.pxm

27.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)