--- a/helpers.py Mon Feb 09 03:05:19 2009 +0200
+++ b/helpers.py Mon Feb 09 04:38:23 2009 +0200
@@ -6,44 +6,56 @@
from qmsk.web import config
-def now () :
- """
- Returns the current date/time
+class Helpers (object) :
"""
-
- return time.strftime(config.DATETIME_FMT)
-
-def copyright_year () :
- """
- Returns the current year
- """
-
- return time.strftime("%Y")
-
-def validation_notice (site_host) :
- """
- Returns a short "Validated XHTML & CSS" link text for the given site hostname
+ A bunch of useful helper methods for use in templates
"""
- return 'Validated <a href="http://validator.w3.org/check?uri=http://%(host)s">XHTML 1.0 Strict</a> & <a href="http://jigsaw.w3.org/css-validator/validator?uri=http://%(host)s">CSS 2.1</a>' % dict(
- host = site_host
- )
-
-def breadcrumb (trail, links=True) :
- """
- Returns a nicely formatted breadcrumb tail, optinally with links
- """
+ def _bind_ctx (self, ctx) :
+ """
+ Initialize with the given render context
+ """
- return ' » '.join(
- (
- '<a href="$site_url/%s">%s</a>' % (page.url, page.title) if links else page.title
- ) for page in trail
- )
+ self.ctx = ctx
-def escape (data) :
- """
- Escape data as HTML
- """
+ def now (self) :
+ """
+ Returns the current date/time
+ """
- return cgi.escape(data)
+ return time.strftime(config.DATETIME_FMT)
+ def copyright_year (self) :
+ """
+ Returns the current year
+ """
+
+ return time.strftime("%Y")
+
+ def validation_notice (self, site_host) :
+ """
+ Returns a short "Validated XHTML & CSS" link text for the given site hostname
+ """
+
+ return 'Validated <a href="http://validator.w3.org/check?uri=http://%(host)s">XHTML 1.0 Strict</a> & <a href="http://jigsaw.w3.org/css-validator/validator?uri=http://%(host)s">CSS 2.1</a>' % dict(
+ host = site_host
+ )
+
+ def breadcrumb (self, trail, links=True) :
+ """
+ Returns a nicely formatted breadcrumb tail, optinally with links
+ """
+
+ return ' » '.join(
+ (
+ '<a href="$site_url/%s">%s</a>' % (page.url, page.title) if links else page.title
+ ) for page in trail
+ )
+
+ def escape (self, data) :
+ """
+ Escape data as HTML
+ """
+
+ return cgi.escape(data)
+