Add Django REST Framework documentantion
Unified · Split
| @@ -231,6 +231,11 @@ credits = [ · 230 unmodified lines | ||
| 231 | 231 | 'Django Software Foundation and individual contributors', |
| 232 | 232 | 'BSD', |
| 233 | 233 | 'https://raw.githubusercontent.com/django/django/master/LICENSE' |
| 234 | + ], [ | |
| 235 | + 'Django REST Framework', | |
| 236 | + '2011-present Encode OSS Ltd.', | |
| 237 | + 'BSD', | |
| 238 | + 'https://raw.githubusercontent.com/encode/django-rest-framework/master/LICENSE.md' | |
| 234 | 239 | ], [ |
| 235 | 240 | 'Docker', |
| 236 | 241 | '2019 Docker, Inc.<br>Docker and the Docker logo are trademarks of Docker, Inc.', |
| @@ -72,6 +72,7 @@ · 71 unmodified lines | ||
| 72 | 72 | 'pages/lua', |
| 73 | 73 | 'pages/mdn', |
| 74 | 74 | 'pages/meteor', |
| 75 | + 'pages/mkdocs', | |
| 75 | 76 | 'pages/modernizr', |
| 76 | 77 | 'pages/moment', |
| 77 | 78 | 'pages/nginx', |
| @@ -0,0 +1,11 @@ | ||
| 1 | +._mkdocs { | |
| 2 | + h2 { @extend %block-heading; } | |
| 3 | + h3 { @extend %block-label, %label-blue; } | |
| 4 | + h4 { @extend %block-label; } | |
| 5 | + | |
| 6 | + blockquote { @extend %note; } | |
| 7 | + | |
| 8 | + strong { font-weight: var(--bolderFontWeight); } | |
| 9 | + | |
| 10 | + p > code, li > code { @extend %label; } | |
| 11 | +} | |
| @@ -0,0 +1,30 @@ | ||
| 1 | +module Docs | |
| 2 | + class DjangoRestFramework | |
| 3 | + class CleanHtmlFilter < Docs::Filter | |
| 4 | + def call | |
| 5 | + css('hr').remove | |
| 6 | + css('.badges').remove | |
| 7 | + | |
| 8 | + css('pre').attr('data-language', 'python') | |
| 9 | + | |
| 10 | + css('h1').remove_attribute('style') | |
| 11 | + css('.promo a').remove_attribute('style') | |
| 12 | + | |
| 13 | + # Translate source files links to DevDocs links | |
| 14 | + links = Nokogiri::XML::Node.new('p', doc) | |
| 15 | + links['class'] = '_links' | |
| 16 | + | |
| 17 | + css('a.github').each do |node| | |
| 18 | + span = node.at_css('span') | |
| 19 | + node.content = span.content | |
| 20 | + node['class'] = '_links-link' | |
| 21 | + links.add_child(node) | |
| 22 | + end | |
| 23 | + | |
| 24 | + doc.add_child(links) | |
| 25 | + | |
| 26 | + doc | |
| 27 | + end | |
| 28 | + end | |
| 29 | + end | |
| 30 | +end | |
| @@ -0,0 +1,59 @@ | ||
| 1 | +module Docs | |
| 2 | + class DjangoRestFramework | |
| 3 | + class EntriesFilter < Docs::EntriesFilter | |
| 4 | + def get_name | |
| 5 | + name = css('h1').first.content | |
| 6 | + name.slice! 'Tutorial ' | |
| 7 | + name = '0: ' + name if name.include? 'Quickstart' | |
| 8 | + name | |
| 9 | + end | |
| 10 | + | |
| 11 | + def get_type | |
| 12 | + case subpath | |
| 13 | + when /\Atutorial/ | |
| 14 | + 'Tutorial' | |
| 15 | + when /\Aapi-guide/ | |
| 16 | + 'API Guide' | |
| 17 | + end | |
| 18 | + end | |
| 19 | + | |
| 20 | + def additional_entries | |
| 21 | + return [] if type == nil || type == 'Tutorial' | |
| 22 | + | |
| 23 | + # Framework classes are provided in two different ways: | |
| 24 | + # - as H2's after H1 category titled: | |
| 25 | + accepted_headers = ['API Reference', 'API Guide'] | |
| 26 | + # - as headers (1 or 2) with these endings: | |
| 27 | + endings = ['Validator', 'Field', 'View', 'Mixin', 'Default', 'Serializer'] | |
| 28 | + | |
| 29 | + # To avoid writing down all the endings | |
| 30 | + # and to ensure all entries in API categories are matched | |
| 31 | + # two different ways of finding them are used | |
| 32 | + | |
| 33 | + entries = [] | |
| 34 | + | |
| 35 | + local_type = 'Ref: ' + name | |
| 36 | + in_category = false | |
| 37 | + | |
| 38 | + css('h1, h2').each do |node| | |
| 39 | + # Third party category contains entries that could be matched (and shouldn't be) | |
| 40 | + break if node.content === 'Third party packages' | |
| 41 | + | |
| 42 | + if in_category | |
| 43 | + if node.name === 'h1' | |
| 44 | + in_category = false | |
| 45 | + next | |
| 46 | + end | |
| 47 | + entries << [node.content, node['id'], local_type] | |
| 48 | + elsif accepted_headers.include? node.content | |
| 49 | + in_category = true | |
| 50 | + elsif endings.any? { |word| node.content.ends_with?(word) } | |
| 51 | + entries << [node.content, node['id'], local_type] | |
| 52 | + end | |
| 53 | + end | |
| 54 | + | |
| 55 | + entries | |
| 56 | + end | |
| 57 | + end | |
| 58 | + end | |
| 59 | +end | |
| @@ -0,0 +1,17 @@ | ||
| 1 | +module Docs | |
| 2 | + class Mkdocs | |
| 3 | + class CleanHtmlFilter < Docs::Filter | |
| 4 | + def call | |
| 5 | + css('.toclink').each do |node| | |
| 6 | + node.parent.content = node.content | |
| 7 | + end | |
| 8 | + | |
| 9 | + css('pre').each do |node| | |
| 10 | + node.content = node.at_css('code').content | |
| 11 | + end | |
| 12 | + | |
| 13 | + at_css('#main-content') | |
| 14 | + end | |
| 15 | + end | |
| 16 | + end | |
| 17 | +end | |
| @@ -0,0 +1,29 @@ | ||
| 1 | +module Docs | |
| 2 | + class DjangoRestFramework < Mkdocs | |
| 3 | + self.name = 'Django REST Framework' | |
| 4 | + self.release = '3.9.3' | |
| 5 | + self.slug = 'django_rest_framework' | |
| 6 | + self.base_url = 'https://www.django-rest-framework.org/' | |
| 7 | + self.root_path = 'index.html' | |
| 8 | + self.links = { | |
| 9 | + home: 'https://www.django-rest-framework.org/', | |
| 10 | + code: 'https://github.com/encode/django-rest-framework' | |
| 11 | + } | |
| 12 | + | |
| 13 | + html_filters.push 'django_rest_framework/clean_html', 'django_rest_framework/entries' | |
| 14 | + | |
| 15 | + options[:skip_patterns] = [ | |
| 16 | + /\Atopics\//, | |
| 17 | + /\Acommunity\//, | |
| 18 | + ] | |
| 19 | + | |
| 20 | + options[:attribution] = <<-HTML | |
| 21 | + Copyright © 2011–present Encode OSS Ltd.<br> | |
| 22 | + Licensed under the BSD License. | |
| 23 | + HTML | |
| 24 | + | |
| 25 | + def get_latest_version(opts) | |
| 26 | + get_latest_github_release('encode', 'django-rest-framework', opts) | |
| 27 | + end | |
| 28 | + end | |
| 29 | +end | |
| @@ -0,0 +1,19 @@ | ||
| 1 | +module Docs | |
| 2 | + class Mkdocs < UrlScraper | |
| 3 | + self.abstract = true | |
| 4 | + self.type = 'mkdocs' | |
| 5 | + | |
| 6 | + html_filters.push 'mkdocs/clean_html' | |
| 7 | + | |
| 8 | + private | |
| 9 | + | |
| 10 | + def handle_response(response) | |
| 11 | + # Some scrapped urls don't have ending slash | |
| 12 | + # which leads to page duplication | |
| 13 | + if !response.url.path.ends_with?('/') && !response.url.path.ends_with?('index.html') | |
| 14 | + response.url.path << '/' | |
| 15 | + end | |
| 16 | + super | |
| 17 | + end | |
| 18 | + end | |
| 19 | +end | |
Binary file not shown.
Binary file not shown.
| @@ -0,0 +1 @@ | ||
| 1 | +https://github.com/encode/django-rest-framework/blob/master/docs_theme/img/favicon.ico | |