allow adding other languages in source code documentation

This commit is contained in:
Georg Baumann 2017-07-07 21:11:12 +02:00
parent 3dab905656
commit 5194e81493
7 changed files with 19 additions and 12 deletions

View File

@ -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,

View File

@ -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
}

View File

@ -8,9 +8,9 @@
{% endif %}
</div>
<div class="col-md-6 intro-code">
{% 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 %}
</div>
</div>

View File

@ -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');
</script>
</body>
</html>

View File

@ -1,3 +1,3 @@
{% load rest_framework %}
<pre class="highlight shell" data-language="shell"><code>{% code bash %}# Install the command line client
<pre class="highlight shell hide" data-language="shell"><code>{% code bash %}# Install the command line client
$ pip install coreapi-cli{% endcode %}</code></pre>

View File

@ -1,5 +1,5 @@
{% load rest_framework %}
<pre class="highlight shell" data-language="shell"><code>{% code bash %}# Load the schema document
<pre class="highlight shell hide" data-language="shell"><code>{% code bash %}# Load the schema document
$ coreapi get {{ document.url }}{% if schema_format %} --format {{ schema_format }}{% endif %}
# Interact with the API endpoint

View File

@ -29,12 +29,12 @@
</ul>
<li data-toggle="collapse" data-target="#language-control" class="collapsed">
<a><i class="fa fa-code fa-lg"></i> Source Code</a> <span id="selected-language">shell</span>
<a><i class="fa fa-code fa-lg"></i> Source Code</a> <span id="selected-language">{{ langs | first }}</span>
</li>
<ul class="sub-menu collapse out" id="language-control">
<li class="active"><a href="#" data-language="shell">shell</a></li>
<li><a href="#" data-language="javascript">javascript</a></li>
<li><a href="#" data-language="python">python</a></li>
{% for lang in langs %}
<li{% if loop.first %} class="active"{% endif %}><a href="#" data-language="{{ lang }}">{{ lang }}</a></li>
{% endfor %}
</ul>
</ul>