view piecrust/data/piecrustdata.py @ 979:45ad976712ec

tests: Big push to get the tests to pass again. - Lots of fixes everywhere in the code. - Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now. - Replace all `.md` test files with `.html` since now a auto-format extension always sets the format. - Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 29 Oct 2017 22:51:57 -0700
parents f71d576835ee
children
line wrap: on
line source

import logging
from piecrust import APP_VERSION
from piecrust.data.debug import build_debug_info


logger = logging.getLogger(__name__)


class PieCrustData(object):
    debug_render = ['version', 'url', 'branding', 'debug_info']
    debug_render_invoke = ['version', 'url', 'branding', 'debug_info']
    debug_render_redirect = {'debug_info': '_debugRenderDebugInfo'}

    def __init__(self):
        self.version = APP_VERSION
        self.url = 'http://bolt80.com/piecrust/'
        self.branding = 'Baked with <em><a href="%s">PieCrust</a> %s</em>.' % (
            'http://bolt80.com/piecrust/', APP_VERSION)
        self._page = None

    @property
    def debug_info(self):
        if self._page is not None:
            try:
                return build_debug_info(self._page)
            except Exception as ex:
                logger.exception(ex)
                return ('An error occured while generating debug info. '
                        'Please check the logs.')
        return ''

    def enableDebugInfo(self, page):
        self._page = page

    def _debugRenderDebugInfo(self):
        return "The very thing you're looking at!"