blob: b32a2748af234b91bb8e10d30f9f07009b914fc3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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__())
|