1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Added documentation renderer

This commit is contained in:
Jeremy Stretch
2016-05-24 12:38:06 -04:00
parent f43184695b
commit fbb3911346
10 changed files with 317 additions and 230 deletions

View File

@@ -2,7 +2,7 @@ from django.conf.urls import include, url
from django.contrib import admin
from django.views.defaults import page_not_found
from views import home, trigger_500
from views import home, docs, trigger_500
from users.views import login, logout
@@ -30,6 +30,10 @@ urlpatterns = [
url(r'^api/docs/', include('rest_framework_swagger.urls')),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
# Dcoumentation
url(r'^docs/$', docs, kwargs={'path': 'index'}, name='docs_root'),
url(r'^docs/(?P<path>[\w-]+)/$', docs, name='docs'),
# Error testing
url(r'^404/$', page_not_found),
url(r'^500/$', trigger_500),

View File

@@ -1,4 +1,9 @@
from markdown import markdown
from django.conf import settings
from django.http import Http404
from django.shortcuts import render
from django.utils.safestring import mark_safe
from circuits.models import Provider, Circuit
from dcim.models import Site, Rack, Device, ConsolePort, PowerPort, InterfaceConnection
@@ -40,6 +45,25 @@ def home(request):
})
def docs(request, path):
"""
Display a page of Markdown-formatted documentation.
"""
filename = '{}/docs/{}.md'.format(settings.BASE_DIR.rsplit('/', 1)[0], path)
try:
with open(filename, 'r') as docfile:
markup = docfile.read()
except:
raise Http404
content = mark_safe(markdown(markup, extensions=['mdx_gfm']))
return render(request, 'docs.html', {
'content': content,
'path': path,
})
def trigger_500(request):
"""Hot-wired method of triggering a server error to test reporting."""

View File

@@ -0,0 +1,19 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}
{% block title %}Documentation{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-3">
<div class="list-group">
<a href="{% url 'docs_root' %}" class="list-group-item{% if path == 'index' %} active{% endif %}">Home</a>
<a href="{% url 'docs' path='configuration' %}" class="list-group-item{% if path == 'configuration' %} active{% endif %}">Configuration</a>
<a href="{% url 'docs' path='data-model' %}" class="list-group-item{% if path == 'data-model' %} active{% endif %}">Data Model</a>
</div>
</div>
<div class="col-md-9">
{{ content }}
</div>
</div>
{% endblock %}