66Uncomment the steps as you add to your rendering.
77
88"""
9- from io import open , StringIO
9+
10+ from cStringIO import StringIO
1011
1112
1213# importing the html_rendering code with a short name for easy typing.
1314import html_render as hr
14- reload (hr )
15+ reload (hr ) # reloading in case you are running this in iPython
16+ # -- we want to make sure the latest version is used
1517
1618
1719## writing the file out:
18- def render (page , filename ):
20+ def render_page (page , filename ):
1921 """
2022 render the tree of elements
2123
@@ -24,26 +26,26 @@ def render(page, filename):
2426 """
2527
2628 f = StringIO ()
27- page .render (f , u " " )
29+ page .render (f , " " )
2830
29- f .seek ( 0 )
31+ f .reset ( )
3032
3133 print f .read ()
3234
33- f .seek ( 0 )
34- open (filename , 'w' , encoding = "utf-8" ).write ( f .read () )
35+ f .reset ( )
36+ open (filename , 'w' ).write ( f .read () )
3537
3638
3739## Step 1
3840##########
3941
4042page = hr .Element ()
4143
42- page .append (u "Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text" )
44+ 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" )
4345
44- page .append (u "And here is another piece of text -- you should be able to add any number" )
46+ page .append ("And here is another piece of text -- you should be able to add any number" )
4547
46- render (page , u "test_html_output1.html" )
48+ render_page (page , "test_html_output1.html" )
4749
4850# ## Step 2
4951# ##########
@@ -52,134 +54,134 @@ def render(page, filename):
5254
5355# body = hr.Body()
5456
55- # body.append(hr.P(u "Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text"))
57+ # 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"))
5658
57- # body.append(hr.P(u "And here is another piece of text -- you should be able to add any number"))
59+ # body.append(hr.P("And here is another piece of text -- you should be able to add any number"))
5860
5961# page.append(body)
6062
61- # render (page, u "test_html_output2.html")
63+ # render_page (page, "test_html_output2.html")
6264
6365# # Step 3
6466# ##########
6567
6668# page = hr.Html()
6769
6870# head = hr.Head()
69- # head.append(hr.Title(u "PythonClass = Revision 1087:"))
71+ # head.append(hr.Title("PythonClass = Revision 1087:"))
7072
7173# page.append(head)
7274
7375# body = hr.Body()
7476
75- # body.append(hr.P(u "Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text"))
76- # body.append(hr.P(u "And here is another piece of text -- you should be able to add any number"))
77+ # 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"))
78+ # body.append(hr.P("And here is another piece of text -- you should be able to add any number"))
7779
7880# page.append(body)
7981
80- # render (page, u "test_html_output3.html")
82+ # render_page (page, "test_html_output3.html")
8183
8284# # Step 4
8385# ##########
8486
8587# page = hr.Html()
8688
8789# head = hr.Head()
88- # head.append(hr.Title(u "PythonClass = Revision 1087:"))
90+ # head.append(hr.Title("PythonClass = Revision 1087:"))
8991
9092# page.append(head)
9193
9294# body = hr.Body()
9395
94- # body.append(hr.P(u "Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
95- # style=u "text-align: center; font-style: oblique;"))
96+ # 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",
97+ # style="text-align: center; font-style: oblique;"))
9698
9799# page.append(body)
98100
99- # render (page, u "test_html_output4.html")
101+ # render_page (page, "test_html_output4.html")
100102
101103# # Step 5
102104# #########
103105
104106# page = hr.Html()
105107
106108# head = hr.Head()
107- # head.append(hr.Title(u "PythonClass = Revision 1087:"))
109+ # head.append(hr.Title("PythonClass = Revision 1087:"))
108110
109111# page.append(head)
110112
111113# body = hr.Body()
112114
113- # body.append(hr.P(u "Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
114- # style=u "text-align: center; font-style: oblique;"))
115+ # 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",
116+ # style="text-align: center; font-style: oblique;"))
115117
116118# body.append(hr.Hr())
117119
118120# page.append(body)
119121
120- # render (page, u "test_html_output5.html")
122+ # render_page (page, "test_html_output5.html")
121123
122124# # Step 6
123125# #########
124126
125127# page = hr.Html()
126128
127129# head = hr.Head()
128- # head.append(hr.Title(u "PythonClass = Revision 1087:"))
130+ # head.append(hr.Title("PythonClass = Revision 1087:"))
129131
130132# page.append(head)
131133
132134# body = hr.Body()
133135
134- # body.append(hr.P(u "Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
135- # style=u "text-align: center; font-style: oblique;"))
136+ # 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",
137+ # style="text-align: center; font-style: oblique;"))
136138
137139# body.append(hr.Hr())
138140
139- # body.append(u "And this is a ")
140- # body.append( hr.A(u "http://google.com/", "link") )
141- # body.append(u "to google")
141+ # body.append("And this is a ")
142+ # body.append( hr.A("http://google.com/", "link") )
143+ # body.append("to google")
142144
143145# page.append(body)
144146
145- # render (page, u "test_html_output6.html")
147+ # render_page (page, "test_html_output6.html")
146148
147149# # Step 7
148150# #########
149151
150152# page = hr.Html()
151153
152154# head = hr.Head()
153- # head.append(hr.Title(u "PythonClass = Revision 1087:"))
155+ # head.append(hr.Title("PythonClass = Revision 1087:"))
154156
155157# page.append(head)
156158
157159# body = hr.Body()
158160
159- # body.append( hr.H(2, u "PythonClass - Class 6 example") )
161+ # body.append( hr.H(2, "PythonClass - Class 6 example") )
160162
161- # body.append(hr.P(u "Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
162- # style=u "text-align: center; font-style: oblique;"))
163+ # 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",
164+ # style="text-align: center; font-style: oblique;"))
163165
164166# body.append(hr.Hr())
165167
166- # list = hr.Ul(id=u "TheList", style=u "line-height:200%")
168+ # list = hr.Ul(id="TheList", style="line-height:200%")
167169
168- # list.append( hr.Li(u "The first item in a list") )
169- # list.append( hr.Li(u "This is the second item", style="color: red") )
170+ # list.append( hr.Li("The first item in a list") )
171+ # list.append( hr.Li("This is the second item", style="color: red") )
170172
171173# item = hr.Li()
172- # item.append(u "And this is a ")
173- # item.append( hr.A(u "http://google.com/", u "link") )
174- # item.append(u "to google")
174+ # item.append("And this is a ")
175+ # item.append( hr.A("http://google.com/", "link") )
176+ # item.append("to google")
175177
176178# list.append(item)
177179
178180# body.append(list)
179181
180182# page.append(body)
181183
182- # render (page, u "test_html_output7.html")
184+ # render_page (page, "test_html_output7.html")
183185
184186# # Step 8
185187# ########
@@ -188,37 +190,37 @@ def render(page, filename):
188190
189191
190192# head = hr.Head()
191- # head.append( hr.Meta(charset=u "UTF-8") )
192- # head.append(hr.Title(u "PythonClass = Revision 1087:"))
193+ # head.append( hr.Meta(charset="UTF-8") )
194+ # head.append(hr.Title("PythonClass = Revision 1087:"))
193195
194196# page.append(head)
195197
196198# body = hr.Body()
197199
198- # body.append( hr.H(2, u "PythonClass - Class 6 example") )
200+ # body.append( hr.H(2, "PythonClass - Class 6 example") )
199201
200- # body.append(hr.P(u "Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
201- # style=u "text-align: center; font-style: oblique;"))
202+ # 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",
203+ # style="text-align: center; font-style: oblique;"))
202204
203205# body.append(hr.Hr())
204206
205- # list = hr.Ul(id=u "TheList", style=u "line-height:200%")
207+ # list = hr.Ul(id="TheList", style="line-height:200%")
206208
207- # list.append( hr.Li(u "The first item in a list") )
208- # list.append( hr.Li(u "This is the second item", style="color: red") )
209+ # list.append( hr.Li("The first item in a list") )
210+ # list.append( hr.Li("This is the second item", style="color: red") )
209211
210212# item = hr.Li()
211- # item.append(u "And this is a ")
212- # item.append( hr.A(u "http://google.com/", "link") )
213- # item.append(u "to google")
213+ # item.append("And this is a ")
214+ # item.append( hr.A("http://google.com/", "link") )
215+ # item.append("to google")
214216
215217# list.append(item)
216218
217219# body.append(list)
218220
219221# page.append(body)
220222
221- # render (page, u "test_html_output8.html")
223+ # render_page (page, "test_html_output8.html")
222224
223225
224226
0 commit comments