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