diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2018-03-01 17:47:10 +0100 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2018-03-01 17:47:10 +0100 |
commit | 7355b3e3503ca95e1ee11ebb814c3f2551143a86 (patch) | |
tree | 510ae83289ef0f8bcef05fa52c6c7b5a8727bc35 /mensa/frontends/html.py | |
parent | ff5121b7512f4677ddca1e922e4c66ca6b546694 (diff) | |
download | mensa-7355b3e3503ca95e1ee11ebb814c3f2551143a86.tar.gz mensa-7355b3e3503ca95e1ee11ebb814c3f2551143a86.tar.bz2 mensa-7355b3e3503ca95e1ee11ebb814c3f2551143a86.zip |
Bumped version to 0.3, added html formatter
Diffstat (limited to 'mensa/frontends/html.py')
-rw-r--r-- | mensa/frontends/html.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/mensa/frontends/html.py b/mensa/frontends/html.py new file mode 100644 index 0000000..8ffec37 --- /dev/null +++ b/mensa/frontends/html.py @@ -0,0 +1,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)) |