File tree Expand file tree Collapse file tree 10 files changed +58
-27
lines changed
templates/rest_framework/docs Expand file tree Collapse file tree 10 files changed +58
-27
lines changed Original file line number Diff line number Diff line change
1
+ {% for section_key, section in items %}
2
+ {% if section_key %}
3
+ < h {{level}} id ="{{prefix}}-{{ section_key }} " class ="coredocs-section-title "> {{ section_key }} < a href ="#{{ section_key }} "> < i class ="fa fa-link " aria-hidden ="true "> </ i >
4
+ </ a > </ h {{level}}>
5
+ {% endif %}
6
+
7
+ {% if section.links.items %}
8
+ {% for link_key, link in section.links.items %}
9
+ {% include "rest_framework/docs/link.html" with prefix=prefix level=level|add:1%}
10
+ {% endfor %}
11
+ {% else %}
12
+ {% include 'rest_framework/docs/_recursive_document.html' with items=section.items prefix=prefix|add:section_key|add:'/' level=level|add:1 %}
13
+ {% endif %}
14
+ {% endfor %}
15
+
Original file line number Diff line number Diff line change
1
+ < ul id ="{% if prefix %}{{prefix}}-dropdown{% else %}menu-content{% endif %} " class ="menu-content collapse out ">
2
+ {% for section_key, section in items %}
3
+ < li data-toggle ="collapse " data-target ="#{{prefix}}{{ section_key }}-dropdown " class ="collapsed ">
4
+ < a > < i class ="fa fa-dot-circle-o fa-lg "> </ i > {% if prefix %}{{prefix}}/{% endif %}{% if section_key %}{{ section_key }}{% else %}API Endpoints{% endif %} < span class ="arrow "> </ span > </ a >
5
+ </ li >
6
+ {% if section.links.items %}
7
+ < ul class ="sub-menu {% if section_key %}collapse{% endif %} " id ="{{prefix}}{{ section_key }}-dropdown ">
8
+ {% for link_key, link in section.links.items %}
9
+ < li > < a href ="#{{prefix}}-{{ section_key }}-{{ link_key }} "> {{ link.title|default:link_key }}</ a > </ li >
10
+ {% endfor %}
11
+ </ ul >
12
+ {% else %}
13
+ {% include 'rest_framework/docs/_recursive_menu.html' with items=section.items prefix=prefix|add:section_key %}
14
+ {% endif %}
15
+ {% endfor %}
16
+ </ ul >
17
+
Original file line number Diff line number Diff line change @@ -14,16 +14,7 @@ <h1>{{ document.title }}</h1>
14
14
</ div >
15
15
</ div >
16
16
17
- {% for section_key, section in document.data|items %}
18
- {% if section_key %}
19
- < h2 id ="{{ section_key }} " class ="coredocs-section-title "> {{ section_key }} < a href ="#{{ section_key }} "> < i class ="fa fa-link " aria-hidden ="true "> </ i >
20
- </ a > </ h2 >
21
- {% endif %}
22
-
23
- {% for link_key, link in section.links|items %}
24
- {% include "rest_framework/docs/link.html" %}
25
- {% endfor %}
26
- {% endfor %}
17
+ {% include 'rest_framework/docs/_recursive_document.html' with items=document.data|items level=2 %}
27
18
28
19
{% for link_key, link in document.links|items %}
29
20
{% include "rest_framework/docs/link.html" %}
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ <h3 class="modal-title"><i class="fa fa-exchange"></i> {{ link.title|default:lin
16
16
17
17
</ div >
18
18
19
- < form data-key ='["{{ section_key }}", "{{ link_key }}"] ' class ="api-interaction ">
19
+ < form data-key ='[{{ prefix|split_keys }} "{{ section_key }}", "{{ link_key }}"] ' class ="api-interaction ">
20
20
< div class ="modal-body ">
21
21
< div class ="row ">
22
22
< div class ="col-lg-6 request ">
Original file line number Diff line number Diff line change 6
6
var client = new coreapi.Client()
7
7
8
8
// Interact with the API endpoint
9
- var action = [{% if section_key %}"{{ section_key }}", {% endif %}"{{ link_key }}"]
9
+ var action = [{% if prefix %}{{ prefix|split_keys }} {% endif %}{% if section_key %}"{{ section_key }}", {% endif %}"{{ link_key }}"]
10
10
{% if link.fields %}var params = {
11
11
{% for field in link.fields %} {{ field.name }}: ...{% if not loop.last %},{% endif %}
12
12
{% endfor %}}
Original file line number Diff line number Diff line change 6
6
schema = client.get("{{ document.url }}"{% if schema_format %}, format="{{ schema_format }}"{% endif %})
7
7
8
8
# Interact with the API endpoint
9
- action = [{% if section_key %}"{{ section_key }}", {% endif %}"{{ link_key }}"]
9
+ action = [{% if prefix %}{{ prefix|split_keys }} {% endif %}{% if section_key %}"{{ section_key }}", {% endif %}"{{ link_key }}"]
10
10
{% if link.fields %}params = {
11
11
{% for field in link.fields %} "{{ field.name }}": ...{% if not loop.last %},{% endif %}
12
12
{% endfor %}}
Original file line number Diff line number Diff line change 3
3
$ coreapi get {{ document.url }}{% if schema_format %} --format {{ schema_format }}{% endif %}
4
4
5
5
# Interact with the API endpoint
6
- $ coreapi action {% if section_key %}{{ section_key }} {% endif %}{{ link_key }}{% for field in link.fields %} -p {{ field.name }}=...{% endfor %}{% endcode %}</ code > </ pre >
6
+ $ coreapi action {% if prefix %}{{ prefix|split_keys:'cmd' }} {% endif %}{% if section_key %}{{ section_key }} {% endif %}{{ link_key }}{% for field in link.fields %} -p {{ field.name }}=...{% endfor %}{% endcode %}</ code > </ pre >
Original file line number Diff line number Diff line change 10
10
< i class ="fa fa-exchange "> </ i > Interact
11
11
</ button >
12
12
13
- < h3 id ="{{ section_key }}-{{ link_key }} " class ="coredocs-link-title "> {{ link.title|default:link_key }} < a href ="#{{ section_key }}-{{ link_key }} "> < i class ="fa fa-link " aria-hidden ="true "> </ i >
13
+ < h3 id ="{{prefix}}-{{ section_key }}-{{ link_key }} " class ="coredocs-link-title "> {{ link.title|default:link_key }} < a href ="#{{prefix}}- {{ section_key }}-{{ link_key }} "> < i class ="fa fa-link " aria-hidden ="true "> </ i >
14
14
</ a > </ h3 >
15
15
16
16
< div class ="meta ">
Original file line number Diff line number Diff line change @@ -4,18 +4,7 @@ <h3 class="brand"><a href="#">{{ document.title }}</a></h3>
4
4
5
5
< i class ="fa fa-bars fa-2x toggle-btn " data-toggle ="collapse " data-target ="#menu-content "> </ i >
6
6
< div class ="menu-list ">
7
- < ul id ="menu-content " class ="menu-content collapse out ">
8
- {% for section_key, section in document.data|items %}
9
- < li data-toggle ="collapse " data-target ="#{{ section_key }}-dropdown " class ="collapsed ">
10
- < a > < i class ="fa fa-dot-circle-o fa-lg "> </ i > {% if section_key %}{{ section_key }}{% else %}API Endpoints{% endif %} < span class ="arrow "> </ span > </ a >
11
- </ li >
12
- < ul class ="sub-menu {% if section_key %}collapse{% endif %} " id ="{{ section_key }}-dropdown ">
13
- {% for link_key, link in section.links|items %}
14
- < li > < a href ="#{{ section_key }}-{{ link_key }} "> {{ link.title|default:link_key }}</ a > </ li >
15
- {% endfor %}
16
- </ ul >
17
- {% endfor %}
18
- </ ul >
7
+ {% include 'rest_framework/docs/_recursive_menu.html' with items=document.data|items %}
19
8
20
9
< ul class ="menu-list menu-list-bottom ">
21
10
< li data-toggle ="collapse " data-target ="#auth-control " class ="collapsed ">
Original file line number Diff line number Diff line change @@ -362,3 +362,22 @@ def break_long_headers(header):
362
362
if len (header ) > 160 and ',' in header :
363
363
header = mark_safe ('<br> ' + ', <br>' .join (header .split (',' )))
364
364
return header
365
+
366
+
367
+ @register .filter
368
+ def split_keys (keys , cmd_type = 'script' ):
369
+ if not keys :
370
+ return ''
371
+
372
+ if cmd_type == 'script' :
373
+ joiner = ', '
374
+ wrapper = '"'
375
+ else :
376
+ joiner = ' '
377
+ wrapper = ''
378
+
379
+ return joiner .join ([
380
+ '{wrapper}{k}{wrapper}' .format (k = k , wrapper = wrapper )
381
+ if k != '' else ''
382
+ for k in keys .split ('/' )
383
+ ])
You can’t perform that action at this time.
0 commit comments