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
55
56
57
58
59
60
61
62
63
64
//! The view engine, built once and used by both the application and its tests.
//!
//! `@lang` asks the *engine* for its translator, so an engine built without
//! one renders the key instead of the word: a page that should read "Sign in"
//! reads `auth.sign_in`. That is the right behaviour for a missing phrase, and
//! the wrong thing for a test to be asserting against — a test that renders a
//! page is standing in for a visitor, and a visitor never sees a key.
//!
//! So the wiring lives here rather than in `main.rs`, where a test could not
//! reach it. `main.rs` calls this; `tests/web.rs` calls this; neither can
//! drift into building an engine the other does not have.
use *;
use ;
/// Load `lang/`, falling back to English for anything untranslated.
///
/// The path is a setting so a deployment can move the directory; `lang` is
/// where the kit puts it.
/// The engine `App` would have built, with somewhere for `@lang` to look.
///
/// `App::finish` builds its own only when nobody else has, so handing this to
/// `.views(...)` replaces it rather than fighting it. The *locale* is not set
/// here — it is per page, and `page::shell` puts it in the view context.
/// The engine above, plus the route table `@route(…)` resolves against.
///
/// **For tests, and only for tests.** `App` fills the table from the router it
/// actually serves, and a route added in `main.rs` and nowhere else is in
/// *that* table — so `main.rs` must keep using [`engine`] and let `App` do it.
/// A test that renders a view without a request has no `App`, so this replays
/// the same registration `main.rs` performs: the two route files and every
/// module. Once the layouts used `@route`, every such test failed with "an
/// engine with no route table"; this is what gives them one.
///
/// If a name a template uses is missing here, the test fails loudly naming it,
/// which is the right outcome: it means `main.rs` registers something this
/// list does not, and the two have drifted.