Skip to content

Commit ea32f41

Browse files
committed
a litle bit of clean up of the html_render solution
1 parent 497c58d commit ea32f41

4 files changed

Lines changed: 72 additions & 26 deletions

File tree

Examples/Session06/html_render/run_html_render.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
Uncomment the steps as you add to your rendering.
77
88
"""
9+
910
from cStringIO import StringIO
1011

1112

1213
# importing the html_rendering code with a short name for easy typing.
1314
import html_render as hr
14-
reload(hr) #reloding in case you are ruuing this in iPython
15-
# -- want to make sure the latest version is used
15+
reload(hr) # reloading in case you are running this in iPython
16+
# -- we want to make sure the latest version is used
1617

1718

1819
## writing the file out:
19-
def render(page, filename):
20+
def render_page(page, filename):
2021
"""
2122
render the tree of elements
2223
@@ -27,11 +28,11 @@ def render(page, filename):
2728
f = StringIO()
2829
page.render(f, " ")
2930

30-
f.seek(0)
31+
f.reset()
3132

3233
print f.read()
3334

34-
f.seek(0)
35+
f.reset()
3536
open(filename, 'w').write( f.read() )
3637

3738

@@ -44,7 +45,7 @@ def render(page, filename):
4445

4546
page.append("And here is another piece of text -- you should be able to add any number")
4647

47-
render(page, "test_html_output1.html")
48+
render_page(page, "test_html_output1.html")
4849

4950
# ## Step 2
5051
# ##########
@@ -59,7 +60,7 @@ def render(page, filename):
5960

6061
# page.append(body)
6162

62-
# render(page, "test_html_output2.html")
63+
# render_page(page, "test_html_output2.html")
6364

6465
# # Step 3
6566
# ##########
@@ -78,7 +79,7 @@ def render(page, filename):
7879

7980
# page.append(body)
8081

81-
# render(page, "test_html_output3.html")
82+
# render_page(page, "test_html_output3.html")
8283

8384
# # Step 4
8485
# ##########
@@ -97,7 +98,7 @@ def render(page, filename):
9798

9899
# page.append(body)
99100

100-
# render(page, "test_html_output4.html")
101+
# render_page(page, "test_html_output4.html")
101102

102103
# # Step 5
103104
# #########
@@ -118,7 +119,7 @@ def render(page, filename):
118119

119120
# page.append(body)
120121

121-
# render(page, "test_html_output5.html")
122+
# render_page(page, "test_html_output5.html")
122123

123124
# # Step 6
124125
# #########
@@ -143,7 +144,7 @@ def render(page, filename):
143144

144145
# page.append(body)
145146

146-
# render(page, "test_html_output6.html")
147+
# render_page(page, "test_html_output6.html")
147148

148149
# # Step 7
149150
# #########
@@ -180,7 +181,7 @@ def render(page, filename):
180181

181182
# page.append(body)
182183

183-
# render(page, "test_html_output7.html")
184+
# render_page(page, "test_html_output7.html")
184185

185186
# # Step 8
186187
# ########
@@ -199,7 +200,7 @@ def render(page, filename):
199200
# body.append( hr.H(2, "PythonClass - Class 6 example") )
200201

201202
# 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",
202-
# style="text-align: center; font-style: oblique;"))
203+
# style="text-align: center; font-style: oblique;"))
203204

204205
# body.append(hr.Hr())
205206

@@ -219,7 +220,7 @@ def render(page, filename):
219220

220221
# page.append(body)
221222

222-
# render(page, "test_html_output8.html")
223+
# render_page(page, "test_html_output8.html")
223224

224225

225226

Solutions/Session06/html_render.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Html(Element):
8989
tag = 'html'
9090
def render(self, file_out, current_ind=""):
9191
file_out.write("<!DOCTYPE html>\n")
92-
Element.render(self, file_out, current_ind=self.indent)
92+
Element.render(self, file_out, current_ind=current_ind)
9393

9494

9595
class Body(Element):

Solutions/Session06/test_html_render.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,20 @@ def test_render_content_indent():
8181
assert lines[1].startswith(" ")
8282

8383

84-
def test_render_html():
85-
""" the html element """
84+
## this one no longer currect with step 8 added
85+
# def test_render_html():
86+
# """ the html element """
8687

87-
e = hr.Html("this is some content")
88-
e.append("and this is some more")
88+
# e = hr.Html("this is some content")
89+
# e.append("and this is some more")
8990

90-
output = render_element(e)
91+
# output = render_element(e)
9192

92-
print output
93-
assert output.startswith('<html>')
94-
assert output.endswith('</html>\n')
95-
assert "this is some content" in output
96-
assert "and this is some more" in output
93+
# print output
94+
# assert output.startswith('<html>')
95+
# assert output.endswith('</html>\n')
96+
# assert "this is some content" in output
97+
# assert "and this is some more" in output
9798

9899

99100
def test_render_body():
@@ -196,7 +197,7 @@ def test_anchor():
196197
output = render_element(e, ind=" ")
197198

198199
print output
199-
assert output == ' <a href="proxy.php?url=http%3A%2F%2Fgoogle.com">link to google</a>\n'
200+
assert output == ' <a href="proxy.php?url=http%3A%2F%2Fgoogle.com">link to google</a>\n'
200201

201202

202203
def test_header():
@@ -207,10 +208,27 @@ def test_header():
207208
print output
208209
assert output == ' <h2>The text of the header</h2>\n'
209210

211+
210212
def test_header3():
211213
e = hr.H(3, "The text of the header")
212214

213215
output = render_element(e, ind=" ")
214216

215217
print output
216218
assert output == ' <h3>The text of the header</h3>\n'
219+
220+
221+
def test_doctype():
222+
"""
223+
html element should render teh doctype header, too
224+
"""
225+
226+
e = hr.Html("Just a tiny bit of content")
227+
228+
output = render_element( e )
229+
230+
print output
231+
assert output.startswith("<!DOCTYPE html>")
232+
assert "<html>" in output
233+
assert output.endswith("</html>\n")
234+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
.. Foundations 2: Python slides file, created by
3+
hieroglyph-quickstart on Wed Apr 2 18:42:06 2014.
4+
5+
6+
******************************************************************
7+
Session Nine: Decorators, Context Managers, Packages and packaging
8+
******************************************************************
9+
10+
======================
11+
Lightning Talks Today:
12+
======================
13+
14+
.. rst-class:: medium
15+
16+
person 1
17+
18+
person 2
19+
20+
person 3
21+
22+
person 4
23+
24+
================
25+
Review/Questions
26+
================
27+

0 commit comments

Comments
 (0)