diff --git a/Scripts/CentOS-Web/Apps/xhtml.py b/Scripts/CentOS-Web/Apps/xhtml.py index c313f41..721c7d8 100755 --- a/Scripts/CentOS-Web/Apps/xhtml.py +++ b/Scripts/CentOS-Web/Apps/xhtml.py @@ -1,9 +1,9 @@ #!/usr/bin/python # -# Xhtml.output -- This module encapsulates XHTML output code needed by +# Apps.xhtml -- This module encapsulates XHTML output code needed by # web applications. # -# Copyright (C) 2009, 2010, 2011 The CentOS Project +# Copyright (C) 2011 The CentOS Project # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,122 +26,130 @@ import os import cgi import cgitb; cgitb.enable() -from datetime import date - -qs = cgi.parse_qs(os.environ['QUERY_STRING']) - -now = date.today() - -def tag(name, attrs, indent=[8,1], content="", has_child=0): - """Returns XHTML tag definition. - - Arguments: - - name: The XHTML tag's name. Notice that this function doesn't - verify nor validate the XHTML tags you provide. It is up to - you write them correctly considering the XHTML standard - definition. - - attrs: The XHTML tag's attribute. Notice that this function - doesn't verify the attributes assignation to tags. You need to - know what attributes are considered valid to the tag you are - creating in order to build a well-formed XHTML document. Such - verification can be achived inside firefox browser through the - `firebug' plugin. - - indent: The XHTML tag's indentation (Optional). This argument is a - list of two numerical values. The first value in the list - represents the amount of horizontal spaces between the - beginning of line and the opening tag. The second value in - the list represents the amount of vertical spaces (new lines) - between tags. - - content: The XHTML tag's content (Optional). This argument - provides the information the tag encloses. When this argument - is empty, tag is rendered without content. - - has_child: The XHTML tag has a child? (Optional). This argument is - specifies whether a tag has another tag inside (1) or not (0). - When a tag has not a child tag, indentation is applied between - the tag content and the closing tag provoking an unecessary - spaces to be shown. Such kind of problems are prevented by - setting this option to `0'. On the other hand, when a tag has - a child tag inside, using the value `1' will keep the closing - tag indentation aligned with the opening one. - - This function encapsulates the construction of XHTML tags. Use - this function wherever you need to create XHTML tags. It helps to - standardize tag constructions and their final output and, this - way, produce consistent XHTML documents. - - """ - if indent[0] > 0: - h_indent = ' '*indent[0] - else: - h_indent = '' - - if indent[1] > 0: - v_indent = "\n"*indent[1] - else: - v_indent = '' + +class Page: + + + def __init__(self): + """Initialize page data.""" + self.qs = cgi.parse_qs(os.environ['QUERY_STRING']) + self.name = 'Home' + self.title = 'The CentOS Project' + self.description = 'Community Enterprise Operating System' + self.keywords = 'centos, project, community, enterprise, operating system' + self.copyright = '2009-2011 The CentOS Project. All rights reserved.' + self.language = 'en' + + + def tag(self, name, attrs, indent=[8,1], content="", has_child=0): + """Returns XHTML tag definition. + + Arguments: + + name: The XHTML tag's name. Notice that this function doesn't + verify nor validate the XHTML tags you provide. It is up + to you write them correctly considering the XHTML standard + definition. + + attrs: The XHTML tag's attribute. Notice that this function + doesn't verify the attributes assignation to tags. You + need to know what attributes are considered valid to the + tag you are creating in order to build a well-formed XHTML + document. Such verification can be achived inside firefox + browser through the `firebug' plugin. + + indent: The XHTML tag's indentation (Optional). This argument + is a list of two numerical values. The first value in the + list represents the amount of horizontal spaces between + the beginning of line and the opening tag. The second + value in the list represents the amount of vertical spaces + (new lines) between tags. + + content: The XHTML tag's content (Optional). This argument + provides the information the tag encloses. When this + argument is empty, tag is rendered without content. + + has_child: The XHTML tag has a child? (Optional). This + argument is specifies whether a tag has another tag inside + (1) or not (0). When a tag has not a child tag, + indentation is applied between the tag content and the + closing tag provoking an unecessary spaces to be shown. + Such kind of problems are prevented by setting this option + to `0'. On the other hand, when a tag has a child tag + inside, using the value `1' will keep the closing tag + indentation aligned with the opening one. + + This function encapsulates the construction of XHTML tags. + Use this function wherever you need to create XHTML tags. It + helps to standardize tag constructions and their final output + and, this way, produce consistent XHTML documents. + """ + if indent[0] > 0: + h_indent = ' '*indent[0] + else: + h_indent = '' + + if indent[1] > 0: + v_indent = "\n"*indent[1] + else: + v_indent = '' - output = v_indent + h_indent + '<' + str(name) - if len(attrs) > 0: - attr_names = attrs.keys() - attr_names.sort() - for attr_name in attr_names: - output += ' ' + str(attr_name) + '="' + str(attrs[attr_name]) + '"' - if content == '': - output += ' />' - else: - output += '>' - output += str(content) - if has_child == 1: - output += h_indent + '' + output = v_indent + h_indent + '<' + str(name) + if len(attrs) > 0: + attr_names = attrs.keys() + attr_names.sort() + for attr_name in attr_names: + output += ' ' + str(attr_name) + '="' + str(attrs[attr_name]) + '"' + if content == '': + output += ' />' else: - output += '' - output += v_indent + output += '>' + output += str(content) + if has_child == 1: + output += h_indent + '' + else: + output += '' + output += v_indent - return output + return output -def page_preamble(): - """Return XHTML code of page preamble. + def page_preamble(self): + """Return XHTML code of page preamble. - The page preamble sets the document type definition required by - the XHTML standard. + The page preamble sets the document type definition required + by the XHTML standard. - """ - output = '' + "\n" - output += '' + "\n" + """ + output = '' + "\n" + output += '' + "\n" - return output + return output -def page_logo(): - """Returns XHTML code of page logo. + def page_logo(self): + """Returns XHTML code of page logo. - The page logo is displayed on the top-left corner of the page. We - use this area to show The CentOS Logo, the main visual - representation of The CentOS Project. In order to print the page - logo correctly, the image related must be 78 pixels of height. + The page logo is displayed on the top-left corner of the page. + We use this area to show The CentOS Logo, the main visual + representation of The CentOS Project. In order to print the + page logo correctly, the image related must be 78 pixels of + height. - """ - attrs = [] - attrs.append({'id': 'logo'}) - attrs.append({'title': 'Community Enterprise Operating System', 'href': '/centos-web/'}) - attrs.append({'src': '/centos-web-pub/Images/centos-logo.png', 'alt': 'CentOS'}) + """ + attrs = [] + attrs.append({'id': 'logo'}) + attrs.append({'title': 'Community Enterprise Operating System', 'href': '/centos-web/'}) + attrs.append({'src': '/centos-web-pub/Images/centos-logo.png', 'alt': 'CentOS'}) - return tag('div', attrs[0], [8,1], tag('a', attrs[1], [12,1], tag('img', attrs[2], [0,0], '', 0), 0), 1) + return self.tag('div', attrs[0], [8,1], self.tag('a', attrs[1], [12,1], self.tag('img', attrs[2], [0,0], '', 0), 0), 1) -def page_ads_google(): - """Returns XHTML code of Google advertisement (468x60 pixels). - - """ - output = """ + def page_ads_google(self): + """Returns XHTML code of Google advertisement (468x60 pixels).""" + output = """
Google Advertisement