-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathrun_html_render.py
More file actions
223 lines (133 loc) · 5 KB
/
run_html_render.py
File metadata and controls
223 lines (133 loc) · 5 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/usr/bin/env python
"""
a simple script can run and test your html rendering classes.
Uncomment the steps as you add to your rendering.
"""
from io import StringIO
# importing the html_rendering code with a short name for easy typing.
import html_render as hr
# reloading in case you are running this in iPython
# -- we want to make sure the latest version is used
import importlib
importlib.reload(hr)
# writing the file out:
def render_page(page, filename):
"""
render the tree of elements
This uses StringIO to render to memory, then dump to console and
write to file -- very handy!
"""
f = StringIO()
page.render(f, " ")
f.seek(0)
print(f.read())
f.seek(0)
open(filename, 'w').write(f.read())
# Step 1
#########
page = hr.Element()
page.append("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text")
page.append("And here is another piece of text -- you should be able to add any number")
render_page(page, "test_html_output1_kr.html")
# ## Step 2
# ##########
#page = hr.Html()
#body = hr.Body()
#body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text"))
#body.append(hr.P("And here is another piece of text -- you should be able to add any number"))
#page.append(body)
#render_page(page, "test_html_output2_krhtml")
# # Step 3
# ##########
# page = hr.Html()
# head = hr.Head()
# head.append(hr.Title("PythonClass = Revision 1087:"))
# page.append(head)
# body = hr.Body()
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text"))
# body.append(hr.P("And here is another piece of text -- you should be able to add any number"))
# page.append(body)
# render_page(page, "test_html_output3.html")
# # Step 4
# ##########
# page = hr.Html()
# head = hr.Head()
# head.append(hr.Title("PythonClass = Revision 1087:"))
# page.append(head)
# body = hr.Body()
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
# style="text-align: center; font-style: oblique;"))
# page.append(body)
# render_page(page, "test_html_output4.html")
# # Step 5
# #########
# page = hr.Html()
# head = hr.Head()
# head.append(hr.Title("PythonClass = Revision 1087:"))
# page.append(head)
# body = hr.Body()
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
# style="text-align: center; font-style: oblique;"))
# body.append(hr.Hr())
# page.append(body)
# render_page(page, "test_html_output5.html")
# # Step 6
# #########
# page = hr.Html()
# head = hr.Head()
# head.append(hr.Title("PythonClass = Revision 1087:"))
# page.append(head)
# body = hr.Body()
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
# style="text-align: center; font-style: oblique;"))
# body.append(hr.Hr())
# body.append("And this is a ")
# body.append( hr.A("http://google.com", "link") )
# body.append("to google")
# page.append(body)
# render_page(page, "test_html_output6.html")
# # Step 7
# #########
# page = hr.Html()
# head = hr.Head()
# head.append(hr.Title("PythonClass = Revision 1087:"))
# page.append(head)
# body = hr.Body()
# body.append( hr.H(2, "PythonClass - Class 6 example") )
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
# style="text-align: center; font-style: oblique;"))
# body.append(hr.Hr())
# list = hr.Ul(id="TheList", style="line-height:200%")
# list.append( hr.Li("The first item in a list") )
# list.append( hr.Li("This is the second item", style="color: red") )
# item = hr.Li()
# item.append("And this is a ")
# item.append( hr.A("http://google.com", "link") )
# item.append("to google")
# list.append(item)
# body.append(list)
# page.append(body)
# render_page(page, "test_html_output7.html")
# # Step 8
# ########
# page = hr.Html()
# head = hr.Head()
# head.append( hr.Meta(charset="UTF-8") )
# head.append(hr.Title("PythonClass = Revision 1087:"))
# page.append(head)
# body = hr.Body()
# body.append( hr.H(2, "PythonClass - Class 6 example") )
# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
# style="text-align: center; font-style: oblique;"))
# body.append(hr.Hr())
# list = hr.Ul(id="TheList", style="line-height:200%")
# list.append( hr.Li("The first item in a list") )
# list.append( hr.Li("This is the second item", style="color: red") )
# item = hr.Li()
# item.append("And this is a ")
# item.append( hr.A("http://google.com", "link") )
# item.append("to google")
# list.append(item)
# body.append(list)
# page.append(body)
# render_page(page, "test_html_output8.html")