Skip to content
Browse files

Add a new option on endpoint : 'full_description'

Content of this option can be in markdown

This allows the endpoint to be fully described, with titles,
bullet points and so on. You can even insert some code snippets.
  • Loading branch information...
1 parent ae18498 commit c7b37a4aca24384b51fd7acaa096db26ca2bc885 @pjambet pjambet committed
View
16 apiplayground/playground.py
@@ -1,4 +1,5 @@
import json
+import markdown
from django.conf.urls import url
from django.http import HttpResponse, HttpResponseBadRequest
@@ -50,9 +51,10 @@ def browser_index(self, request):
"""
A view that returns api browser index.
"""
+ self.build_full_description()
return render_to_response(self.index_template, {
- "schema": self.get_schema(),
- "feedback_form": self.get_feedback_form(request)
+ "schema": self.get_schema(),
+ "feedback_form": self.get_feedback_form(request)
}, context_instance=RequestContext(request))
def save_feedback_form(self, request, form):
@@ -99,9 +101,17 @@ def get_urls(self):
url("^submit-feedback$", self.submit_feedback, name="api_playground_submit_feedback"),
]
+ def build_full_description(self):
+ schema = self.get_schema()
+ for resource in schema['resources']:
+ for endpoint in resource.get('endpoints', []):
+ if endpoint.get('full_description', ""):
+ endpoint['full_description'] = markdown.markdown(
+ endpoint['full_description'].strip())
+
@property
def urls(self):
"""
A shortcut property for reaching the urls.
"""
- return self.get_urls()
+ return self.get_urls()
View
11 apiplayground/static/api_browser/css/screen.css
@@ -151,6 +151,15 @@ section.resource {
font-size: 14px;
}
+ section.resource ul li .full_description {
+ font-size: 16px;
+ font-weight: normal;
+ padding: 0 30px;
+ }
+ section.resource ul li .full_description ol li {
+ list-style-type: decimal;
+ }
+
section.resource ul li form, section.resource ul li .result {
margin: 0 100px;
overflow: hidden;
@@ -275,4 +284,4 @@ section.resource li.endpoint a.give-feedback {
background-color: #fdffd1;
padding: 10px;
display: none;
- }
+ }
View
5 apiplayground/templates/api_browser/index.html
@@ -18,6 +18,9 @@
<i>{{ endpoint.description }}</i>
</a>
<section class="try-it">
+ {% if endpoint.full_description %}
+ <div class="full_description">{{ endpoint.full_description|safe }}</div>
+ {% endif %}
<form action="{{ endpoint.url }}" data-endpoint-url="{{ endpoint.url }}" method="{{ endpoint.method|upper }}">
{% spaceless %}
{% get_endpoint_forms endpoint as forms %}
@@ -67,4 +70,4 @@
new APIBrowser();
});
</script>
-{% endblock %}
+{% endblock %}
View
3 setup.py
@@ -4,13 +4,14 @@
name='django-api-playground',
version='0.1.1',
packages=['apiplayground', 'apiplayground.templatetags'],
- zip_safe = False,
+ zip_safe=False,
include_package_data=True,
url='http://github.com/fatiherikli/django-api-playground',
license='BSD',
author='fatiherikli',
author_email='fatiherikli@gmail.com',
description='API Playground for RESTful APIs',
+ install_requires=['markdown'],
classifiers=[
"Development Status :: 3 - Alpha",
"Environment :: Web Environment",

0 comments on commit c7b37a4

Please sign in to comment.
Something went wrong with that request. Please try again.