1 /**************************************************************************
2 *
3 * Copyright (c) 2016-2020 Yawg project contributors.
4 *
5 **************************************************************************/
6
7 package com.varmateo.yawg.spi;
8
9
10 /**
11 * Data available to a template during processing.
12 */
13 public interface TemplateContext {
14
15
16 /**
17 * The authors of the document. It may be an empty list.
18 */
19 Iterable<Author> authors();
20
21
22 /**
23 * The raw HTML contents of the baked document. This is actually
24 * an HTML snippet appropriate for inclusion under a
25 * <code><body></code> tag, or any other block level
26 * element.
27 */
28 String body();
29
30
31 /**
32 * The URL of the page being baked relative to the root directory
33 * of the site.
34 */
35 String pageUrl();
36
37
38 /**
39 * Set of variables available to the page template. These
40 * variables are immutable.
41 */
42 PageVars pageVars();
43
44
45 /**
46 * The URL of the root directory of the site being baked relative
47 * to the document about to be baked.
48 */
49 String rootRelativeUrl();
50
51
52 /**
53 * The title of the document, as extracted from its source.
54 */
55 String title();
56
57
58 /**
59 * Randomly generated unique bake identifier. Each bake will have
60 * a different identifier.
61 */
62 String bakeId();
63
64
65 /**
66 * Document author data.
67 */
68 final class Author {
69
70
71 private final String _name;
72 private final String _email;
73
74
75 /**
76 *
77 */
78 private Author(
79 final String name,
80 final String email) {
81
82 _name = name;
83 _email = email;
84 }
85
86
87 /**
88 *
89 */
90 public static Author create(
91 final String name,
92 final String email) {
93
94 return new Author(name, email);
95 }
96
97
98 /**
99 * @return Author's name. It is never null.
100 */
101 public String name() {
102
103 return _name;
104 }
105
106
107 /**
108 * @return Author's email. It might be null.
109 */
110 public String email() {
111
112 return _email;
113 }
114
115
116 }
117
118
119 }