Skip to content

Commit 6ff1d92

Browse files
committed
Redo example
1 parent 49be769 commit 6ff1d92

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

examples/document.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
22
"MyBook": {
33
"title": "My life in Python",
4-
"pages": {
5-
"1": {},
6-
"2": {}
4+
"sections": {
5+
"Abstract": {
6+
"paragraphs": {
7+
"contents": "Blah blah blah"
8+
}
9+
},
10+
"Chapter 1": {}
711
}
812
}
913
}

examples/document.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ def __init__(self, **kwargs):
1212

1313
self.allowed_children = collections.OrderedDict(
1414
[
15-
("pages", ("The pages", Page)),
15+
("sections", ("The Sections", Section)),
1616
]
1717
)
1818

19+
#self.add_allowed_child("sections", "The sections of the document", Section)
20+
21+
1922
self.allowed_fields = collections.OrderedDict(
2023
[
2124
("title", ("Document title", str)),
@@ -32,39 +35,43 @@ def __init__(self, **kwargs):
3235
super(Document, self).__init__(**kwargs)
3336

3437

35-
class Page(BaseWithId):
38+
class Section(BaseWithId):
3639

37-
_definition = "A model of a page"
40+
_definition = "A model of a section of the document"
3841

3942
def __init__(self, **kwargs):
4043

4144
self.allowed_children = collections.OrderedDict(
4245
[
43-
("lines", ("The pages", Line)),
46+
("paragraphs", ("The paragraphs", Paragraph)),
4447
]
4548
)
4649

47-
super(Page, self).__init__(**kwargs)
50+
super(Section, self).__init__(**kwargs)
4851

4952

50-
class Line(Base):
53+
class Paragraph(Base):
5154

52-
_definition = "A model of a line"
55+
_definition = "A model of a paragraph"
5356

5457
def __init__(self, **kwargs):
5558

5659
self.allowed_fields = collections.OrderedDict(
5760
[
58-
("title", ("Document title", str)),
61+
("contents", ("Paragraph contents", str)),
5962
]
6063
)
6164

65+
super(Paragraph, self).__init__(**kwargs)
6266

6367
doc = Document(id="MyBook")
6468
doc.title = "My life in Python"
6569

66-
doc.pages.append(Page(id=1))
67-
doc.pages.append(Page(id=2))
70+
a = Section(id="Abstract")
71+
p = Paragraph(contents='Blah blah blah')
72+
a.paragraphs.append(p)
73+
doc.sections.append(a)
74+
doc.sections.append(Section(id="Chapter 1"))
6875

6976
print(doc)
7077

examples/document.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
MyBook:
22
title: My life in Python
3-
pages:
4-
'1': {}
5-
'2': {}
3+
sections:
4+
Abstract:
5+
paragraphs:
6+
contents: Blah blah blah
7+
Chapter 1: {}

0 commit comments

Comments
 (0)