瀏覽代碼

Add FastAPI (0.85.0) documentation

Tim Lim 3 年之前
父節點
當前提交
fcbdddc741

+ 5 - 0
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',

+ 1 - 0
assets/stylesheets/application.css.scss

@@ -58,6 +58,7 @@
         'pages/ember',
         'pages/erlang',
         'pages/express',
+        'pages/fastapi',
         'pages/git',
         'pages/github',
         'pages/gnuplot',

+ 22 - 0
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);
+  }
+}

+ 32 - 0
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

+ 9 - 0
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

+ 55 - 0
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

+ 30 - 0
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
+      &copy; 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

二進制
public/icons/docs/fastapi/16.png


二進制
public/icons/docs/fastapi/16@2x.png


+ 1 - 0
public/icons/docs/fastapi/SOURCE

@@ -0,0 +1 @@
+https://fastapi.tiangolo.com/img/favicon.png