--- a/lib/page.py Sat Feb 07 03:35:37 2009 +0200
+++ b/lib/page.py Sat Feb 07 04:37:28 2009 +0200
@@ -5,6 +5,7 @@
# for filesystem ops
import os, os.path
+import time
# for ResponseError
import http
@@ -30,7 +31,7 @@
This object represents the information about our attempt to render some specific page
"""
- def __init__ (self, url, path, basename, url_tail) :
+ def __init__ (self, url, path, basename, url_tail, charset='utf8') :
"""
Initialize the page at the given location
@@ -38,6 +39,7 @@
@param path the filesystem path to this page's file
@param basename the filesystem name of this page's file, without the file extension
@param url_trail trailing URL for this page
+ @param charset file charset
"""
# store
@@ -45,6 +47,7 @@
self.path = path
self.basename = basename
self.url_tail = url_tail
+ self.charset = charset
# unbound
self.request = None
@@ -93,6 +96,17 @@
"""
abstract
+
+ @property
+ def modified (self) :
+ """
+ Returns the page modification timestamp
+ """
+
+ # stat
+ timestamp = os.stat(self.path).st_mtime
+
+ return time.strftime("%Y/%m/%d %H:%M %Z", time.gmtime(timestamp))
class HTMLPage (Page) :
"""
@@ -105,7 +119,7 @@
Opens the .html file, reads and returns contents
"""
- return open(self.path, 'rb').read()
+ return open(self.path, 'rb').read().decode(self.charset)
class TemplatePage (Page) :
"""
--- a/lib/template.py Sat Feb 07 03:35:37 2009 +0200
+++ b/lib/template.py Sat Feb 07 04:37:28 2009 +0200
@@ -55,11 +55,11 @@
def render_template (tpl, **params) :
"""
- Render the given template, returning the output, or raising a TemplateError
+ Render the given template, returning the output as a unicode string, or raising a TemplateError
"""
try :
- return tpl.render(**params)
+ return tpl.render_unicode(**params)
# a template may render other templates
except TemplateError :
--- a/lib/tree_parse.py Sat Feb 07 03:35:37 2009 +0200
+++ b/lib/tree_parse.py Sat Feb 07 04:37:28 2009 +0200
@@ -12,7 +12,7 @@
pass
-def _read_lines (path, stop_tokens='') :
+def _read_lines (path, stop_tokens, charset) :
"""
Reads lines from the given path, ignoring empty lines, and yielding (line_number, indent, line) tuples, where
line_number is the line number, indent counts the amount of leading whitespace, and line is the actual line
@@ -23,6 +23,9 @@
"""
for line_number, line in enumerate(open(path, 'rb')) :
+ # decode to unicode
+ line = line.decode(charset)
+
indent = 0
# count indent
@@ -52,7 +55,7 @@
# yield
yield line_number + 1, indent, line
-def parse (path, stop_tokens='') :
+def parse (path, stop_tokens='', charset='utf8') :
"""
Reads and parses the file at the given path, returning a list of (line_number, line, children) tuples.
"""
@@ -67,7 +70,7 @@
prev = None
# read lines
- for line_number, indent, line in _read_lines(path, stop_tokens) :
+ for line_number, indent, line in _read_lines(path, stop_tokens, charset) :
# create item
item = (line_number, line, [])
Binary file static/link.png has changed
--- a/static/style.css Sat Feb 07 03:35:37 2009 +0200
+++ b/static/style.css Sat Feb 07 04:37:28 2009 +0200
@@ -21,16 +21,6 @@
color: #000000;
}
-a {
- color: black;
- text-decoration: none;
- font-weight: bold;
-}
-
-a:hover {
- text-decoration: underline;
-}
-
/*
* Top header
*/
@@ -112,6 +102,9 @@
}
+/*
+ * Footer
+ */
div#footer {
padding: 10px;
@@ -120,3 +113,39 @@
font-size: x-small;
font-style: italic;
}
+
+div#footer-right {
+ float: right;
+}
+
+/*
+ * General styles
+ */
+a {
+ color: black;
+ text-decoration: none;
+ font-weight: bold;
+}
+
+a:hover {
+ text-decoration: underline;
+}
+
+h1 {
+ font-size: x-large;
+}
+
+h2 {
+ font-size: large;
+}
+
+#content li {
+ padding: 2px;
+}
+
+#content a {
+ padding-right: 13px;
+
+ background: transparent url(/static/link.png) no-repeat center right;
+}
+
--- a/templates/layout.tmpl Sat Feb 07 03:35:37 2009 +0200
+++ b/templates/layout.tmpl Sat Feb 07 04:37:28 2009 +0200
@@ -35,6 +35,10 @@
</div>
<div id="footer">
+ <div id="footer-right">
+ Modified ${page.modified}
+ </div>
+
© 2009 Tero Marttila
</div>
</body>