libhtml.py: add title=None default option to Html.page static method

svn: r12663
This commit is contained in:
Gerald Britton 2009-06-12 16:36:31 +00:00
parent bb83288883
commit 44028cc47c

View File

@ -42,8 +42,8 @@ __all__ = ['Html']
#------------------------------------------------------------------------
try:
from gen.plug import PluginManager, Plugin
from gettext import gettext as _
from gen.plug import PluginManager, Plugin
except ImportError:
print 'Plugin manager not imported.'
@ -183,12 +183,12 @@ class Html(list):
)
#
@staticmethod
def head(title=_('Title'), encoding='utf-8', *args, **keywargs):
def head(title=None, encoding='utf-8', *args, **keywargs):
"""
Build and return a properly-formated <head> object
@type title: string or None
@param title: title for HTML page. Default='Title'. If None no
@param title: title for HTML page. Default=None. If None no
title tag is written
@type encoding: string
@param encoding: encoding to be used. Default = 'utf-8'
@ -198,21 +198,19 @@ class Html(list):
meta1 = 'http-equiv="content-type" content="text/html;charset=%s"'
meta2 = 'http-equiv="Content-Style-Type" content="text/css"'
head = Html('head', *args, **keywargs)
if title != None:
if title is not None:
head += (Html('title', title, inline=True, indent=True))
head += (
Html('meta', attr=meta1 % encoding, indent=True),
Html('meta', attr=meta2, indent=True)
)
head += Html('meta', attr=meta1 % encoding, indent=True)
head += Html('meta', attr=meta2, indent=True)
return head
#
@staticmethod
def page(title=_('Title'), encoding='utf-8', lang='en', *args, **keywargs):
def page(title=None, encoding='utf-8', lang='en', *args, **keywargs):
"""
This function prepares a new Html class based page and returns
@type title: string
@param title: title for HTML page. Default='Title'
@param title: title for HTML page. Default=None
@type encoding: string
@param encoding: encoding to be used. Default = 'utf-8'
@type lang: string
@ -249,7 +247,7 @@ class Html(list):
@param indent: True ==> indent this object with respect to its parent
False ==> do not indent this object
None ==> no indent for this object (use eg for pre tag)
Defaults to False
Defaults to True
@type inline: boolean
@param inline: True ==> instructs the write() method to output this
object and any child objects as a single string
@ -281,8 +279,8 @@ class Html(list):
# addition to the opening tag as attributes.
#
for keyw, arg in keywargs.iteritems():
if keyw in ['indent', 'close', 'inline'] and \
arg in [True, False, None]:
if (keyw in ['indent', 'close', 'inline'] and
arg in [True, False, None]):
exec '%s = %s' % (keyw, arg) # keep these settings
elif keyw == 'attr': # pass attributes along
attr += ' ' + arg