History

Merge pull request #1003 from emilekm/master

Add Django REST Framework documentantion

Jasper van Merle committed 7 years ago

Commit dc5ba972 parents fef9589 a14ef3811 files · +170 −-2Browse files

Unified · Split

11 files
  1. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  2. assets/stylesheets/application.css.scss +1 −0
  3. assets/stylesheets/pages/_mkdocs.scss +11 −0
  4. lib/docs/filters/django_rest_framework/clean_html.rb +30 −0
  5. lib/docs/filters/django_rest_framework/entries.rb +59 −0
  6. lib/docs/filters/mkdocs/clean_html.rb +17 −0
  7. lib/docs/scrapers/mkdocs/django_rest_framework.rb +29 −0
  8. lib/docs/scrapers/mkdocs/mkdocs.rb +19 −0
  9. public/icons/docs/django_rest_framework/16.png +0 −0
  10. public/icons/docs/django_rest_framework/16@2x.png +0 −0
  11. public/icons/docs/django_rest_framework/SOURCE +1 −0
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -231,6 +231,11 @@ credits = [ · 230 unmodified lines
231231 'Django Software Foundation and individual contributors',
232232 'BSD',
233233 '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'
234239 ], [
235240 'Docker',
236241 '2019 Docker, Inc.<br>Docker and the Docker logo are trademarks of Docker, Inc.',
assets/stylesheets/application.css.scss+1−0
@@ -72,6 +72,7 @@ · 71 unmodified lines
7272 'pages/lua',
7373 'pages/mdn',
7474 'pages/meteor',
75+ 'pages/mkdocs',
7576 'pages/modernizr',
7677 'pages/moment',
7778 'pages/nginx',
assets/stylesheets/pages/_mkdocs.scss+11−0
@@ -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+}
lib/docs/filters/django_rest_framework/clean_html.rb+30−0
@@ -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
lib/docs/filters/django_rest_framework/entries.rb+59−0
@@ -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
lib/docs/filters/mkdocs/clean_html.rb+17−0
@@ -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
lib/docs/scrapers/mkdocs/django_rest_framework.rb+29−0
@@ -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 &copy; 2011&ndash;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
lib/docs/scrapers/mkdocs/mkdocs.rb+19−0
@@ -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
public/icons/docs/django_rest_framework/16.png+0−0

Binary file not shown.

public/icons/docs/django_rest_framework/16@2x.png+0−0

Binary file not shown.

public/icons/docs/django_rest_framework/SOURCE+1−0
@@ -0,0 +1 @@
1+https://github.com/encode/django-rest-framework/blob/master/docs_theme/img/favicon.ico