Renders a file to text using the mako template system.
    
    To learn more about mako and its usage, see [[www.makotemplates.org]]
    
    :return     <str> formatted text

def renderfile(filename,
               options=None,
               templatePaths=None,
               default='',
               silent=False):
    """
    Renders a file to text using the mako template system.
    
    To learn more about mako and its usage, see [[www.makotemplates.org]]
    
    :return     <str> formatted text
    """
    if not mako:
        logger.debug('mako is not installed')
        return default

    if not mako:
        logger.debug('mako is not installed.')
        return default

    if templatePaths is None:
        templatePaths = []

    # use the default mako templates
    basepath = os.environ.get('MAKO_TEMPLATEPATH', '')
    if basepath:
        basetempls = basepath.split(os.path.pathsep)
    else:
        basetempls = []

    templatePaths += basetempls

    # include the root path
    templatePaths.insert(0, os.path.dirname(filename))
    templatePaths = map(lambda x: x.replace('\\', '/'), templatePaths)

    # update the default options
    scope = dict(os.environ)

    scope['projex_text'] = projex.text
    scope['date'] = date
    scope['datetime'] = datetime
    scope.update(_macros)
    scope.update(os.environ)

    if options is not None:
        scope.update(options)

    old_env_path = os.environ.get('MAKO_TEMPLATEPATH', '')
    os.environ['MAKO_TEMPLATEPATH'] = os.path.pathsep.join(templatePaths)

    logger.debug('rendering mako file: %s', filename)
    if templatePaths:
        lookup = mako.lookup.TemplateLookup(directories=templatePaths)
        templ = mako.template.Template(filename=filename, lookup=lookup)
    else:
        templ = mako.template.Template(filename=filename)

    try:
        output = templ.render(**scope)
    except StandardError:
        output = default
        if not silent:
            logger.exception('Error rendering mako text')

    os.environ['MAKO_TEMPLATEPATH'] = old_env_path

    return output