First pass at spec viewing system

This commit is contained in:
str4d
2015-11-10 08:15:11 +00:00
parent 8edd5a8df1
commit 3816f2f6be
20 changed files with 147 additions and 0 deletions

View File

@ -103,6 +103,7 @@ GETTEXT_DOMAIN_MAPPING = {
TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), 'pages')
STATIC_DIR = os.path.join(os.path.dirname(__file__), 'static')
SPEC_DIR = os.path.join(os.path.dirname(__file__), 'spec')
BLOG_DIR = os.path.join(os.path.dirname(__file__), 'blog')
MEETINGS_DIR = os.path.join(os.path.dirname(__file__), 'meetings/logs')
SITE_DIR = os.path.join(TEMPLATE_DIR, 'site')

View File

@ -0,0 +1,40 @@
{% extends "global/layout.html" %}
{% block title %}I2P Specification Documents{% endblock %}
{% block content %}
This page provides the specifications for various components of the I2P network
and router software. These are living documents, and the specifications are
updated as modifications are made to the network and software.
<ul><li>
"Last updated" is the last date when the specification given within a document
was altered in any way, except for changes to the "accurate for" information.
</li><li>
The "accurate for" column gives the version of the I2P network and reference
Java implementation that the document is verified to be valid for. Because the
documents are usually only updated when changes are made, the listed versions
can sometimes be several releases behind. This does not mean that documents with
old listed versions are necessarily inaccurate, but small differences may creep
in during the course of development. Periodic reviews are conducted to update
the "accurate for" information.
</li></ul>
<table>
<tr>
<th>Title</th>
<th>Last updated</th>
<th>Accurate for</th>
<th>Link</th>
</tr>
{% for spec in specs %}
<tr>
<td>{{ spec.title }}</td>
<td><time>{{ spec.lastupdated }}</time></td>
<td>{{ spec.accuratefor }}</td>
<td>
<a href="{{ get_url('spec_show', name=spec.name) }}">HTML</a> |
<a href="{{ get_url('spec_show_txt', name=spec.name) }}">TXT</a>
</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -0,0 +1,10 @@
{% extends "global/layout.html" %}
{%- from "global/macros" import render_categories with context -%}
{% block title %}{{ title }}{% endblock %}
{% block lastupdated %}{{ meta.lastupdated }}{% endblock %}
{% block accuratefor %}{{ meta.accuratefor }}{% endblock %}
{% block content %}
{% autoescape false %}
{{ body }}
{% endautoescape %}
{% endblock %}

0
i2p2www/spec/__init__.py Normal file
View File

88
i2p2www/spec/views.py Normal file
View File

@ -0,0 +1,88 @@
import codecs
from docutils.core import publish_parts
from flask import (
abort,
g,
make_response,
redirect,
render_template,
render_template_string,
request,
safe_join,
url_for,
)
import os.path
from i2p2www import SPEC_DIR
from i2p2www import helpers
SPEC_METATAGS = {
'accuratefor': None,
'lastupdated': None,
}
SPEC_LIST_METATAGS = [
]
def spec_index():
specs = []
for f in os.listdir(SPEC_DIR):
if f.endswith('.rst'):
path = safe_join(SPEC_DIR, f)
# read file
with codecs.open(path, encoding='utf-8') as fd:
content = fd.read()
parts = publish_parts(source=content, source_path=SPEC_DIR, writer_name="html")
meta = get_metadata_from_meta(parts['meta'])
spec = {
'name': f[:-4],
'title': parts['title'],
}
spec.update(meta)
specs.append(spec)
return render_template('spec/index.html', specs=specs)
def spec_show(name, txt=False):
# check if that file actually exists
path = safe_join(SPEC_DIR, name + '.rst')
if not os.path.exists(path):
abort(404)
# read file
with codecs.open(path, encoding='utf-8') as fd:
content = fd.read()
if txt:
# Strip out RST
content = content.replace('.. meta::\n', '')
content = content.replace('.. raw:: html\n\n', '')
content = content.replace('\n.. [', '\n[')
content = content.replace(']_', ']')
# Change highlight formatter
content = content.replace('{% highlight', "{% highlight formatter='textspec'")
# render the post with Jinja2 to handle URLs etc.
rendered_content = render_template_string(content)
rendered_content = rendered_content.replace('</pre></div>', ' </pre></div>')
if txt:
# Send response
r = make_response(rendered_content)
r.mimetype = 'text/plain'
return r
# publish the post with docutils
parts = publish_parts(source=rendered_content, source_path=SPEC_DIR, writer_name="html")
meta = get_metadata_from_meta(parts['meta'])
return render_template('spec/show.html', title=parts['title'], body=parts['fragment'], name=name, meta=meta)
def spec_show_txt(name):
return spec_show(name, True)
def get_metadata_from_meta(meta):
return helpers.get_metadata_from_meta(meta, SPEC_METATAGS, SPEC_LIST_METATAGS)

View File

@ -30,6 +30,9 @@ def utility_processor():
else:
return url_for('site_show', lang=lang)
def get_spec_url(name):
return url_for('spec_show', name=name, _external=True)
# Shorthand for getting a language-specific url
def get_url_with_lang(endpoint, **args):
lang = 'en'
@ -111,6 +114,7 @@ def utility_processor():
change_theme=change_theme,
logo_url=get_logo_for_theme,
site_url=get_site_url,
spec_url=get_spec_url,
get_url=get_url_with_lang,
is_rtl=is_rtl_lang,
get_flag=get_flag,

View File

@ -44,6 +44,10 @@ url('/', 'views.main_index')
url('/<lang:lang>/', 'views.site_show', defaults={'page': 'index'})
url('/<lang:lang>/<path:page>', 'views.site_show')
url('/spec', 'spec.views.spec_index')
url('/spec/<string:name>', 'spec.views.spec_show')
url('/spec/<string:name>.txt', 'spec.views.spec_show_txt')
url('/<lang:lang>/papers/', 'anonbib.views.papers_list')
url('/<lang:lang>/papers/bibtex', 'anonbib.views.papers_bibtex')
url('/<lang:lang>/papers/by-<string:choice>', 'anonbib.views.papers_list')