Mercurial > piecrust2
comparison tests/test_templating_pystacheengine.py @ 369:4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
* We need a distinction between source metadata and route metadata. In most
cases they're the same, but in cases like taxonomy pages, route metadata
contains more things that can't be in source metadata if we want to re-use
cached pages.
* Create a new `QualifiedPage` type which is a page with a specific route
and route metadata. Pass this around in many places.
* Instead of passing an URL around, use the route in the `QualifiedPage` to
generate URLs. This is better since it removes the guess-work from trying
to generate URLs for sub-pages.
* Deep-copy app and page configurations before passing them around to things
that could modify them, like data builders and such.
* Exclude taxonomy pages from iterator data providers.
* Properly nest iterator data providers for when the theme and user page
sources are merged inside `site.pages`.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 03 May 2015 18:47:10 -0700 |
parents | 139179dc7abd |
children | 2537fe95d771 |
comparison
equal
deleted
inserted
replaced
368:2408eb6f4da8 | 369:4b1019bb2533 |
---|---|
17 'contents, expected', | 17 'contents, expected', |
18 [ | 18 [ |
19 ("Raw text", "Raw text"), | 19 ("Raw text", "Raw text"), |
20 ("This is {{foo}}", "This is bar"), | 20 ("This is {{foo}}", "This is bar"), |
21 ("Info:\n{{#page}}\nMy URL: {{url}}\n{{/page}}\n", | 21 ("Info:\n{{#page}}\nMy URL: {{url}}\n{{/page}}\n", |
22 "Info:\nMy URL: /foo\n") | 22 "Info:\nMy URL: /foo.html\n") |
23 ]) | 23 ]) |
24 def test_simple(contents, expected): | 24 def test_simple(contents, expected): |
25 fs = (mock_fs() | 25 fs = (mock_fs() |
26 .withConfig(app_config) | 26 .withConfig(app_config) |
27 .withPage('pages/foo', config=page_config, contents=contents)) | 27 .withPage('pages/foo', config=page_config, contents=contents)) |
28 with mock_fs_scope(fs, open_patches=open_patches): | 28 with mock_fs_scope(fs, open_patches=open_patches): |
29 app = fs.getApp() | 29 app = fs.getApp() |
30 page = get_simple_page(app, 'foo.md') | 30 page = get_simple_page(app, 'foo.md') |
31 output = render_simple_page(page, '/foo') | 31 route = app.getRoute('pages', None) |
32 route_metadata = {'slug': 'foo'} | |
33 output = render_simple_page(page, route, route_metadata) | |
32 assert output == expected | 34 assert output == expected |
33 | 35 |
34 | 36 |
35 def test_layout(): | 37 def test_layout(): |
36 contents = "Blah\n" | 38 contents = "Blah\n" |
42 .withPage('pages/foo', config={'layout': 'blah'}, | 44 .withPage('pages/foo', config={'layout': 'blah'}, |
43 contents=contents)) | 45 contents=contents)) |
44 with mock_fs_scope(fs, open_patches=open_patches): | 46 with mock_fs_scope(fs, open_patches=open_patches): |
45 app = fs.getApp() | 47 app = fs.getApp() |
46 page = get_simple_page(app, 'foo.md') | 48 page = get_simple_page(app, 'foo.md') |
47 output = render_simple_page(page, '/foo') | 49 route = app.getRoute('pages', None) |
50 route_metadata = {'slug': 'foo'} | |
51 output = render_simple_page(page, route, route_metadata) | |
48 assert output == expected | 52 assert output == expected |
49 | 53 |
50 | 54 |
51 def test_partial(): | 55 def test_partial(): |
52 contents = "Info:\n{{#page}}\n{{> page_info}}\n{{/page}}\n" | 56 contents = "Info:\n{{#page}}\n{{> page_info}}\n{{/page}}\n" |
53 partial = "- URL: {{url}}\n- SLUG: {{slug}}\n" | 57 partial = "- URL: {{url}}\n- SLUG: {{slug}}\n" |
54 expected = "Info:\n- URL: /foo\n- SLUG: foo\n" | 58 expected = "Info:\n- URL: /foo.html\n- SLUG: foo\n" |
55 fs = (mock_fs() | 59 fs = (mock_fs() |
56 .withConfig(app_config) | 60 .withConfig(app_config) |
57 .withAsset('templates/page_info.mustache', partial) | 61 .withAsset('templates/page_info.mustache', partial) |
58 .withPage('pages/foo', config=page_config, contents=contents)) | 62 .withPage('pages/foo', config=page_config, contents=contents)) |
59 with mock_fs_scope(fs, open_patches=open_patches): | 63 with mock_fs_scope(fs, open_patches=open_patches): |
60 app = fs.getApp() | 64 app = fs.getApp() |
61 page = get_simple_page(app, 'foo.md') | 65 page = get_simple_page(app, 'foo.md') |
62 output = render_simple_page(page, '/foo') | 66 route = app.getRoute('pages', None) |
67 route_metadata = {'slug': 'foo'} | |
68 output = render_simple_page(page, route, route_metadata) | |
63 assert output == expected | 69 assert output == expected |
64 | 70 |