From fcbdddc741f0e52fa3a8c73a1a16e035b1a70055 Mon Sep 17 00:00:00 2001 From: Tim Lim Date: Thu, 6 Oct 2022 21:56:31 +0800 Subject: [PATCH] Add FastAPI (0.85.0) documentation --- .../templates/pages/about_tmpl.coffee | 5 ++ assets/stylesheets/application.css.scss | 1 + assets/stylesheets/pages/_fastapi.scss | 22 +++++++ lib/docs/filters/fastapi/clean_html.rb | 32 ++++++++++ lib/docs/filters/fastapi/container.rb | 9 +++ lib/docs/filters/fastapi/entries.rb | 55 ++++++++++++++++++ lib/docs/scrapers/fastapi.rb | 30 ++++++++++ public/icons/docs/fastapi/16.png | Bin 0 -> 1364 bytes public/icons/docs/fastapi/16@2x.png | Bin 0 -> 1664 bytes public/icons/docs/fastapi/SOURCE | 1 + 10 files changed, 155 insertions(+) create mode 100644 assets/stylesheets/pages/_fastapi.scss create mode 100644 lib/docs/filters/fastapi/clean_html.rb create mode 100644 lib/docs/filters/fastapi/container.rb create mode 100644 lib/docs/filters/fastapi/entries.rb create mode 100644 lib/docs/scrapers/fastapi.rb create mode 100644 public/icons/docs/fastapi/16.png create mode 100644 public/icons/docs/fastapi/16@2x.png create mode 100644 public/icons/docs/fastapi/SOURCE diff --git a/assets/javascripts/templates/pages/about_tmpl.coffee b/assets/javascripts/templates/pages/about_tmpl.coffee index f34f861f..2a20f48a 100644 --- a/assets/javascripts/templates/pages/about_tmpl.coffee +++ b/assets/javascripts/templates/pages/about_tmpl.coffee @@ -326,6 +326,11 @@ credits = [ '2019 by Falcon contributors', 'Apache', 'https://raw.githubusercontent.com/falconry/falcon/master/LICENSE' + ], [ + 'FastAPI', + '2018 Sebastián Ramírez', + 'MIT', + 'https://github.com/tiangolo/fastapi/blob/master/LICENSE' ], [ 'Fish', '2005–2009 Axel Liljencrantz, 2009–2022 fish-shell contributors', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index 8a6221b6..e7a725e7 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -58,6 +58,7 @@ 'pages/ember', 'pages/erlang', 'pages/express', + 'pages/fastapi', 'pages/git', 'pages/github', 'pages/gnuplot', diff --git a/assets/stylesheets/pages/_fastapi.scss b/assets/stylesheets/pages/_fastapi.scss new file mode 100644 index 00000000..5f56c1ce --- /dev/null +++ b/assets/stylesheets/pages/_fastapi.scss @@ -0,0 +1,22 @@ +._fastapi { + > h2 { @extend %block-heading; } + > h3 { @extend %block-label, %label-blue; } + + code { @extend %label; } + + .tabbed-block { + border: 1px dashed black; + padding: 0.5rem 1rem 0; + margin-bottom: 1rem; + } + .tabbed-block label { + font-weight: var(--bolderFontWeight); + } + + .admonition { @extend %note; } + .admonition.tip { @extend %note-green; } + .admonition.note { @extend %note-blue; } + .admonition-title { + font-weight: var(--bolderFontWeight); + } +} diff --git a/lib/docs/filters/fastapi/clean_html.rb b/lib/docs/filters/fastapi/clean_html.rb new file mode 100644 index 00000000..f9fc7cdb --- /dev/null +++ b/lib/docs/filters/fastapi/clean_html.rb @@ -0,0 +1,32 @@ +module Docs + class Fastapi + class CleanHtmlFilter < Filter + + def call + doc.css('.headerlink').each do |node| + node.remove + end + + doc.css('.tabbed-set').each do |node| + labels = node.css('.tabbed-labels label') + blocks = node.css('.tabbed-content .tabbed-block') + + blocks.each_with_index do |block_node, i| + block_node.prepend_child(labels[i]) if labels[i] + end + + node.css('> input, .tabbed-labels').remove + end + + doc.css('pre').each do |node| + node['class'] = "language-python" + node['data-language'] = "python" + node.content = node.at_css('code').content + end + + doc + end + + end + end +end diff --git a/lib/docs/filters/fastapi/container.rb b/lib/docs/filters/fastapi/container.rb new file mode 100644 index 00000000..418015c3 --- /dev/null +++ b/lib/docs/filters/fastapi/container.rb @@ -0,0 +1,9 @@ +module Docs + class Fastapi + class ContainerFilter < Filter + def call + at_css '.md-content > .md-content__inner' + end + end + end +end diff --git a/lib/docs/filters/fastapi/entries.rb b/lib/docs/filters/fastapi/entries.rb new file mode 100644 index 00000000..d2923bf8 --- /dev/null +++ b/lib/docs/filters/fastapi/entries.rb @@ -0,0 +1,55 @@ +module Docs + class Fastapi + class EntriesFilter < Docs::EntriesFilter + + def sanitized_path + path.gsub(/index$/, "") + end + + def path_parts + sanitized_path.split("/") + end + + def get_name + at_css('h1').content + end + + def get_name_other + header = at_css('h1') + if header + header.content + else + path_parts.last.titleize + end + end + + def get_type + if path_parts.length <= 1 + data = at_css('h1').content + else + data = path_parts[0...path_parts.length-1].join(": ").titleize + ": " + at_css('h1').content + end + + data + end + + def path_count + path_parts.length + end + + def additional_entries + entries = [] + type = get_type + + css('h2').each do |node| + name = node.content + id = path + "#" + node['id'] + entries << [name, id, type] + end + + entries + end + + end + end +end diff --git a/lib/docs/scrapers/fastapi.rb b/lib/docs/scrapers/fastapi.rb new file mode 100644 index 00000000..b0749776 --- /dev/null +++ b/lib/docs/scrapers/fastapi.rb @@ -0,0 +1,30 @@ +module Docs + class Fastapi < UrlScraper + self.name = 'Fastapi' + self.type = 'fastapi' + self.release = '0.85.0' + self.base_url = 'https://fastapi.tiangolo.com/' + self.root_path = '/' + self.links = { + home: 'https://fastapi.tiangolo.com/', + code: 'https://github.com/tiangolo/fastapi' + } + + options[:only_patterns] = [ + /\Afeatures\//, /\Apython-types\//, + /\Atutorial\//, /\Aadvanced\//, /\Aasync\//, + /\Adeployment\//, /\Aproject-generation\// + ] + + html_filters.push 'fastapi/container', 'fastapi/clean_html', 'fastapi/entries' + + options[:attribution] = <<-HTML + © This project is licensed under the terms of the MIT license. + HTML + + def get_latest_version(opts) + get_latest_github_release('tiangolo', 'fastapi', opts) + end + + end +end diff --git a/public/icons/docs/fastapi/16.png b/public/icons/docs/fastapi/16.png new file mode 100644 index 0000000000000000000000000000000000000000..34d0637067b7353eb1b2a24e10277324e88debd7 GIT binary patch literal 1364 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6-E$sR$z z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBDAAG{;hE;^%b*2hb1<+n z3NbJPS&Tr)z$nE4G7ZRL@M4sPvx68lplX;H7}_%#SfFa6fHVkr05M1pgl1mAh%j*h z6I`{x0%imor0saV%ts)_S>O>_%)r1c48n{Iv*t)JFfg6S42dX-@b$4u&d=3LOvz75 z)vL%Y0O?||sjvbvb5lza6)JLb@`|l0Y?Z(&tblBgu)dN4SV>8?tx|+H?jfSfFg)+ zA4CH}eP~{0i5*M}nlQSq2!uSs8e~Cq4gN)$slb2)yUP&jEMzex^&sC_1!PvF=0vz; z=BDNqgZyF)bQo3%bdApWIr&Aw1&PV2c0hZ;T9Aa$RfDaG#AOYV1XQDqJ}9n{;vSN) zz@osEWyfWs4^O3bT#H{kng`4wX`U{QAr^wQlXvU61`0UnbG5L{SI`Pn5UO`r_&``i zYpVYTREPKGY zDUrQeU`mmh^;XV^FI?{vtNZ&Ex~kLwypGs z^34ZoMla7lw*HoO>ch(5HpR(=@aGtq3dG=4nhK&5hbC%6}1}ZB&UHx3vIVCg! E046!H)Bpeg literal 0 HcmV?d00001 diff --git a/public/icons/docs/fastapi/16@2x.png b/public/icons/docs/fastapi/16@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..79505801089e6c053bede0eedab690a9a938e84a GIT binary patch literal 1664 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}EvXTnX}-P; zT0k}j11qBt12aeo5Hc`IF|dN!3=Ce3(r|VVqXtwB69YqgCIbspO%#v@0S_Ps>W0$H z3m6e5E?|PIR#?D{V1u;9@8SOdq&N#aB8wRqxP?KOkzv*x37~0_nIRD+5xzcF$@#f@ zi7EL>sd^Q;1t47vHWgMtW^QUpqC!P(PF}H9g{=};g%ywu64qBz04piUwpEJo4N!2- zFG^J~(=*UBP_pAvP*AWbN=dT{a&d!d2l8x{GD=Dctn~HE%ggo3jrH=2()A53EiLs8 zjP#9+bb%^#i!1X=5-W7`ij^UTz|3(;Elw`VEGWs$&r<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