summaryrefslogtreecommitdiff
path: root/css.py
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2015-11-21 20:30:02 +0100
committerYves Fischer <yvesf-git@xapek.org>2015-11-21 20:30:02 +0100
commit49ac3c20cb77b90493ce79b4e31cf0f58cba0116 (patch)
tree7a2199b5a6d3a5c6d26ee896b243676c918268cd /css.py
parent76b682ac3073638fda5d6caa23594dd56bf6f06d (diff)
downloadwatchnews-49ac3c20cb77b90493ce79b4e31cf0f58cba0116.tar.gz
watchnews-49ac3c20cb77b90493ce79b4e31cf0f58cba0116.zip
improve template
Diffstat (limited to 'css.py')
-rw-r--r--css.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/css.py b/css.py
new file mode 100644
index 0000000..b32a274
--- /dev/null
+++ b/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__())