~sirn/fanboi2

ref: a68873a108d20a6a49a1b6caf374bfb2cf6a94fe fanboi2/fanboi2/helpers/partials.py -rw-r--r-- 1.7 KiB
a68873a1Kridsada Thanabulpong Coding style cleanups and setup pre-commit hooks (#42) 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from markupsafe import Markup

from ..interfaces import IPageQueryService
from .formatters import format_markdown


def get_partial(request, slug):
    """Returns a content of internal page.

    :param request: A :class:`pyramid.request.Request` object.
    :param slug: An internal page slug.
    """
    page_query_svc = request.find_service(IPageQueryService)
    try:
        return page_query_svc.internal_body_from_slug(slug)
    except ValueError:
        return None


def global_css(context, request):
    """Returns a string of inline global custom CSS for site-wide CSS override.
    This custom CSS is the content of ``internal:global/css`` page.

    :param context: A :class:`mako.runtime.Context` object.
    :param request: A :class:`pyramid.request.Request` object.
    """
    page = get_partial(request, "global/css")
    if page:
        return Markup(page)


def global_appendix(context, request):
    """Returns a HTML of global appendix content. This appendix content is the
    content of ``internal:global/appendix`` page.

    :param context: A :class:`mako.runtime.Context` object.
    :param request: A :class:`pyramid.request.Request` object.
    """
    page = get_partial(request, "global/appendix")
    if page:
        return format_markdown(context, request, page)


def global_footer(context, request):
    """Returns a HTML of global footer content. This footer content is the
    content of ``internal:global/footer`` page.

    :param context: A :class:`mako.runtime.Context` object.
    :param request: A :class:`pyramid.request.Request` object.
    :param cache_region: Optional cache region to cache this partial.
    """
    page = get_partial(request, "global/footer")
    if page:
        return Markup(page)