Showing the changes to lib/docs (4 of 10 files). Show all
Unified · Split
| @@ -0,0 +1,32 @@ | |||
| 1 | module Docs | ||
| 2 | class Fastapi | ||
| 3 | class CleanHtmlFilter < Filter | ||
| 4 | |||
| 5 | def call | ||
| 6 | doc.css('.headerlink').each do |node| | ||
| 7 | node.remove | ||
| 8 | end | ||
| 9 | |||
| 10 | doc.css('.tabbed-set').each do |node| | ||
| 11 | labels = node.css('.tabbed-labels label') | ||
| 12 | blocks = node.css('.tabbed-content .tabbed-block') | ||
| 13 | |||
| 14 | blocks.each_with_index do |block_node, i| | ||
| 15 | block_node.prepend_child(labels[i]) if labels[i] | ||
| 16 | end | ||
| 17 | |||
| 18 | node.css('> input, .tabbed-labels').remove | ||
| 19 | end | ||
| 20 | |||
| 21 | doc.css('pre').each do |node| | ||
| 22 | node['class'] = "language-python" | ||
| 23 | node['data-language'] = "python" | ||
| 24 | node.content = node.at_css('code').content | ||
| 25 | end | ||
| 26 | |||
| 27 | doc | ||
| 28 | end | ||
| 29 | |||
| 30 | end | ||
| 31 | end | ||
| 32 | end | ||
| @@ -0,0 +1,9 @@ | |||
| 1 | module Docs | ||
| 2 | class Fastapi | ||
| 3 | class ContainerFilter < Filter | ||
| 4 | def call | ||
| 5 | at_css '.md-content > .md-content__inner' | ||
| 6 | end | ||
| 7 | end | ||
| 8 | end | ||
| 9 | end | ||
| @@ -0,0 +1,55 @@ | |||
| 1 | module Docs | ||
| 2 | class Fastapi | ||
| 3 | class EntriesFilter < Docs::EntriesFilter | ||
| 4 | |||
| 5 | def sanitized_path | ||
| 6 | path.gsub(/index$/, "") | ||
| 7 | end | ||
| 8 | |||
| 9 | def path_parts | ||
| 10 | sanitized_path.split("/") | ||
| 11 | end | ||
| 12 | |||
| 13 | def get_name | ||
| 14 | at_css('h1').content | ||
| 15 | end | ||
| 16 | |||
| 17 | def get_name_other | ||
| 18 | header = at_css('h1') | ||
| 19 | if header | ||
| 20 | header.content | ||
| 21 | else | ||
| 22 | path_parts.last.titleize | ||
| 23 | end | ||
| 24 | end | ||
| 25 | |||
| 26 | def get_type | ||
| 27 | if path_parts.length <= 1 | ||
| 28 | data = at_css('h1').content | ||
| 29 | else | ||
| 30 | data = path_parts[0...path_parts.length-1].join(": ").titleize + ": " + at_css('h1').content | ||
| 31 | end | ||
| 32 | |||
| 33 | data | ||
| 34 | end | ||
| 35 | |||
| 36 | def path_count | ||
| 37 | path_parts.length | ||
| 38 | end | ||
| 39 | |||
| 40 | def additional_entries | ||
| 41 | entries = [] | ||
| 42 | type = get_type | ||
| 43 | |||
| 44 | css('h2').each do |node| | ||
| 45 | name = node.content | ||
| 46 | id = path + "#" + node['id'] | ||
| 47 | entries << [name, id, type] | ||
| 48 | end | ||
| 49 | |||
| 50 | entries | ||
| 51 | end | ||
| 52 | |||
| 53 | end | ||
| 54 | end | ||
| 55 | end | ||
| @@ -0,0 +1,30 @@ | |||
| 1 | module Docs | ||
| 2 | class Fastapi < UrlScraper | ||
| 3 | self.name = 'Fastapi' | ||
| 4 | self.type = 'fastapi' | ||
| 5 | self.release = '0.85.0' | ||
| 6 | self.base_url = 'https://fastapi.tiangolo.com/' | ||
| 7 | self.root_path = '/' | ||
| 8 | self.links = { | ||
| 9 | home: 'https://fastapi.tiangolo.com/', | ||
| 10 | code: 'https://github.com/tiangolo/fastapi' | ||
| 11 | } | ||
| 12 | |||
| 13 | options[:only_patterns] = [ | ||
| 14 | /\Afeatures\//, /\Apython-types\//, | ||
| 15 | /\Atutorial\//, /\Aadvanced\//, /\Aasync\//, | ||
| 16 | /\Adeployment\//, /\Aproject-generation\// | ||
| 17 | ] | ||
| 18 | |||
| 19 | html_filters.push 'fastapi/container', 'fastapi/clean_html', 'fastapi/entries' | ||
| 20 | |||
| 21 | options[:attribution] = <<-HTML | ||
| 22 | © This project is licensed under the terms of the MIT license. | ||
| 23 | HTML | ||
| 24 | |||
| 25 | def get_latest_version(opts) | ||
| 26 | get_latest_github_release('tiangolo', 'fastapi', opts) | ||
| 27 | end | ||
| 28 | |||
| 29 | end | ||
| 30 | end | ||