Skip to content

Commit 44a8595

Browse files
committed
Convert the test templates to jinja2
1 parent b023876 commit 44a8595

5 files changed

Lines changed: 74 additions & 112 deletions

File tree

code/python/foafroll.xml.tmpl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
xmlns:dc="http://purl.org/dc/elements/1.1/"
88
>
99
<foaf:Group>
10-
<foaf:name><TMPL_VAR name></foaf:name>
11-
<foaf:homepage><TMPL_VAR link ESCAPE="HTML"></foaf:homepage>
12-
<rdfs:seeAlso rdf:resource="<TMPL_VAR uri ESCAPE="HTML">" />
10+
<foaf:name>{{ name }}</foaf:name>
11+
<foaf:homepage>{{ link | e }}</foaf:homepage>
12+
<rdfs:seeAlso rdf:resource="{{ uri | e }}" />
1313

14-
<TMPL_LOOP Channels>
14+
{% for channel in Channels %}
1515
<foaf:member>
1616
<foaf:Agent>
17-
<foaf:name><TMPL_VAR name></foaf:name>
17+
<foaf:name>{{ channel.name }}</foaf:name>
1818
<foaf:weblog>
19-
<foaf:Document rdf:about="<TMPL_VAR link ESCAPE="HTML">">
20-
<dc:title><TMPL_VAR title></dc:title>
19+
<foaf:Document rdf:about="{{ channel.link | e }}">
20+
<dc:title>{{ channel.title }}</dc:title>
2121
<rdfs:seeAlso>
22-
<rss:channel rdf:about="<TMPL_VAR uri ESCAPE="HTML">" />
22+
<rss:channel rdf:about="{{ channel.uri | e }}" />
2323
</rdfs:seeAlso>
2424
</foaf:Document>
2525
</foaf:weblog>
2626
</foaf:Agent>
2727
</foaf:member>
28-
</TMPL_LOOP>
28+
{% endfor %}
2929

3030
</foaf:Group>
3131
</rdf:RDF>

code/python/index.html.tmpl

Lines changed: 20 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,49 @@
11
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
22
<html>
33

4-
### Planet HTML template.
5-
###
6-
### This is intended to demonstrate and document Planet's templating
7-
### facilities, and at the same time provide a good base for you to
8-
### modify into your own design.
9-
###
10-
### The output's a bit boring though, if you're after less documentation
11-
### and more instant gratification, there's an example with a much
12-
### prettier output in the fancy-examples/ directory of the Planet source.
13-
14-
### Lines like this are comments, and are automatically removed by the
15-
### templating engine before processing.
16-
17-
18-
### Planet makes a large number of variables available for your templates.
19-
### See INSTALL for the complete list. The raw value can be placed in your
20-
### output file using <TMPL_VAR varname>. We'll put the name of our
21-
### Planet in the page title and again in an h1.
22-
234
<head>
24-
<title><TMPL_VAR name></title>
5+
<title>{{ name }}</title>
256
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
26-
<meta name="generator" content="<TMPL_VAR generator>">
7+
<meta name="generator" content="{{ generator }}">
278
</head>
289

2910
<body>
30-
<h1><TMPL_VAR name></h1>
31-
32-
### One of the two loops available is the Channels loop. This allows you
33-
### to easily create a list of subscriptions, which is exactly what we'll do
34-
### here.
35-
36-
### Note that we can also expand variables inside HTML tags, but we need
37-
### to be cautious and HTML-escape any illegal characters using the form
38-
### <TMPL_VAR varname ESCAPE="HTML">
11+
<h1>{{ name }}</h1>
3912

4013
<div style="float: right">
4114
<h2>Subscriptions</h2>
4215
<ul>
43-
<TMPL_LOOP Channels>
44-
<li><a href="<TMPL_VAR link ESCAPE="HTML">" title="<TMPL_VAR title ESCAPE="HTML">"><TMPL_VAR name></a> <a href="<TMPL_VAR uri ESCAPE="HTML">">(feed)</a></li>
45-
</TMPL_LOOP>
16+
{% for channel in Channels %}
17+
<li><a href="{{ channel.link | e }}" title="{{ channel.title | e }}">{{ channel.name }}</a> <a href="{{ channel.uri | e }}">(feed)</a></li>
18+
{% endfor %}
4619
</ul>
4720
</div>
4821

49-
### The other loop is the Items loop, which will get iterated for each
50-
### news item.
51-
52-
<TMPL_LOOP Items>
53-
54-
### Visually distinguish articles from different days by checking for
55-
### the new_date flag. This demonstrates the <TMPL_IF varname> ... </TMPL_IF>
56-
### check.
57-
58-
<TMPL_IF new_date>
59-
<h2><TMPL_VAR new_date></h2>
60-
</TMPL_IF>
61-
62-
### Group consecutive articles by the same author together by checking
63-
### for the new_channel flag.
22+
{% for item in Items %}
6423

65-
<TMPL_IF new_channel>
66-
<h3><a href="<TMPL_VAR channel_link ESCAPE="HTML">" title="<TMPL_VAR channel_title ESCAPE="HTML">"><TMPL_VAR channel_name></a></h3>
67-
</TMPL_IF>
24+
{% if item.new_date %}
25+
<h2>{{ item.new_date }}</h2>
26+
{% endif %}
6827

28+
{% if item.new_channel %}
29+
<h3><a href="{{ item.channel_link | e }}" title="{{ item.channel_title | e }}">{{ item.channel_name }}</a></h3>
30+
{% endif %}
6931

70-
<TMPL_IF title>
71-
<h4><a href="<TMPL_VAR link ESCAPE="HTML">"><TMPL_VAR title></a></h4>
72-
</TMPL_IF>
32+
{% if item.title %}
33+
<h4><a href="{{ item.link | e }}">{{ item.title }}</a></h4>
34+
{% endif %}
7335
<p>
74-
<TMPL_VAR content>
36+
{{ item.content }}
7537
</p>
7638
<p>
77-
<em><a href="<TMPL_VAR link ESCAPE="HTML">"><TMPL_IF creator>by <TMPL_VAR creator> at </TMPL_IF><TMPL_VAR date></a></em>
39+
<em><a href="{{ item.link | e }}">{% if item.creator %}by {{ item.creator }} at {% endif %}{{ item.date }}</a></em>
7840
</p>
79-
</TMPL_LOOP>
41+
{% endfor %}
8042

8143
<hr>
8244
<p>
8345
<a href="http://www.planetplanet.org/">Powered by Planet!</a><br>
84-
<em>Last updated: <TMPL_VAR date></em>
46+
<em>Last updated: {{ date }}</em>
8547
</p>
8648
</body>
8749

code/python/opml.xml.tmpl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?xml version="1.0"?>
22
<opml version="1.1">
33
<head>
4-
<title><TMPL_VAR name></title>
5-
<dateCreated><TMPL_VAR date_822></dateCreated>
6-
<dateModified><TMPL_VAR date_822></dateModified>
7-
<ownerName><TMPL_VAR owner_name></ownerName>
8-
<ownerEmail><TMPL_VAR owner_email></ownerEmail>
4+
<title>{{ name }}</title>
5+
<dateCreated>{{ date_822 }}</dateCreated>
6+
<dateModified>{{ date_822 }}</dateModified>
7+
<ownerName>{{ owner_name }}</ownerName>
8+
<ownerEmail>{{ owner_email }}</ownerEmail>
99
</head>
10-
10+
1111
<body>
12-
<TMPL_LOOP Channels>
13-
<outline text="<TMPL_VAR name ESCAPE="HTML">" xmlUrl="<TMPL_VAR uri ESCAPE="HTML">"/>
14-
</TMPL_LOOP>
12+
{% for channel in Channels %}
13+
<outline text="{{ channel.name | e }}" xmlUrl="{{ channel.uri | e }}"/>
14+
{% endfor %}
1515
</body>
1616
</opml>

code/python/rss10.xml.tmpl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,32 @@
66
xmlns:content="http://purl.org/rss/1.0/modules/content/"
77
xmlns="http://purl.org/rss/1.0/"
88
>
9-
<channel rdf:about="<TMPL_VAR link ESCAPE="HTML">">
10-
<title><TMPL_VAR name></title>
11-
<link><TMPL_VAR link ESCAPE="HTML"></link>
12-
<description><TMPL_VAR name> - <TMPL_VAR link ESCAPE="HTML"></description>
9+
<channel rdf:about="{{ link | e }}">
10+
<title>{{ name }}</title>
11+
<link>{{ link | e }}</link>
12+
<description>{{ name }} - {{ link | e }}</description>
1313

1414
<items>
1515
<rdf:Seq>
16-
<TMPL_LOOP Items>
17-
<rdf:li rdf:resource="<TMPL_VAR id ESCAPE="HTML">" />
18-
</TMPL_LOOP>
16+
{% for item in Items %}
17+
<rdf:li rdf:resource="{{ item.id | e }}" />
18+
{% endfor %}
1919
</rdf:Seq>
2020
</items>
2121
</channel>
2222

23-
<TMPL_LOOP Items>
24-
<item rdf:about="<TMPL_VAR id ESCAPE="HTML">">
25-
<title><TMPL_VAR channel_name><TMPL_IF title>: <TMPL_VAR title></TMPL_IF></title>
26-
<link><TMPL_VAR link ESCAPE="HTML"></link>
27-
<TMPL_IF content>
28-
<content:encoded><TMPL_VAR content ESCAPE="HTML"></content:encoded>
29-
</TMPL_IF>
30-
<dc:date><TMPL_VAR date_iso></dc:date>
31-
<TMPL_IF creator>
32-
<dc:creator><TMPL_VAR creator></dc:creator>
33-
</TMPL_IF>
23+
{% for item in Items %}
24+
<item rdf:about="{{ item.id | e }}">
25+
<title>{{ item.channel_name }}{% if item.title %}: {{ item.title }}{% endif %}</title>
26+
<link>{{ item.link | e }}</link>
27+
{% if item.content %}
28+
<content:encoded>{{ item.content | e }}</content:encoded>
29+
{% endif %}
30+
<dc:date>{{ item.date_iso }}</dc:date>
31+
{% if item.creator %}
32+
<dc:creator>{{ item.creator }}</dc:creator>
33+
{% endif %}
3434
</item>
35-
</TMPL_LOOP>
35+
{% endfor %}
3636

3737
</rdf:RDF>

code/python/rss20.xml.tmpl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
33

44
<channel>
5-
<title><TMPL_VAR name></title>
6-
<link><TMPL_VAR link ESCAPE="HTML"></link>
5+
<title>{{ name }}</title>
6+
<link>{{ link | e }}</link>
77
<language>en</language>
8-
<description><TMPL_VAR name> - <TMPL_VAR link ESCAPE="HTML"></description>
8+
<description>{{ name }} - {{ link | e }}</description>
99

10-
<TMPL_LOOP Items>
11-
<item>
12-
<title><TMPL_VAR channel_name><TMPL_IF title>: <TMPL_VAR title></TMPL_IF></title>
13-
<guid><TMPL_VAR id ESCAPE="HTML"></guid>
14-
<link><TMPL_VAR link ESCAPE="HTML"></link>
15-
<TMPL_IF content>
16-
<description><TMPL_VAR content ESCAPE="HTML"></description>
17-
</TMPL_IF>
18-
<pubDate><TMPL_VAR date_822></pubDate>
19-
<TMPL_IF creator>
20-
<dc:creator><TMPL_VAR creator></dc:creator>
21-
</TMPL_IF>
22-
</item>
23-
</TMPL_LOOP>
10+
{% for item in Items %}
11+
<item>
12+
<title>{{ item.channel_name }}{% if item.title %}: {{ item.title }}{% endif %}</title>
13+
<guid>{{ item.id | e }}</guid>
14+
<link>{{ item.link | e }}</link>
15+
{% if item.content %}
16+
<description>{{ item.content | e }}</description>
17+
{% endif %}
18+
<pubDate>{{ item.date_822 }}</pubDate>
19+
{% if item.creator %}
20+
<dc:creator>{{ item.creator }}</dc:creator>
21+
{% endif %}
22+
</item>
23+
{% endfor %}
2424

2525
</channel>
2626
</rss>

0 commit comments

Comments
 (0)