1
2
3
4
5
6
7 package com.varmateo.yawg.core;
8
9 import java.nio.file.Path;
10
11 import io.vavr.collection.List;
12 import io.vavr.collection.Seq;
13 import io.vavr.control.Option;
14
15 import com.varmateo.yawg.spi.PageVars;
16 import com.varmateo.yawg.spi.PageVarsBuilder;
17 import com.varmateo.yawg.util.GlobMatcher;
18
19
20
21
22
23
24 final class DirBakeOptions {
25
26
27
28
29
30
31 public final Option<String> templateName;
32
33
34
35
36
37 public final Option<GlobMatcher> filesToExclude;
38
39
40
41
42 public final Option<GlobMatcher> filesToExcludeHere;
43
44
45
46
47
48 public final Option<GlobMatcher> filesToIncludeHere;
49
50
51
52
53 public final Option<BakerMatcher> bakerTypes;
54
55
56
57
58
59 public final PageVars pageVars;
60
61
62
63
64
65
66 public final PageVars pageVarsHere;
67
68
69
70
71
72 public final TemplateNameMatcher templatesHere;
73
74
75
76
77
78
79
80
81 public final Seq<Path> extraDirsHere;
82
83
84
85
86
87 DirBakeOptions(final Builder builder) {
88
89 this.templateName = builder._templateName;
90 this.filesToExclude = builder._filesToExclude;
91 this.filesToExcludeHere = builder._filesToExcludeHere;
92 this.filesToIncludeHere = builder._filesToIncludeHere;
93 this.bakerTypes = builder._bakerTypes;
94 this.pageVars = builder._pageVarsBuilder.build();
95 this.pageVarsHere = builder._pageVarsHere;
96 this.templatesHere = builder._templatesHere;
97 this.extraDirsHere = builder._extraDirsHere;
98 }
99
100
101
102
103
104
105
106 public static Builder builder() {
107
108 return new Builder();
109 }
110
111
112
113
114
115 public static DirBakeOptions empty() {
116
117 return DirBakeOptions.builder().build();
118 }
119
120
121
122
123
124
125
126
127
128
129
130
131 public DirBakeOptions#DirBakeOptions">DirBakeOptions mergeOnTopOf(final DirBakeOptions that) {
132
133 final Builder builder = new Builder(that);
134
135 this.templateName.forEach(builder::templateName);
136 this.filesToExclude.forEach(builder::addFilesToExclude);
137 this.filesToExcludeHere.forEach(builder::filesToExcludeHere);
138 this.filesToIncludeHere.forEach(builder::filesToIncludeHere);
139 this.bakerTypes.forEach(builder::addBakerTypes);
140 builder
141 .addPageVars(this.pageVars)
142 .pageVarsHere(this.pageVarsHere)
143 .templatesHere(this.templatesHere)
144 .extraDirsHere(this.extraDirsHere);
145
146
147 return builder.build();
148 }
149
150
151
152
153
154 public static final class Builder {
155
156
157
158 private Option<GlobMatcher> _filesToExcludeHere = Option.none();
159 private Option<GlobMatcher> _filesToIncludeHere = Option.none();
160 private PageVars _pageVarsHere = PageVars.empty();
161 private TemplateNameMatcher _templatesHere = TemplateNameMatcher.empty();
162
163
164
165 private Option<String> _templateName;
166 private Option<GlobMatcher> _filesToExclude;
167 private Option<BakerMatcher> _bakerTypes;
168 private PageVarsBuilder _pageVarsBuilder;
169 private Seq<Path> _extraDirsHere;
170
171
172
173
174
175 Builder() {
176
177 _templateName = Option.none();
178 _filesToExclude = Option.none();
179 _bakerTypes = Option.none();
180 _pageVarsBuilder = PageVarsBuilder.create();
181 _extraDirsHere = List.of();
182 }
183
184
185
186
187
188 Builder(final DirBakeOptions defaults) {
189
190 _templateName = defaults.templateName;
191 _filesToExclude = defaults.filesToExclude;
192 _bakerTypes = defaults.bakerTypes;
193 _pageVarsBuilder = PageVarsBuilder.create(defaults.pageVars);
194 _extraDirsHere = defaults.extraDirsHere;
195 }
196
197
198
199
200
201 public Builder templateName(final String templateName) {
202
203 _templateName = Option.of(templateName);
204
205 return this;
206 }
207
208
209
210
211
212 public Builder filesToExclude(final GlobMatcher fileNames) {
213
214 _filesToExclude = Option.of(fileNames);
215
216 return this;
217 }
218
219
220
221
222
223
224 public Builder filesToExclude(final String... fileNames) {
225
226 final GlobMatcher patterns = GlobMatcher.create(fileNames);
227
228 filesToExclude(patterns);
229
230 return this;
231 }
232
233
234
235
236
237 private Builder addFilesToExclude(final GlobMatcher fileNames) {
238
239 _filesToExclude = _filesToExclude
240 .map(x ->
241 GlobMatcher.builder(x).addGlobMatcher(fileNames).build())
242 .orElse(() -> Option.some(fileNames));
243
244 return this;
245 }
246
247
248
249
250
251 public Builder filesToExcludeHere(final GlobMatcher fileNames) {
252
253 _filesToExcludeHere = Option.of(fileNames);
254
255 return this;
256 }
257
258
259
260
261
262
263 public Builder filesToExcludeHere(final String... fileNames) {
264
265 final GlobMatcher patterns = GlobMatcher.create(fileNames);
266
267 return filesToExcludeHere(patterns);
268 }
269
270
271
272
273
274 public Builder filesToIncludeHere(final GlobMatcher fileNames) {
275
276 _filesToIncludeHere = Option.of(fileNames);
277
278 return this;
279 }
280
281
282
283
284
285
286 public Builder filesToIncludeHere(final String... fileNames) {
287
288 final GlobMatcher patterns = GlobMatcher.create(fileNames);
289
290 return filesToIncludeHere(patterns);
291 }
292
293
294
295
296
297 public Builder bakerTypes(final BakerMatcher bakerTypes) {
298
299 _bakerTypes = Option.of(bakerTypes);
300
301 return this;
302 }
303
304
305
306
307
308 public Builder addBakerType(
309 final String bakerType,
310 final String... fileNames) {
311
312 final BakerMatcher bakerTypes = BakerMatcher.builder()
313 .addBakerType(bakerType, fileNames)
314 .build();
315
316 addBakerTypes(bakerTypes);
317
318 return this;
319 }
320
321
322
323
324
325 private Builder addBakerTypes(final BakerMatcher bakerTypes) {
326
327 _bakerTypes = _bakerTypes
328 .map(x ->
329 BakerMatcher.builder(x).addBakerTypes(bakerTypes).build())
330 .orElse(() -> Option.of(bakerTypes));
331
332 return this;
333 }
334
335
336
337
338
339 public Builder pageVars(final PageVars pageVars) {
340
341 _pageVarsBuilder = PageVarsBuilder.create(pageVars);
342
343 return this;
344 }
345
346
347
348
349
350 private Builder addPageVars(final PageVars pageVars) {
351
352 _pageVarsBuilder.addPageVars(pageVars);
353
354 return this;
355 }
356
357
358
359
360
361 public Builder pageVarsHere(final PageVars pageVarsHere) {
362
363 _pageVarsHere = pageVarsHere;
364
365 return this;
366 }
367
368
369
370
371
372 public Builder templatesHere(final TemplateNameMatcher templatesHere) {
373
374 _templatesHere = templatesHere;
375
376 return this;
377 }
378
379
380
381
382
383 public Builder extraDirsHere(final Seq<Path> extraDirsHere) {
384
385 _extraDirsHere = extraDirsHere;
386
387 return this;
388 }
389
390
391
392
393
394 public DirBakeOptions build() {
395
396 return new DirBakeOptions(this);
397 }
398
399
400 }
401
402
403 }