2010-06-04 16:13:53 -05:00
|
|
|
.. _websupportquickstart:
|
|
|
|
|
|
|
|
Web Support Quick Start
|
|
|
|
=======================
|
|
|
|
|
|
|
|
To use the :ref:`websupportapi` in your application you must import
|
|
|
|
the :class:`~sphinx.websupport.api.WebSupport` object::
|
|
|
|
|
|
|
|
from sphinx.websupport import support
|
|
|
|
|
|
|
|
This provides a reference to a :class:`~sphinx.websupport.api.WebSupport`
|
|
|
|
object. You will then need to provide some information about your
|
|
|
|
environment::
|
|
|
|
|
|
|
|
support.init(srcdir='/path/to/rst/sources/',
|
|
|
|
outdir='/path/to/build/outdir')
|
|
|
|
|
|
|
|
You only need to provide a srcdir if you are building documentation::
|
|
|
|
|
|
|
|
support.build()
|
|
|
|
|
|
|
|
This will create the data the web support package needs and place
|
2010-06-16 08:33:33 -05:00
|
|
|
it in *outdir*. You can then access this data by calling the
|
|
|
|
get_document(docname) method. For example, to retrieve the "contents"
|
2010-06-04 16:13:53 -05:00
|
|
|
document, do this::
|
|
|
|
|
|
|
|
contents_doc = support.get_document('contents')
|
|
|
|
|
2010-06-16 08:33:33 -05:00
|
|
|
This will return a dictionary containing the context you need to render
|
|
|
|
a document.
|
|
|
|
|
2010-06-04 16:13:53 -05:00
|
|
|
A more useful example, in the form of a `Flask <http://flask.pocoo.org/>`_
|
|
|
|
application is::
|
|
|
|
|
|
|
|
from flask import Flask, render_template
|
|
|
|
from sphinx.websupport import support
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
support.init(outdir='/path/to/sphinx/data')
|
|
|
|
|
|
|
|
@app.route('/docs/<path:docname>')
|
|
|
|
def doc(docname):
|
|
|
|
document = support.get_document(docname)
|
|
|
|
return render_template('doc.html', document=document)
|
|
|
|
|
|
|
|
In the previous example the doc.html template would look something
|
|
|
|
like this::
|
|
|
|
|
|
|
|
{% extends "base.html" %}
|
|
|
|
|
|
|
|
{% block title %}
|
|
|
|
{{ document.title }}
|
|
|
|
{% endblock %}
|
|
|
|
|
2010-06-16 08:33:33 -05:00
|
|
|
{% block extra_js %}
|
|
|
|
<script type="text/javascript" src="/static/jquery.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
<!--
|
|
|
|
$(document).ready(function() {
|
|
|
|
$(".spxcmt").append(' <a href="#" class="sphinx_comment"><img src="/static/comment.png" /></a>');
|
|
|
|
$("a.sphinx_comment").click(function() {
|
|
|
|
id = $(this).parent().attr('id');
|
|
|
|
alert('[ comment stub ' + id + ' ]');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
-->
|
|
|
|
</script>
|
|
|
|
{% endblock %}
|
|
|
|
|
2010-06-04 16:13:53 -05:00
|
|
|
{% block body %}
|
2010-06-16 08:33:33 -05:00
|
|
|
{{ document.body|safe }}
|
|
|
|
{% endblock %}
|
|
|
|
|
|
|
|
{% block sidebar %}
|
2010-06-04 16:13:53 -05:00
|
|
|
{% endblock %}
|