From 48d5ae7d45a2856b2c66b7c52d0566cad8dbc1b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kom=D1=8Fpa?= Date: Sat, 24 Jul 2010 17:07:53 +0300 Subject: [PATCH] Eval cond() --- src/mapcss/Eval.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mapcss/Eval.py b/src/mapcss/Eval.py index f680203..7f37ea4 100644 --- a/src/mapcss/Eval.py +++ b/src/mapcss/Eval.py @@ -80,6 +80,8 @@ class Eval(): "any": m_any, "min": m_min, "max": m_max, + "cond": m_cond, + "boolean": m_boolean })) except: return "" @@ -88,6 +90,19 @@ class Eval(): def __repr__(self): return "eval(%s)"%repr(self.expr) +def m_boolean(expr): + expr = str(expr) + if expr in ("", "0", "no", "false", "False"): + return False + else: + return True + +def m_cond(why, yes, no): + if m_boolean(why): + return yes + else: + return no + def m_min(*x): """ min() MapCSS Feature @@ -136,7 +151,12 @@ def m_metric(x, t): # FIXME: add ft, m and friends x = x.strip() try: - if x[-1] == "m": + if x[-2:] in ("cm", "CM", "см"): + print x, float(x[0:-2])*float(t)/100 + return float(x[0:-2])*float(t)/100 + if x[-2:] in ("mm", "MM", "мм"): + return float(x[0:-2])*float(t)/1000 + if x[-1] in ("m", "M", "м"): return float(x[0:-1])*float(t) except: return ""