Пример #1
0
def build_page_data(ctx):
    page = ctx.page
    sub_num = ctx.sub_num
    app = page.app

    pgn_source = ctx.pagination_source or get_default_pagination_source(page)

    pc_data = PieCrustData()
    config_data = PageData(page, ctx)
    paginator = Paginator(pgn_source,
                          page,
                          sub_num,
                          pgn_filter=ctx.pagination_filter)
    assetor = Assetor(page)
    linker = Linker(page.source, page.content_item)
    data = {
        'piecrust': pc_data,
        'page': config_data,
        'assets': assetor,
        'pagination': paginator,
        'family': linker
    }

    for route in app.routes:
        name = route.func_name
        if not name:
            continue

        func = data.get(name)
        if func is None:
            data[name] = RouteFunction(route)
        elif isinstance(func, RouteFunction):
            if not func._isCompatibleRoute(route):
                raise Exception(
                    "Route function '%s' can't target both route '%s' and "
                    "route '%s' as the 2 patterns are incompatible." %
                    (name, func._route.uri_pattern, route.uri_pattern))
        else:
            raise Exception("Route function '%s' collides with an "
                            "existing function or template data." % name)

    # TODO: handle slugified taxonomy terms.

    site_data = app.config.getAll()
    providers_data = DataProvidersData(page)

    # Put the site data first so that `MergedMapping` doesn't load stuff
    # for nothing just to find a value that was in the YAML config all
    # along.
    data = MergedMapping([site_data, data, providers_data])

    # Do this at the end because we want all the data to be ready to be
    # displayed in the debugger window.
    if (app.config.get('site/show_debug_info')
            and not app.config.get('baker/is_baking')):
        pc_data.enableDebugInfo(page)

    return data
Пример #2
0
def test_linker_children(fs_fac, page_path, expected):
    fs = fs_fac()
    fs.withConfig()
    with mock_fs_scope(fs):
        app = fs.getApp()
        app.config.set('site/pretty_urls', True)
        src = app.getSource('pages')
        item = get_simple_content_item(app, page_path)
        linker = Linker(src, item)
        actual = list(linker.children)
        assert sorted(map(lambda i: i.url, actual)) == sorted(expected)
Пример #3
0
def test_recursive_linker_iteration(fs, page_path, expected):
    with mock_fs_scope(fs):
        app = fs.getApp()
        app.config.set('site/pretty_urls', True)
        src = app.getSource('pages')
        linker = Linker(src, page_path)
        actual = list(iter(linker.allpages))

        assert len(actual) == len(expected)
        for i, (a, e) in enumerate(zip(actual, expected)):
            assert a.is_dir is False
            assert a.url == e[0]
            assert a.is_self == e[1]
Пример #4
0
def test_linker_iteration(fs, page_path, expected):
    with mock_fs_scope(fs):
        app = fs.getApp()
        app.config.set('site/pretty_urls', True)
        src = app.getSource('pages')
        linker = Linker(src, page_path)
        actual = list(iter(linker))

        assert len(actual) == len(expected)
        for (a, e) in zip(actual, expected):
            is_dir, name, is_self, url = e
            assert a.is_dir == is_dir
            assert a.name == name
            assert a.is_self == is_self
            assert a.url == url
Пример #5
0
def _load_family(data, name):
    from piecrust.data.linker import Linker
    return Linker(data._page.source, data._page.content_item)