From 6080b38fb2b6b3c1017bdd34bb7552bc7e26a4a0 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sun, 22 Nov 2015 00:25:56 +0100 Subject: project restructure make it a proper python package --- watchnews/css.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 watchnews/css.py (limited to 'watchnews/css.py') diff --git a/watchnews/css.py b/watchnews/css.py new file mode 100644 index 0000000..b32a274 --- /dev/null +++ b/watchnews/css.py @@ -0,0 +1,29 @@ +#!/usr/bin/python3 +import re + + +class Rule: + + def __init__(self, *path, **properties): + self.path = path + self.properties = properties + + def _f(self, prop): + key, value = prop + key = re.sub("([A-Z])", "-\\1", key).lower() + return " {}: {};".format(key, value) + + def __format__(self): + result = " ".join(self.path) + result += " {\n" + result += "\n".join(map(self._f, self.properties.items())) + result += "\n}\n" + return result + + +def string(*rules): + return "\n".join(map(lambda r: r.__format__(), rules)) + +if __name__ == "__main__": + print("CSS Demo") + print(Rule(".foo", "#blah", backgroundColor="red").__format__()) -- cgit v1.2.1