Skip to content

Commit 0429e07

Browse files
jmerleThibaut
authored andcommitted
Add Dart documentation
1 parent 4e56a77 commit 0429e07

11 files changed

Lines changed: 187 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
@@ -215,6 +215,11 @@ credits = [
215215
'2010-2018 Michael Bostock',
216216
'BSD',
217217
'https://raw.githubusercontent.com/d3/d3/master/LICENSE'
218+
], [
219+
'Dart',
220+
'2012 the Dart project authors',
221+
'CC BY-SA',
222+
'https://creativecommons.org/licenses/by-sa/4.0/'
218223
], [
219224
'Django',
220225
'Django Software Foundation and individual contributors',

assets/javascripts/vendor/prism.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,3 +2113,27 @@ Prism.languages.yaml = {
21132113
'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./
21142114
};
21152115

2116+
Prism.languages.dart = Prism.languages.extend('clike', {
2117+
'string': [
2118+
{
2119+
pattern: /r?("""|''')[\s\S]*?\1/,
2120+
greedy: true
2121+
},
2122+
{
2123+
pattern: /r?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/,
2124+
greedy: true
2125+
}
2126+
],
2127+
'keyword': [
2128+
/\b(?:async|sync|yield)\*/,
2129+
/\b(?:abstract|assert|async|await|break|case|catch|class|const|continue|default|deferred|do|dynamic|else|enum|export|external|extends|factory|final|finally|for|get|if|implements|import|in|library|new|null|operator|part|rethrow|return|set|static|super|switch|this|throw|try|typedef|var|void|while|with|yield)\b/
2130+
],
2131+
'operator': /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/
2132+
});
2133+
2134+
Prism.languages.insertBefore('dart','function',{
2135+
'metadata': {
2136+
pattern: /@\w+/,
2137+
alias: 'symbol'
2138+
}
2139+
});

assets/stylesheets/application-dark.css.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
'pages/crystal',
4747
'pages/d',
4848
'pages/d3',
49+
'pages/dart',
4950
'pages/dojo',
5051
'pages/drupal',
5152
'pages/elixir',

assets/stylesheets/application.css.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
'pages/crystal',
4747
'pages/d',
4848
'pages/d3',
49+
'pages/dart',
4950
'pages/dojo',
5051
'pages/drupal',
5152
'pages/elixir',
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
._dart {
2+
@extend %simple;
3+
4+
dl:not(.dl-horizontal) dt, .multi-line-signature {
5+
@extend %note, %note-blue;
6+
padding: 1px 0.5rem 2px 0.5rem;
7+
8+
.features {
9+
float: right;
10+
}
11+
}
12+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module Docs
2+
class Dart
3+
class CleanHtmlFilter < Filter
4+
def call
5+
# Move the title into the main content node in the v1 docs
6+
title = at_css('h1.title')
7+
unless title.nil?
8+
name = title.children.last.content.strip
9+
kind = title.at_css('.kind').content
10+
at_css('.main-content').prepend_child("<h1>#{name} #{kind}</h1>")
11+
end
12+
13+
# Add a title to the homepage of the v2 docs
14+
if subpath == 'index.html' && at_css('.main-content > h1').nil?
15+
at_css('.main-content').prepend_child('<h1>Dart SDK</h1>')
16+
end
17+
18+
# Add the library to the main content (it is not always visible in the menu entry)
19+
breadcrumbs = at_css('.breadcrumbs').css('li:not(.self-crumb) > a')
20+
if breadcrumbs.length > 1
21+
library = breadcrumbs[1].content
22+
23+
# Generate the link to the homepage of the library
24+
with_hypens = library.gsub(/:/, '-')
25+
location = "#{'../' * subpath.count('/')}#{with_hypens}/#{with_hypens}-library"
26+
link = "<a href=\"#{location}\" class=\"_links-link\">#{library}</span>"
27+
28+
# Add the link to the main title, just like how the "Homepage" and "Source code" links appear
29+
at_css('.main-content').prepend_child("<p class=\"_links\">#{link}</p>")
30+
end
31+
32+
# Extract the actual content
33+
# We can't use options[:container] here because the entries filter uses the breadcrumbs node
34+
@doc = at_css('.main-content')
35+
36+
# Move the features (i.e. "read-only, inherited") into the blue header
37+
css('.features').each do |node|
38+
header = node.xpath('parent::dd/preceding::dt').last
39+
header.add_child node unless header.nil?
40+
end
41+
42+
# Make code blocks detectable by Prism
43+
css('pre').each do |node|
44+
node['data-language'] = 'dart'
45+
end
46+
47+
doc
48+
end
49+
end
50+
end
51+
end

lib/docs/filters/dart/entries.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module Docs
2+
class Dart
3+
class EntriesFilter < Docs::EntriesFilter
4+
def get_name
5+
title = get_title
6+
kind = get_kind
7+
8+
breadcrumbs = at_css('.breadcrumbs').css('li:not(.self-crumb) > a')
9+
first_part = ''
10+
11+
if breadcrumbs.length == 2 && !kind.include?('class')
12+
first_part = breadcrumbs[1].content
13+
elsif breadcrumbs.length == 3
14+
first_part = breadcrumbs[2].content
15+
end
16+
17+
separator = ''
18+
unless first_part.empty?
19+
if kind.include?('class')
20+
separator = ':'
21+
else
22+
separator = '.'
23+
end
24+
end
25+
26+
first_part + separator + title
27+
end
28+
29+
def get_type
30+
at_css('.breadcrumbs > li:nth-child(2)').content.split(' ')[0]
31+
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
56+
end
57+
end
58+
end

lib/docs/scrapers/dart.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Docs
2+
class Dart < FileScraper
3+
self.type = 'dart'
4+
self.root_path = 'index.html'
5+
self.links = {
6+
home: 'https://www.dartlang.org/',
7+
code: 'https://github.com/dart-lang/sdk'
8+
}
9+
10+
html_filters.push 'dart/entries', 'dart/clean_html'
11+
12+
options[:fix_urls] = ->(url) do
13+
# localhost/dart-web_audio/..dart-io/dart-io-library.html > localhost/dart-io/dart-io-library.html
14+
url.sub(/(([^\/]+)\/\.\.)/, '')
15+
end
16+
17+
options[:attribution] = <<-HTML
18+
&copy; 2012, the Dart project authors<br>
19+
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
20+
HTML
21+
22+
# Download the documentation from https://www.dartlang.org/tools/sdk/archive
23+
24+
version '1' do
25+
self.release = '1.24.3'
26+
self.dir = '/home/jasper/Documents/dart-docs-1.24.3'
27+
end
28+
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'
32+
end
33+
end
34+
end

public/icons/docs/dart/16.png

1.1 KB
Loading

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

4.12 KB
Loading

0 commit comments

Comments
 (0)