Added snippet database to the website.

This commit is contained in:
Armin Ronacher 2010-05-03 11:20:52 +02:00
parent a81cf3a67c
commit 0ab7a9cb67
22 changed files with 825 additions and 118 deletions

View file

@ -0,0 +1,19 @@
{% extends "snippets/layout.html" %}
{% block title %}{{ category.name }}{% endblock %}
{% block body %}
<h2>{{ category.name }}</h2>
{% if category.count > 3 %}
<p>
Here you can find all {{ category.count }} snippets of this
category. You can also
{% else %}
This category is pretty empty so far. Why not
{% endif %}
<a href="{{ url_for('snippets.new',
category=category.slug) }}">add a new one</a>.
<ul>
{% for snippet in snippets %}
<li><a href="{{ snippet.url }}">{{ snippet.title }}</a>
{% endfor %}
</ul>
{% endblock %}

View file

@ -0,0 +1,44 @@
{% extends "snippets/layout.html" %}
{% block head %}
{{ super() }}
<style type=text/css>
h1 { background-image: url(/static/new-snippet.png); }
</style>
{% endblock %}
{% block title %}Edit Snippet “{{ snippet.title }}”{% endblock %}
{% block body %}
<script type=text/javascript>
$(function() {
$('input[name="delete"]').click(function() {
if (!confirm("Do you really want to delete this Snippet?\n\n" +
"THIS CANNOT BE UNDONE!"))
return false;
});
});
</script>
<form action="" method=post>
<dl>
<dt>Title:
<dd><input type=text name=title value="{{ form.title }}" size=40>
<dt>Category:
<dd>
<select name=category>
{% for category in categories %}
<option{% if category.id == form.category %} selected{% endif
%} value={{ category.id }}>{{ category.name }}</option>
{% endfor %}
</select>
</dl>
<p><textarea name=body cols=40 rows=20>{{ form.body }}</textarea>
<p>
<input type=submit value="Edit Snippet">
<input type=submit name=delete value="Delete">
<input type=submit name=preview value="Preview">
</form>
{% if preview %}
<div id=preview>
<h2>Preview</h2>
{{ preview }}
</div>
{% endif %}
{% endblock %}

View file

@ -4,14 +4,33 @@
<p>
Welcome to the Flask snippet archive. This is the place where anyone
can drop helpful pieces of code for others to use.
{% if g.user %}
<p>
You're signed in as “<span title="{{ g.user.openid }}">{{ g.user.name
}}</span>”. You can <a href="{{ url_for('general.logout')
}}">sign out</a> here after you're done if you want.
{% else %}
<p>
In order to add snippets to this page or to add comments, all you need
is an <a href=http://en.wikipedia.org/wiki/OpenID>OpenID</a> account.
<form action=/snippets/search/ method=get>
<p>
Search snippets:
<input type=text name=q size=30>
<input type=submit value=Search>
</form>
You can <a href="{{ url_for('general.login') }}">sign in</a> here.
{% endif %}
<p>
Want to share something? Then add a
<a href="{{ url_for('snippets.new') }}">new snippet</a>.
<h2>Snippets by Category</h2>
<ul>
{% for category in categories %}
<li><a href="{{ category.url }}">{{ category.name }}</a> ({{ category.count }})
{% endfor %}
</ul>
{% if recent %}
<h2>Recently Added</h2>
<ul>
{% for snippet in recent %}
<li><a href="{{ snippet.url }}">{{ snippet.title }}</a> in
<a href="{{ snippet.category.url }}">{{ snippet.category.name }}</a>
{% endfor %}
</ul>
{% endif %}
{% endblock %}

View file

@ -2,8 +2,7 @@
{% block head %}
{{ super() }}
<style type=text/css>
h1 { margin: 0 0 30px 0; background: url(/static/snippets.png) no-repeat center; height: 165px; }
h1 span { display: none; }
h1 { background-image: url(/static/snippets.png); }
</style>
{% endblock %}
{% block body_title %}

View file

@ -0,0 +1,43 @@
{% extends "snippets/layout.html" %}
{% block head %}
{{ super() }}
<style type=text/css>
h1 { background-image: url(/static/new-snippet.png); }
</style>
{% endblock %}
{% block title %}New Snippet{% endblock %}
{% block body %}
<p>
Got something to share? Here you can create a new snippet and
publish it here. By adding the snippet here, you hereby grant
the user of the snippet all rights.
<p>
The syntax used for snippets is <a href="http://www.wikicreole.org/">Creole</a>.
To highlight Python code or Jinja templates, prefix your code blocks
with <code>#!python</code>, <code>#!html+jinja</code> or any other
<a href="http://pygments.org/docs/lexers">Pygments lexer name</a>.
<form action="" method=post>
<dl>
<dt>Title:
<dd><input type=text name=title value="{{ request.form.title }}" size=40>
<dt>Category:
<dd>
<select name=category>
{% for category in categories %}
<option{% if category.id == active_category %} selected{% endif
%} value={{ category.id }}>{{ category.name }}</option>
{% endfor %}
</select>
</dl>
<p><textarea name=body cols=40 rows=20>{{ request.form.body }}</textarea>
<p>
<input type=submit value="Add Snippet">
<input type=submit name=preview value="Preview">
</form>
{% if preview %}
<div id=preview>
<h2>Preview</h2>
{{ preview }}
</div>
{% endif %}
{% endblock %}

View file

@ -0,0 +1,38 @@
{% extends "snippets/layout.html" %}
{% block title %}{{ snippet.title }}{% endblock %}
{% block body %}
<h2>{{ snippet.title }}</h2>
<p class=snippet-author>By {{ snippet.author.name }}
filed in <a href="{{ snippet.category.url }}">{{ snippet.category.name }}</a>
{% if snippet.author == g.user %}
(<a href="{{ url_for('snippets.edit', id=snippet.id) }}">edit</a>)
{% endif %}
{{ snippet.rendered_body }}
{% if snippet.comments or g.user %}
<div id=comment-box>
{% if snippet.comments %}
<h2>Comments</h2>
<ul class=comments>
{% for comment in snippet.comments %}
<li>
<p class=title>
{{ comment.title or "Comment" }}
by {{ comment.author.name }}
on {{ comment.pub_date.strftime('%Y-%m-%d @ %H:%M') }}
<div class=body>{{ comment.rendered_text }}</div></li>
{% endfor %}
</ul>
{% endif %}
{% if g.user %}
<div id=add-comment>
<h2>Add Comment</h2>
<form action=#add-comment method=post>
<p>Title: <input type=text name=title value="{{ request.form.title }}" size=30>
<p><textarea name=text cols=40 rows=8>{{ request.form.text }}</textarea>
<p><input type=submit value="Add Comment">
</form>
</div>
{% endif %}
</div>
{% endif %}
{% endblock %}