blob: 8ffec375e6236907f78bee1520edbcb28727b1f9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
from mensa import base
from yapsy.IPlugin import IPlugin
from xml.sax.saxutils import escape as esc
class HTMLRenderer(IPlugin) :
def render (self, foods, **options) :
## Expects list of tuples with (Restaurant, Foodlist)
r = ""
vegkeys = [ "", "Vegetarian", "Vegan" ]
for restaurant, food in foods :
cat = []
if not food :
continue
r = r+"<div class=\"restaurant\"><h3>"+esc(restaurant.human_name)+"</h3>"+"\n"#+base.formt(food)
food.sort(key=lambda foo: foo.category)
for i in food:
if options["only_veggie"] and options["only_veggie"] > i.veggie :
continue
if not i.category in cat :
if cat :
r = r + "</ul>"
cat.append(i.category)
if not i.category == None :
r=r+ "<h4>"+esc(i.category)+"</h4><ul class=\"food-by-cat\">\n"
r=r+"<li class=\"fooditem\" ><span class=\"name\">" + esc(i.name) + "</span><span class=\"price\">"+ esc(i.price) + "</span><span class=\"veggie\">"+ esc(vegkeys[i.veggie])+"</span>\n"
if i.desc :
r = r+"<div class=\"description\">"+esc(i.desc)+"</div>\n"
r = r+"</div>"
r = r
print(r)
def register_renderer(self) :
base.register_renderer(base.Renderer("html", "HTML Renderer", self))
|