-
-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathhtml_paths.py
58 lines (40 loc) · 1.15 KB
/
html_paths.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import cobble
from . import html
def path(elements):
return HtmlPath(elements)
def element(names, attributes=None, class_names=None, fresh=None, separator=None):
if attributes is None:
attributes = {}
if class_names is None:
class_names = []
if fresh is None:
fresh = False
if class_names:
attributes["class"] = " ".join(class_names)
return HtmlPathElement(html.tag(
tag_names=names,
attributes=attributes,
collapsible=not fresh,
separator=separator,
))
@cobble.data
class HtmlPath(object):
elements = cobble.field()
def wrap(self, generate_nodes):
nodes = generate_nodes()
for element in reversed(self.elements):
nodes = element.wrap_nodes(nodes)
return nodes
@cobble.data
class HtmlPathElement(object):
tag = cobble.field()
def wrap(self, generate_nodes):
return self.wrap_nodes(generate_nodes())
def wrap_nodes(self, nodes):
element = html.Element(self.tag, nodes)
return [element]
empty = path([])
class ignore(object):
@staticmethod
def wrap(generate_nodes):
return []