Changes

Jump to: navigation, search

Libhtml

1,928 bytes added, 14:38, 3 April 2009
Writing your output as and where you wish
from libhtml import _XMLMS
 
=== Recommended approach ===
 
The Html class is versatile and there are many ways to use it to produce an HTML page. You can make your life easier, however, if you organize your work as described in this section.
 
== Use Html.page to begin a new page ==
 
The Html.page function takes care of the HTML boilerplate that is needed for every valid HTML page. Start off like this:
 
page, head, body = Html.page(title="My title')
 
You will then have three Html objects to use for the rest of your work. (Insert your own title text as desired.)
 
== Add additional tags to the header ==
 
Many pages require additional tags to be added to the <head> ... </head> section. These can easily be added like this:
 
head += Html('meta', name="author", content="Bill Shakespeare")
head += Html('link', media="screen" href="../my.css" type="text/css" rel="stylesheet"
 
== Build up the page body by divisions ==
 
Try to design the body of your document as a logical arrangement of divisions that refer to CSS styles. Instantiate each division separately:
 
div1 = Html('div', id="first_division", class_='div1class')
div2 = Html('div', id="second_division", class_='div2class')
 
When you have designed your divisions, add them to the page body:
 
body += div1
body += div2
 
Or, if you have man divisions, you can add them all at once like this:
 
body += [div1, div2]
 
'''Note:''' by adding them as a list, the divisions are siblings within the body.
 
== Add content to your divisions ==
 
If you are adding content that is more or less fixed, just add it directly:
 
div1 += Html('p','division 1 content')
div2 += Html('p','division 2 content')
 
If you are adding content that you will need to build up, first instantiate a new object and add it to your division:
 
table1 = Html('table')
div1 += table
 
== Write out your completed page ==
 
When all content has been added to your page, write it out:
 
page.write(myoutputmethod())
== Static Methods ==
70
edits

Navigation menu