From 0429e077611c30a3202017def8a4a580a54f5326 Mon Sep 17 00:00:00 2001 From: Jasper van Merle Date: Fri, 13 Jul 2018 16:26:02 +0200 Subject: [PATCH] Add Dart documentation --- .../templates/pages/about_tmpl.coffee | 5 ++ assets/javascripts/vendor/prism.js | 24 ++++++++ assets/stylesheets/application-dark.css.scss | 1 + assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_dart.scss | 12 ++++ lib/docs/filters/dart/clean_html.rb | 51 +++++++++++++++ lib/docs/filters/dart/entries.rb | 58 ++++++++++++++++++ lib/docs/scrapers/dart.rb | 34 ++++++++++ public/icons/docs/dart/16.png | Bin 0 -> 1129 bytes public/icons/docs/dart/16@2x.png | Bin 0 -> 4217 bytes public/icons/docs/dart/SOURCE | 1 + 11 files changed, 187 insertions(+) create mode 100644 assets/stylesheets/pages/_dart.scss create mode 100644 lib/docs/filters/dart/clean_html.rb create mode 100644 lib/docs/filters/dart/entries.rb create mode 100644 lib/docs/scrapers/dart.rb create mode 100644 public/icons/docs/dart/16.png create mode 100644 public/icons/docs/dart/16@2x.png create mode 100644 public/icons/docs/dart/SOURCE 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 0000000000000000000000000000000000000000..3272c1d7648b62aedb7a62ebd9ce9835b0a476f8 GIT binary patch literal 1129 zcmZuvO=uHQ5T1FP#%7b4q#Ly~2Cc1WlVV$=!6wwwhJ>~vLHt4L!5_qf2cam42k{^% zcoA=csCe-t3VIPQ5)~sJ`~eT`q4-yOC{;8TEp4{@oVS~oY-47boq6AU^S$?G_sX8! zuvcwS0l+&tlG#hqFTBx7?+x?(7zNk($k-VGwD5eh`=~?3#0r4)6|`BvQ0$`AxtLPrNTA7@Hh2q>Qe%%uq>OA)3F>4&euyt zJqwSHo7b_9cL&%gnPLD_NwY540-5qN2fv(Rj%zbxT z%_~JLAqazm_tU%@P7^?%9$lg!Ex2v#n&6h$Z>v?DKxUMeXN25{GaAg{a+4yPWeoQA ztk$}_{>XK`C}v;|O-#7f1funHyS1+954v}yZ09m==wnowlGQ3rA^^d7ucpO1r)?UQ zB7=J;XAA{~XtXnuP*-GoJRFE@o{+msuJs?>J@E}1SsIPykFp>{>@K!k+n0#?+S}e% zwx^^zT3QS|<6%JloYIZtm7@Jb9KrbVB0n(u?)@wp^a!He(ghyk2IL8Ax8owO2r1B- yPvU2RSyvEQ*`B6w1{n+zd6In5?nGG>&Wx(o_`dr`rZ0Cq6z!wgT;@Ug=*55V48VT? literal 0 HcmV?d00001 diff --git a/public/icons/docs/dart/16@2x.png b/public/icons/docs/dart/16@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..cad29d188f36091e768731a47a711bbf87f18f3b GIT binary patch literal 4217 zcmb_fU1(fI6h1S1v)P|C*}tT25~Z}5CfO9zO>Hf9X_QDCZG(s_RYX*ohY&z$)eyWqsZ=T8EJ3^;u;!~XIT&@%x_EHpTU36Ei- zur1jl6L4TU!+x~cU55=5$jpj%jl(I7^aeJ2Vl}}cR-|DPbqRP#ye<;11lF0@GYLlm zJ3hGfdVXQ?MXvc;80XE{nt<_U&Y7PxUo&pJCdL@{Oj9$GE=0+~ec%s=?}j!fM!$b5 zI%~(taW#SLr|koW_kTJ6>z{$88#mJxU^P_EIrRcJ0*U7L=Y(z?TKnvkADnR9Zsc4) zZWN4QXC{-5Y}@(=gW}JQt2ZVulEUh0T-OWVz>PCixw*~vEa8yAMrOyK0cy*<(G z56-KOc>JJNvtUak(ALI*f9piTN`U$3h_wkrr_0Qg&5u0X9qa4K(SQ=y6FWv$0{t9G zR0tfN3~??_Py(Sd++>wh9lLkMror~I6+OrhRN4>O-ia5GglNsz8tc2$qE%ho*}a;7c!|u}eDJDi;3=>?0(FjbBms$mezQ8XX7_d5J*{KR8{p8taeis~Af!_?7>_~v>`MW~Jq#3;Kab`G*ws(-C)P!#!gR7|E?yazr% zdd?755-QLOiH@PcrdX;suP#E3MY=jyBtTY^1bfp27={I8+UT!AX&*|5qrKbjNVwbT zX})+BOXT&hu8M)N+pV$4lm2AV@$FaZ(orkb(%l)ozhXTr!^2@vY% zuYU?W`hvgZ{_eea9nd|oZV7jFwHEUE-