From 5194e8149320946ed215b0b30c497d88d0ecd384 Mon Sep 17 00:00:00 2001 From: Georg Baumann Date: Fri, 7 Jul 2017 21:11:12 +0200 Subject: [PATCH 1/3] allow adding other languages in source code documentation --- rest_framework/documentation.py | 10 +++++++--- rest_framework/renderers.py | 2 ++ .../templates/rest_framework/docs/document.html | 6 +++--- .../templates/rest_framework/docs/index.html | 1 + .../rest_framework/docs/langs/shell-intro.html | 2 +- .../templates/rest_framework/docs/langs/shell.html | 2 +- .../templates/rest_framework/docs/sidebar.html | 8 ++++---- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/rest_framework/documentation.py b/rest_framework/documentation.py index 48458e188..691861796 100644 --- a/rest_framework/documentation.py +++ b/rest_framework/documentation.py @@ -8,8 +8,10 @@ from rest_framework.schemas import SchemaGenerator, get_schema_view def get_docs_view( title=None, description=None, schema_url=None, public=True, - patterns=None, generator_class=SchemaGenerator): - renderer_classes = [DocumentationRenderer, CoreJSONRenderer] + patterns=None, generator_class=SchemaGenerator, + renderer_classes=None): + if renderer_classes is None: + renderer_classes = [DocumentationRenderer, CoreJSONRenderer] return get_schema_view( title=title, @@ -40,7 +42,8 @@ def get_schemajs_view( def include_docs_urls( title=None, description=None, schema_url=None, public=True, - patterns=None, generator_class=SchemaGenerator): + patterns=None, generator_class=SchemaGenerator, + renderer_classes=None): docs_view = get_docs_view( title=title, description=description, @@ -48,6 +51,7 @@ def include_docs_urls( public=public, patterns=patterns, generator_class=generator_class, + renderer_classes=renderer_classes ) schema_js_view = get_schemajs_view( title=title, diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 406dda72c..c90233342 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -808,6 +808,8 @@ class DocumentationRenderer(BaseRenderer): return { 'document': data, 'langs': self.languages, + 'lang_htmls': ["rest_framework/docs/langs/%s.html" % l for l in self.languages], + 'lang_intro_htmls': ["rest_framework/docs/langs/%s-intro.html" % l for l in self.languages], 'code_style': pygments_css(self.code_style), 'request': request } diff --git a/rest_framework/templates/rest_framework/docs/document.html b/rest_framework/templates/rest_framework/docs/document.html index ef5f5966b..b8e7ce74b 100644 --- a/rest_framework/templates/rest_framework/docs/document.html +++ b/rest_framework/templates/rest_framework/docs/document.html @@ -8,9 +8,9 @@ {% endif %}
- {% if 'shell' in langs %}{% include "rest_framework/docs/langs/shell-intro.html" %}{% endif %} - {% if 'python' in langs %}{% include "rest_framework/docs/langs/python-intro.html" %}{% endif %} - {% if 'javascript' in langs %}{% include "rest_framework/docs/langs/javascript-intro.html" %}{% endif %} + {% for html in lang_intro_htmls %} + {% include html %} + {% endfor %}
diff --git a/rest_framework/templates/rest_framework/docs/index.html b/rest_framework/templates/rest_framework/docs/index.html index 84ef03749..88ae103f8 100644 --- a/rest_framework/templates/rest_framework/docs/index.html +++ b/rest_framework/templates/rest_framework/docs/index.html @@ -51,6 +51,7 @@ $('#auth-control').children().removeClass('active'); $('#auth-control').find("[data-auth='session']").closest('li').addClass('active'); {% endif %} + $('pre.highlight').filter('[data-language="{{ langs | first }}"]').removeClass('hide'); diff --git a/rest_framework/templates/rest_framework/docs/langs/shell-intro.html b/rest_framework/templates/rest_framework/docs/langs/shell-intro.html index fa77bce4a..2320ddfa9 100644 --- a/rest_framework/templates/rest_framework/docs/langs/shell-intro.html +++ b/rest_framework/templates/rest_framework/docs/langs/shell-intro.html @@ -1,3 +1,3 @@ {% load rest_framework %} -
{% code bash %}# Install the command line client
+
{% code bash %}# Install the command line client
 $ pip install coreapi-cli{% endcode %}
diff --git a/rest_framework/templates/rest_framework/docs/langs/shell.html b/rest_framework/templates/rest_framework/docs/langs/shell.html index d2744920c..24137e4ae 100644 --- a/rest_framework/templates/rest_framework/docs/langs/shell.html +++ b/rest_framework/templates/rest_framework/docs/langs/shell.html @@ -1,5 +1,5 @@ {% load rest_framework %} -
{% code bash %}# Load the schema document
+
{% code bash %}# Load the schema document
 $ coreapi get {{ document.url }}{% if schema_format %} --format {{ schema_format }}{% endif %}
 
 # Interact with the API endpoint
diff --git a/rest_framework/templates/rest_framework/docs/sidebar.html b/rest_framework/templates/rest_framework/docs/sidebar.html
index c6ac26f66..407ec167b 100644
--- a/rest_framework/templates/rest_framework/docs/sidebar.html
+++ b/rest_framework/templates/rest_framework/docs/sidebar.html
@@ -29,12 +29,12 @@
             
 
             
             
         
 

From 8456d042e41807ddff3f98403692fb16927182e4 Mon Sep 17 00:00:00 2001
From: Georg Baumann 
Date: Mon, 10 Jul 2017 19:17:58 +0200
Subject: [PATCH 2/3] add missing template update for "allow adding other
 langs"

---
 rest_framework/templates/rest_framework/docs/link.html | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/rest_framework/templates/rest_framework/docs/link.html b/rest_framework/templates/rest_framework/docs/link.html
index ae8c7b700..eb5926c4d 100644
--- a/rest_framework/templates/rest_framework/docs/link.html
+++ b/rest_framework/templates/rest_framework/docs/link.html
@@ -93,9 +93,9 @@
 
 
     
- {% if 'shell' in langs %}{% include "rest_framework/docs/langs/shell.html" %}{% endif %} - {% if 'python' in langs %}{% include "rest_framework/docs/langs/python.html" %}{% endif %} - {% if 'javascript' in langs %}{% include "rest_framework/docs/langs/javascript.html" %}{% endif %} + {% for html in lang_htmls %} + {% include html %} + {% endfor %}
From 1f9d2165b92aae032aba0d1ba7f92fc8f0138f95 Mon Sep 17 00:00:00 2001 From: Georg Baumann Date: Fri, 15 Dec 2017 16:33:08 +0100 Subject: [PATCH 3/3] removed white space in blank line (caused flake8 to fail) --- rest_framework/documentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/documentation.py b/rest_framework/documentation.py index d9e40d070..7bafe265f 100644 --- a/rest_framework/documentation.py +++ b/rest_framework/documentation.py @@ -13,7 +13,7 @@ def get_docs_view( authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES, permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES, renderer_classes=None): - + if renderer_classes is None: renderer_classes = [DocumentationRenderer, CoreJSONRenderer]