diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index 60ed00c2..d90c338a 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -215,6 +215,11 @@ credits = [ '2010-2018 Michael Bostock', 'BSD', 'https://raw.githubusercontent.com/d3/d3/master/LICENSE' + ], [ + 'Dart', + '2012 the Dart project authors', + 'CC BY-SA', + 'https://creativecommons.org/licenses/by-sa/4.0/' ], [ 'Django', 'Django Software Foundation and individual contributors', diff --git a/assets/javascripts/vendor/prism.js b/assets/javascripts/vendor/prism.js index 3dc04a14..a99402d9 100644 --- a/assets/javascripts/vendor/prism.js +++ b/assets/javascripts/vendor/prism.js @@ -2113,3 +2113,27 @@ Prism.languages.yaml = { 'punctuation': /---|[:[\]{}\-,|>?]|\.\.\./ }; +Prism.languages.dart = Prism.languages.extend('clike', { + 'string': [ + { + pattern: /r?("""|''')[\s\S]*?\1/, + greedy: true + }, + { + pattern: /r?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/, + greedy: true + } + ], + 'keyword': [ + /\b(?:async|sync|yield)\*/, + /\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/ + ], + 'operator': /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*\/%&^|=!<>]=?|\?/ +}); + +Prism.languages.insertBefore('dart','function',{ + 'metadata': { + pattern: /@\w+/, + alias: 'symbol' + } +}); diff --git a/assets/stylesheets/application-dark.css.scss b/assets/stylesheets/application-dark.css.scss index 3d9efa6c..38346905 100644 --- a/assets/stylesheets/application-dark.css.scss +++ b/assets/stylesheets/application-dark.css.scss @@ -46,6 +46,7 @@ 'pages/crystal', 'pages/d', 'pages/d3', + 'pages/dart', 'pages/dojo', 'pages/drupal', 'pages/elixir', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index d72487c2..64916112 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -46,6 +46,7 @@ 'pages/crystal', 'pages/d', 'pages/d3', + 'pages/dart', 'pages/dojo', 'pages/drupal', 'pages/elixir', diff --git a/assets/stylesheets/pages/_dart.scss b/assets/stylesheets/pages/_dart.scss new file mode 100644 index 00000000..87159057 --- /dev/null +++ b/assets/stylesheets/pages/_dart.scss @@ -0,0 +1,12 @@ +._dart { + @extend %simple; + + dl:not(.dl-horizontal) dt, .multi-line-signature { + @extend %note, %note-blue; + padding: 1px 0.5rem 2px 0.5rem; + + .features { + float: right; + } + } +} diff --git a/lib/docs/filters/dart/clean_html.rb b/lib/docs/filters/dart/clean_html.rb new file mode 100644 index 00000000..ce1733af --- /dev/null +++ b/lib/docs/filters/dart/clean_html.rb @@ -0,0 +1,51 @@ +module Docs + class Dart + class CleanHtmlFilter < Filter + def call + # Move the title into the main content node in the v1 docs + title = at_css('h1.title') + unless title.nil? + name = title.children.last.content.strip + kind = title.at_css('.kind').content + at_css('.main-content').prepend_child("

#{name} #{kind}

") + end + + # Add a title to the homepage of the v2 docs + if subpath == 'index.html' && at_css('.main-content > h1').nil? + at_css('.main-content').prepend_child('

Dart SDK

') + end + + # Add the library to the main content (it is not always visible in the menu entry) + breadcrumbs = at_css('.breadcrumbs').css('li:not(.self-crumb) > a') + if breadcrumbs.length > 1 + library = breadcrumbs[1].content + + # Generate the link to the homepage of the library + with_hypens = library.gsub(/:/, '-') + location = "#{'../' * subpath.count('/')}#{with_hypens}/#{with_hypens}-library" + link = "#{library}" + + # Add the link to the main title, just like how the "Homepage" and "Source code" links appear + at_css('.main-content').prepend_child("

#{link}

") + end + + # Extract the actual content + # We can't use options[:container] here because the entries filter uses the breadcrumbs node + @doc = at_css('.main-content') + + # Move the features (i.e. "read-only, inherited") into the blue header + css('.features').each do |node| + header = node.xpath('parent::dd/preceding::dt').last + header.add_child node unless header.nil? + end + + # Make code blocks detectable by Prism + css('pre').each do |node| + node['data-language'] = 'dart' + end + + doc + end + end + end +end diff --git a/lib/docs/filters/dart/entries.rb b/lib/docs/filters/dart/entries.rb new file mode 100644 index 00000000..f94c451b --- /dev/null +++ b/lib/docs/filters/dart/entries.rb @@ -0,0 +1,58 @@ +module Docs + class Dart + class EntriesFilter < Docs::EntriesFilter + def get_name + title = get_title + kind = get_kind + + breadcrumbs = at_css('.breadcrumbs').css('li:not(.self-crumb) > a') + first_part = '' + + if breadcrumbs.length == 2 && !kind.include?('class') + first_part = breadcrumbs[1].content + elsif breadcrumbs.length == 3 + first_part = breadcrumbs[2].content + end + + separator = '' + unless first_part.empty? + if kind.include?('class') + separator = ':' + else + separator = '.' + end + end + + first_part + separator + title + end + + def get_type + at_css('.breadcrumbs > li:nth-child(2)').content.split(' ')[0] + end + + def get_title + title = at_css('h1.title') + + if not title.nil? + # v1 + title.children.last.content.strip + else + # v2 + at_css('.main-content > h1').content[/(.*)( )/, 1].split(' top-level')[0] + end + end + + def get_kind + title = at_css('h1.title') + + if not title.nil? + # v1 + title.at_css('.kind').content + else + # v2 + at_css('.main-content > h1').content[/(.*)( )(.+)/, 3] + end + end + end + end +end diff --git a/lib/docs/scrapers/dart.rb b/lib/docs/scrapers/dart.rb new file mode 100644 index 00000000..b06960b2 --- /dev/null +++ b/lib/docs/scrapers/dart.rb @@ -0,0 +1,34 @@ +module Docs + class Dart < FileScraper + self.type = 'dart' + self.root_path = 'index.html' + self.links = { + home: 'https://www.dartlang.org/', + code: 'https://github.com/dart-lang/sdk' + } + + html_filters.push 'dart/entries', 'dart/clean_html' + + options[:fix_urls] = ->(url) do + # localhost/dart-web_audio/..dart-io/dart-io-library.html > localhost/dart-io/dart-io-library.html + url.sub(/(([^\/]+)\/\.\.)/, '') + end + + options[:attribution] = <<-HTML + © 2012, the Dart project authors
+ Licensed under the Creative Commons Attribution-ShareAlike License v4.0. + HTML + + # Download the documentation from https://www.dartlang.org/tools/sdk/archive + + version '1' do + self.release = '1.24.3' + self.dir = '/home/jasper/Documents/dart-docs-1.24.3' + end + + version '2' do + self.release = '2.0.0-dev.68.0' + self.dir = '/home/jasper/Documents/dart-docs-2.0.0-dev.68.0' + end + end +end diff --git a/public/icons/docs/dart/16.png b/public/icons/docs/dart/16.png new file mode 100644 index 00000000..3272c1d7 Binary files /dev/null and b/public/icons/docs/dart/16.png differ diff --git a/public/icons/docs/dart/16@2x.png b/public/icons/docs/dart/16@2x.png new file mode 100644 index 00000000..cad29d18 Binary files /dev/null and b/public/icons/docs/dart/16@2x.png differ diff --git a/public/icons/docs/dart/SOURCE b/public/icons/docs/dart/SOURCE new file mode 100644 index 00000000..dd21f7e7 --- /dev/null +++ b/public/icons/docs/dart/SOURCE @@ -0,0 +1 @@ +https://github.com/dart-lang/logos