Skip to main content

Simple Pythonic HTML Creator

Project description

As simple as below:

>>> import sphc

>>> tf = sphc.TagFactory()

>>> html = tf.HTML()
>>> html.head = tf.HEAD()
>>> html.body = tf.BODY()
>>> html.body.content = tf.DIV("Some Text here.", Class='content')
>>> html.body.content.br = tf.BR()
>>> html.body.content.br = tf.BR()
>>> html.footer = tf.FOOTER()

>>> data = [('One', '1'), ('Two', '2'), ('Three', '3')]
>>> atable = tf.TABLE()
>>> for element in data:
>>>     row = tf.TR()
>>>     row.cells = [tf.TD(element[0]), tf.TD(element[1])]
>>>     atable.row = row

>>> more_cells = [tf.TD('Four'), tf.TD('4')]
>>> row = tf.TR()
>>> row.cells = more_cells

>>> atable.row = row

>>> html.body.content.atable = atable
>>> html.body.content.attributes['id'] = 'content_id'

>>> print(html)
>>> print(html.pretty())

Remember

pretty method should only be used for debugging. Real output is generated by str( <tag-object> )

Properties with no value required

>>> c = tf.INPUT('checked', type='checkbox', value='foo')
>>> print(c)
<INPUT checked type="checkbox", value="foo"/>

More

sphc.more module privides base HTML5 page classes (based on html5boilerplate.com templates) This is work in progress.:

>>> import sphc.more
>>> tf = sphc.TagFactory()
>>> class MyPage(sphc.more.HTML5Page):
        def footer(self):
            return tf.FOOTER("Footer text")
>>> my_page = MyPage()
>>> my_page.render()

Similar packages

TODO

  • To add more tests

  • A document class ?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphc-0.5.7.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file sphc-0.5.7.tar.gz.

File metadata

  • Download URL: sphc-0.5.7.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sphc-0.5.7.tar.gz
Algorithm Hash digest
SHA256 1aaa7c3ab817f56c6cfda7d2e22ce3c3d6c911f6ed3cdfa10ed74cee9bd53a56
MD5 4285418429227f9181cb5be1f8aa40d0
BLAKE2b-256 402c779384d9316aeaad62512333c61a84c9234fef264e90c9606534a1545f76

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page