aboutsummaryrefslogtreecommitdiff
path: root/mensa/frontends
diff options
context:
space:
mode:
Diffstat (limited to 'mensa/frontends')
-rw-r--r--mensa/frontends/html.py33
-rw-r--r--mensa/frontends/html.yapsy-plugin3
-rw-r--r--mensa/frontends/plain-text.py4
3 files changed, 40 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))
diff --git a/mensa/frontends/html.yapsy-plugin b/mensa/frontends/html.yapsy-plugin
new file mode 100644
index 0000000..135ad17
--- /dev/null
+++ b/mensa/frontends/html.yapsy-plugin
@@ -0,0 +1,3 @@
+[Core]
+Name = HTML Output
+Module = html \ No newline at end of file
diff --git a/mensa/frontends/plain-text.py b/mensa/frontends/plain-text.py
index 501be54..7a31371 100644
--- a/mensa/frontends/plain-text.py
+++ b/mensa/frontends/plain-text.py
@@ -7,9 +7,13 @@ class TextRenderer(IPlugin) :
vegkeys = [ "", "Vegetarian", "Vegan" ]
for restaurant, food in foods :
cat = []
+ if not food :
+ continue
r = r+"*"*20+restaurant.human_name+"*"*20+"\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 :
cat.append(i.category)
if not i.category == None :