|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +a simple script can run and test your html rendering classes. |
| 5 | +
|
| 6 | +Uncomment the steps as you add to your rendering. |
| 7 | +
|
| 8 | +""" |
| 9 | + |
| 10 | +from cStringIO import StringIO |
| 11 | + |
| 12 | + |
| 13 | +# importing the html_rendering code with a short name for easy typing. |
| 14 | +import html_render as hr |
| 15 | +reload(hr) # reloading in case you are running this in iPython |
| 16 | + # -- we want to make sure the latest version is used |
| 17 | + |
| 18 | + |
| 19 | +## writing the file out: |
| 20 | +def render_page(page, filename): |
| 21 | + """ |
| 22 | + render the tree of elements |
| 23 | +
|
| 24 | + This uses cSstringIO to render to memory, then dump to console and |
| 25 | + write to file -- very handy! |
| 26 | + """ |
| 27 | + |
| 28 | + f = StringIO() |
| 29 | + page.render(f, " ") |
| 30 | + |
| 31 | + f.reset() |
| 32 | + |
| 33 | + print f.read() |
| 34 | + |
| 35 | + f.reset() |
| 36 | + open(filename, 'w').write( f.read() ) |
| 37 | + |
| 38 | + |
| 39 | +## Step 1 |
| 40 | +########## |
| 41 | + |
| 42 | +# page = hr.Element() |
| 43 | + |
| 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") |
| 45 | + |
| 46 | +# page.append("And here is another piece of text -- you should be able to add any number") |
| 47 | + |
| 48 | +# render_page(page, "test_html_output1.html") |
| 49 | + |
| 50 | +# ## Step 2 |
| 51 | +# ########## |
| 52 | + |
| 53 | +# page = hr.Html() |
| 54 | + |
| 55 | +# body = hr.Body() |
| 56 | + |
| 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")) |
| 58 | + |
| 59 | +# body.append(hr.P("And here is another piece of text -- you should be able to add any number")) |
| 60 | + |
| 61 | +# page.append(body) |
| 62 | + |
| 63 | +# render_page(page, "test_html_output2.html") |
| 64 | + |
| 65 | +# # Step 3 |
| 66 | +# ########## |
| 67 | + |
| 68 | +# page = hr.Html() |
| 69 | + |
| 70 | +# head = hr.Head() |
| 71 | +# head.append(hr.Title("PythonClass = Revision 1087:")) |
| 72 | + |
| 73 | +# page.append(head) |
| 74 | + |
| 75 | +# body = hr.Body() |
| 76 | + |
| 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")) |
| 79 | + |
| 80 | +# page.append(body) |
| 81 | + |
| 82 | +# render_page(page, "test_html_output3.html") |
| 83 | + |
| 84 | +# # Step 4 |
| 85 | +# ########## |
| 86 | + |
| 87 | +# page = hr.Html() |
| 88 | + |
| 89 | +# head = hr.Head() |
| 90 | +# head.append(hr.Title("PythonClass = Revision 1087:")) |
| 91 | + |
| 92 | +# page.append(head) |
| 93 | + |
| 94 | +# body = hr.Body() |
| 95 | + |
| 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;")) |
| 98 | + |
| 99 | +# page.append(body) |
| 100 | + |
| 101 | +# render_page(page, "test_html_output4.html") |
| 102 | + |
| 103 | +# # Step 5 |
| 104 | +# ######### |
| 105 | + |
| 106 | +# page = hr.Html() |
| 107 | + |
| 108 | +# head = hr.Head() |
| 109 | +# head.append(hr.Title("PythonClass = Revision 1087:")) |
| 110 | + |
| 111 | +# page.append(head) |
| 112 | + |
| 113 | +# body = hr.Body() |
| 114 | + |
| 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;")) |
| 117 | + |
| 118 | +# body.append(hr.Hr()) |
| 119 | + |
| 120 | +# page.append(body) |
| 121 | + |
| 122 | +# render_page(page, "test_html_output5.html") |
| 123 | + |
| 124 | +# # Step 6 |
| 125 | +# ######### |
| 126 | + |
| 127 | +# page = hr.Html() |
| 128 | + |
| 129 | +# head = hr.Head() |
| 130 | +# head.append(hr.Title("PythonClass = Revision 1087:")) |
| 131 | + |
| 132 | +# page.append(head) |
| 133 | + |
| 134 | +# body = hr.Body() |
| 135 | + |
| 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;")) |
| 138 | + |
| 139 | +# body.append(hr.Hr()) |
| 140 | + |
| 141 | +# body.append("And this is a ") |
| 142 | +# body.append( hr.A("http://google.com", "link") ) |
| 143 | +# body.append("to google") |
| 144 | + |
| 145 | +# page.append(body) |
| 146 | + |
| 147 | +# render_page(page, "test_html_output6.html") |
| 148 | + |
| 149 | +# # Step 7 |
| 150 | +# ######### |
| 151 | + |
| 152 | +# page = hr.Html() |
| 153 | + |
| 154 | +# head = hr.Head() |
| 155 | +# head.append(hr.Title("PythonClass = Revision 1087:")) |
| 156 | + |
| 157 | +# page.append(head) |
| 158 | + |
| 159 | +# body = hr.Body() |
| 160 | + |
| 161 | +# body.append( hr.H(2, "PythonClass - Class 6 example") ) |
| 162 | + |
| 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;")) |
| 165 | + |
| 166 | +# body.append(hr.Hr()) |
| 167 | + |
| 168 | +# list = hr.Ul(id="TheList", style="line-height:200%") |
| 169 | + |
| 170 | +# list.append( hr.Li("The first item in a list") ) |
| 171 | +# list.append( hr.Li("This is the second item", style="color: red") ) |
| 172 | + |
| 173 | +# item = hr.Li() |
| 174 | +# item.append("And this is a ") |
| 175 | +# item.append( hr.A("http://google.com", "link") ) |
| 176 | +# item.append("to google") |
| 177 | + |
| 178 | +# list.append(item) |
| 179 | + |
| 180 | +# body.append(list) |
| 181 | + |
| 182 | +# page.append(body) |
| 183 | + |
| 184 | +# render_page(page, "test_html_output7.html") |
| 185 | + |
| 186 | +# # Step 8 |
| 187 | +# ######## |
| 188 | + |
| 189 | +page = hr.Html() |
| 190 | + |
| 191 | + |
| 192 | +head = hr.Head() |
| 193 | +head.append( hr.Meta(charset="UTF-8") ) |
| 194 | +head.append(hr.Title("PythonClass = Revision 1087:")) |
| 195 | + |
| 196 | +page.append(head) |
| 197 | + |
| 198 | +body = hr.Body() |
| 199 | + |
| 200 | +body.append( hr.H(2, "PythonClass - Class 6 example") ) |
| 201 | + |
| 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;")) |
| 204 | + |
| 205 | +body.append(hr.Hr()) |
| 206 | + |
| 207 | +list = hr.Ul(id="TheList", style="line-height:200%") |
| 208 | + |
| 209 | +list.append( hr.Li("The first item in a list") ) |
| 210 | +list.append( hr.Li("This is the second item", style="color: red") ) |
| 211 | + |
| 212 | +item = hr.Li() |
| 213 | +item.append("And this is a ") |
| 214 | +item.append( hr.A("http://google.com", "link") ) |
| 215 | +item.append("to google") |
| 216 | + |
| 217 | +list.append(item) |
| 218 | + |
| 219 | +body.append(list) |
| 220 | + |
| 221 | +page.append(body) |
| 222 | + |
| 223 | +render_page(page, "test_html_output8.html") |
| 224 | + |
| 225 | + |
| 226 | + |
| 227 | + |
0 commit comments