|
1 |
| -using System.Collections.Generic; |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.IO;
|
3 | 4 | using System.Threading.Tasks;
|
4 | 5 |
|
5 | 6 | using GenHTTP.Api.Content;
|
6 | 7 | using GenHTTP.Api.Content.Templating;
|
7 |
| -using GenHTTP.Api.Content.Websites; |
8 | 8 | using GenHTTP.Api.Protocol;
|
9 | 9 |
|
10 | 10 | namespace GenHTTP.Modules.Pages.Combined
|
11 | 11 | {
|
12 | 12 |
|
13 |
| - public class CombinedPageBuilder : IHandlerBuilder<CombinedPageBuilder>, IContentInfoBuilder<CombinedPageBuilder> |
| 13 | + public class CombinedPageBuilder : |
| 14 | + IHandlerBuilder<CombinedPageBuilder>, |
| 15 | + IContentInfoBuilder<CombinedPageBuilder>, |
| 16 | + IPageAdditionBuilder<CombinedPageBuilder>, |
| 17 | + IResponseModification<CombinedPageBuilder> |
14 | 18 | {
|
15 | 19 | private readonly List<IConcernBuilder> _Concerns = new();
|
16 | 20 |
|
17 | 21 | private readonly ContentInfoBuilder _Info = new();
|
18 | 22 |
|
19 | 23 | private readonly List<PageFragment> _Fragments = new();
|
20 | 24 |
|
21 |
| - private readonly PageAdditions _Additions = PageAdditions.Create(); |
| 25 | + private readonly PageAdditionBuilder _Additions = new PageAdditionBuilder(); |
| 26 | + |
| 27 | + private readonly ResponseModificationBuilder _Modifications = new ResponseModificationBuilder(); |
22 | 28 |
|
23 | 29 | #region Supporting data structures
|
24 | 30 |
|
@@ -66,18 +72,6 @@ public CombinedPageBuilder Title(string title)
|
66 | 72 | return this;
|
67 | 73 | }
|
68 | 74 |
|
69 |
| - public CombinedPageBuilder AddScript(ScriptReference reference) |
70 |
| - { |
71 |
| - _Additions.Scripts.Add(reference); |
72 |
| - return this; |
73 |
| - } |
74 |
| - |
75 |
| - public CombinedPageBuilder AddStyle(StyleReference reference) |
76 |
| - { |
77 |
| - _Additions.Styles.Add(reference); |
78 |
| - return this; |
79 |
| - } |
80 |
| - |
81 | 75 | /// <summary>
|
82 | 76 | /// Adds a dynamically rendered part to the page.
|
83 | 77 | /// </summary>
|
@@ -124,9 +118,69 @@ public CombinedPageBuilder Add(IConcernBuilder concern)
|
124 | 118 | return this;
|
125 | 119 | }
|
126 | 120 |
|
| 121 | + public CombinedPageBuilder AddScript(string path, bool asynchronous = false) |
| 122 | + { |
| 123 | + _Additions.AddScript(path, asynchronous); |
| 124 | + return this; |
| 125 | + } |
| 126 | + |
| 127 | + public CombinedPageBuilder AddStyle(string path) |
| 128 | + { |
| 129 | + _Additions.AddStyle(path); |
| 130 | + return this; |
| 131 | + } |
| 132 | + |
| 133 | + public CombinedPageBuilder Status(ResponseStatus status) |
| 134 | + { |
| 135 | + _Modifications.Status(status); |
| 136 | + return this; |
| 137 | + } |
| 138 | + |
| 139 | + public CombinedPageBuilder Status(int status, string reason) |
| 140 | + { |
| 141 | + _Modifications.Status(status, reason); |
| 142 | + return this; |
| 143 | + } |
| 144 | + |
| 145 | + public CombinedPageBuilder Header(string key, string value) |
| 146 | + { |
| 147 | + _Modifications.Header(key, value); |
| 148 | + return this; |
| 149 | + } |
| 150 | + |
| 151 | + public CombinedPageBuilder Expires(DateTime expiryDate) |
| 152 | + { |
| 153 | + _Modifications.Expires(expiryDate); |
| 154 | + return this; |
| 155 | + } |
| 156 | + |
| 157 | + public CombinedPageBuilder Modified(DateTime modificationDate) |
| 158 | + { |
| 159 | + _Modifications.Modified(modificationDate); |
| 160 | + return this; |
| 161 | + } |
| 162 | + |
| 163 | + public CombinedPageBuilder Cookie(Cookie cookie) |
| 164 | + { |
| 165 | + _Modifications.Cookie(cookie); |
| 166 | + return this; |
| 167 | + } |
| 168 | + |
| 169 | + public CombinedPageBuilder Type(FlexibleContentType contentType) |
| 170 | + { |
| 171 | + _Modifications.Type(contentType); |
| 172 | + return this; |
| 173 | + } |
| 174 | + |
| 175 | + public CombinedPageBuilder Encoding(string encoding) |
| 176 | + { |
| 177 | + _Modifications.Encoding(encoding); |
| 178 | + return this; |
| 179 | + } |
| 180 | + |
127 | 181 | public IHandler Build(IHandler parent)
|
128 | 182 | {
|
129 |
| - return Concerns.Chain(parent, _Concerns, (p) => new CombinedPageProvider(p, _Info.Build(), _Additions, _Fragments)); |
| 183 | + return Concerns.Chain(parent, _Concerns, (p) => new CombinedPageProvider(p, _Info.Build(), _Additions.Build(), _Modifications.Build(), _Fragments)); |
130 | 184 | }
|
131 | 185 |
|
132 | 186 | #endregion
|
|
0 commit comments