Package: HtmlTemplateHtmlTextWithTitleView
HtmlTemplateHtmlTextWithTitleView
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
HtmlTemplateHtmlTextWithTitleView(Id, Site) |
|
|
|
|
|
||||||||||||||||||||
getId() |
|
|
|
|
|
||||||||||||||||||||
lambda$render$0(Template, Object) |
|
|
|
|
|
||||||||||||||||||||
lambda$render$1(Template, Object) |
|
|
|
|
|
||||||||||||||||||||
lambda$render$2(Template, Object) |
|
|
|
|
|
||||||||||||||||||||
lambda$render$3(Optional, Optional, Template.Aggregate) |
|
|
|
|
|
||||||||||||||||||||
render(Optional, Optional, Template.Aggregates) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.frontend.ui.component.htmltextwithtitle.htmltemplate;
28:
29: import javax.annotation.Nonnull;
30: import java.util.Optional;
31: import it.tidalwave.util.Id;
32: import it.tidalwave.northernwind.core.model.ResourcePath;
33: import it.tidalwave.northernwind.core.model.Site;
34: import it.tidalwave.northernwind.core.model.Template.Aggregates;
35: import it.tidalwave.northernwind.frontend.ui.annotation.ViewMetadata;
36: import it.tidalwave.northernwind.frontend.ui.component.htmltemplate.HtmlHolder;
37: import it.tidalwave.northernwind.frontend.ui.component.htmltextwithtitle.HtmlTextWithTitleView;
38: import lombok.Getter;
39: import static java.util.stream.Collectors.*;
40:
41: /***********************************************************************************************************************
42: *
43: * An implementation of {@link HtmlTextWithTitleView} based on HTML templates.
44: *
45: * @see HtmlTemplateHtmlTextWithTitleViewController
46: * @author Fabrizio Giudici
47: *
48: **********************************************************************************************************************/
49: @ViewMetadata(typeUri="http://northernwind.tidalwave.it/component/HtmlTextWithTitle/#v1.0",
50: controlledBy=HtmlTemplateHtmlTextWithTitleViewController.class)
51: public class HtmlTemplateHtmlTextWithTitleView extends HtmlHolder implements HtmlTextWithTitleView
52: {
53: @Getter @Nonnull
54: private final Id id;
55:
56: @Nonnull
57: private final Site site;
58:
59: /*******************************************************************************************************************
60: *
61: * Creates a new instance.
62: *
63: * @param id the id of the view
64: * @param site the {@link Site}
65: *
66: ******************************************************************************************************************/
67: public HtmlTemplateHtmlTextWithTitleView (@Nonnull final Id id, @Nonnull final Site site)
68: {
69: super(id);
70: this.id = id;
71: this.site = site;
72:• }
73:
74: /*******************************************************************************************************************
75: *
76: * Renders this view. See {@link HtmlTemplateHtmlTextWithTitleViewController} for more information.
77: *
78: * @see HtmlTemplateHtmlTextWithTitleViewController
79: * @param wrapperTemplatePath the optional template to wrap around each item of contents
80: * @param templatePath the template for rendering
81: * @param contents the contents to render
82: *
83: ******************************************************************************************************************/
84: public void render (@Nonnull final Optional<ResourcePath> wrapperTemplatePath,
85: @Nonnull final Optional<ResourcePath> templatePath,
86: @Nonnull final Aggregates contents)
87: {
88: addComponent(new HtmlHolder(contents.stream().map(a ->
89: {
90: final var textTemplate = site.getTemplate(getClass(), templatePath, "Text.st");
91: final var wrapperTemplate = site.getTemplate(getClass(), wrapperTemplatePath, "Wrapper.st");
92:
93: a.get("title").ifPresent(t -> textTemplate.addAttribute("title", t.toString()));
94: a.get("text").ifPresent(t -> textTemplate.addAttribute("text", t.toString()));
95: a.get("level").ifPresent(l -> textTemplate.addAttribute("level", l.toString()));
96:
97: return wrapperTemplate.addAttribute("content", textTemplate.render()).render();
98: }).collect(joining("\n"))));
99: }
100: }