# Path: canary/utils.py
# def get_title_from_path (path):
#     """
#     Take a path, probably for a MyStaticFile, in the form of
#     'sample_path_name', and return "Sample Path Name", suitable
#     for passing to header as the page title.
#     
#     Remove the leading "about/" as needed.
#     """
#     underscore_to_space = re.compile('_')
#     if path.startswith('about/'):
#         path = path[len('about/'):]
#     new_path = underscore_to_space.sub(' ', path)
#     from string import capwords
#     return capwords(new_path)


import os
import re
from quixote.html import htmltext, TemplateIO
from quixote.http_response import Stream
from quixote.util import StaticFile
from canary.ui.pageframe import header, footer
from canary.utils import get_title_from_path
# Various utilities to help quixote along or otherwise simplify
# quixote usage.
#
# $Id$





class MyStaticFile (StaticFile):
    """
    Enables templated rendering of static html text (also enables
    simple maintenance of static html files isolated by dir)
    """

    def orig__call__(self, request):
        contents = htmltext('')
        if self.mime_type == 'text/html':
            file_name = request.get_path()[1:]     # drop leading '/'
            contents += header(get_title_from_path(file_name))
            contents += htmltext(StaticFile.__call__(self, request))
            contents += footer()
        return contents

    def __call__(self, request):
        r = TemplateIO(html=0)
        file_name = request.get_path()[1:]     # drop leading '/'

# Path: canary/utils.py
# def get_title_from_path (path):
#     """
#     Take a path, probably for a MyStaticFile, in the form of
#     'sample_path_name', and return "Sample Path Name", suitable
#     for passing to header as the page title.
#     
#     Remove the leading "about/" as needed.
#     """
#     underscore_to_space = re.compile('_')
#     if path.startswith('about/'):
#         path = path[len('about/'):]
#     new_path = underscore_to_space.sub(' ', path)
#     from string import capwords
#     return capwords(new_path)


# Path: canary/qx_utils.py
import os
import re
from quixote.html import htmltext, TemplateIO
from quixote.http_response import Stream
from quixote.util import StaticFile
from canary.ui.pageframe import header, footer
from canary.utils import get_title_from_path

# Various utilities to help quixote along or otherwise simplify
# quixote usage.
#
# $Id$





class MyStaticFile (StaticFile):
    """
    Enables templated rendering of static html text (also enables
    simple maintenance of static html files isolated by dir)
    """

    def orig__call__(self, request):
        contents = htmltext('')
        if self.mime_type == 'text/html':
            file_name = request.get_path()[1:]     # drop leading '/'
            contents += header(get_title_from_path(file_name))
            contents += htmltext(StaticFile.__call__(self, request))
            contents += footer()
        return contents

    def __call__(self, request):
        r = TemplateIO(html=0)
        file_name = request.get_path()[1:]     # drop leading '/'

        r += header(get_title_from_path(file_name))