Search in sources :

Example 11 with Content

use of play.twirl.api.Content in project civiform by seattle-uat.

the class HtmlBundleTest method emptyBundleRendersOutline.

@Test
public void emptyBundleRendersOutline() {
    HtmlBundle bundle = new HtmlBundle();
    Content content = bundle.render();
    assertThat(content.body()).contains("<body><header></header><main></main><div id=\"modal-container\" class=\"hidden fixed" + " h-screen w-screen\"><div id=\"modal-glass-pane\" class=\"fixed h-screen" + " w-screen bg-gray-400 opacity-75\"></div></div><footer></footer></body>");
}
Also used : Content(play.twirl.api.Content) Test(org.junit.Test)

Example 12 with Content

use of play.twirl.api.Content in project civiform by seattle-uat.

the class VersionListView method render.

public Content render(List<Version> allVersions, Http.Request request) {
    Optional<Version> draftVersion = allVersions.stream().filter(version -> version.getLifecycleStage().equals(LifecycleStage.DRAFT)).findAny();
    Optional<Version> activeVersion = allVersions.stream().filter(version -> version.getLifecycleStage().equals(LifecycleStage.ACTIVE)).findAny();
    ImmutableList<Version> olderVersions = allVersions.stream().filter(version -> version.getLifecycleStage().equals(LifecycleStage.OBSOLETE)).sorted((a, b) -> a.id.compareTo(b.id)).collect(ImmutableList.toImmutableList()).reverse();
    String title = "Program Versions";
    HtmlBundle htmlBundle = layout.getBundle().setTitle(title).addMainContent(renderHeader("Current Versions"), renderVersionCard(draftVersion), renderVersionCard(activeVersion), renderHeader("Older Versions"), renderPastVersionTable(olderVersions, request));
    return layout.renderCentered(htmlBundle);
}
Also used : NavPage(views.admin.AdminLayout.NavPage) Inject(com.google.inject.Inject) Styles(views.style.Styles) LinkElement(views.components.LinkElement) Content(play.twirl.api.Content) Version(models.Version) AdminLayoutFactory(views.admin.AdminLayoutFactory) ImmutableList(com.google.common.collect.ImmutableList) HtmlBundle(views.HtmlBundle) BaseHtmlView(views.BaseHtmlView) BaseStyles(views.style.BaseStyles) TagCreator.p(j2html.TagCreator.p) TagCreator.table(j2html.TagCreator.table) Config(com.typesafe.config.Config) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) TagCreator.each(j2html.TagCreator.each) StyleUtils(views.style.StyleUtils) LifecycleStage(models.LifecycleStage) Collectors(java.util.stream.Collectors) controllers.admin.routes(controllers.admin.routes) ZoneId(java.time.ZoneId) List(java.util.List) TagCreator.th(j2html.TagCreator.th) AdminLayout(views.admin.AdminLayout) TagCreator.td(j2html.TagCreator.td) TagCreator.tr(j2html.TagCreator.tr) Optional(java.util.Optional) ReferenceClasses(views.style.ReferenceClasses) TagCreator.tbody(j2html.TagCreator.tbody) TagCreator.div(j2html.TagCreator.div) Http(play.mvc.Http) TagCreator.thead(j2html.TagCreator.thead) Tag(j2html.tags.Tag) HtmlBundle(views.HtmlBundle) Version(models.Version)

Example 13 with Content

use of play.twirl.api.Content in project civiform by seattle-uat.

the class ApplicantLayout method render.

@Override
public Content render(HtmlBundle bundle) {
    bundle.addBodyStyles(ApplicantStyles.BODY);
    String currentTitle = bundle.getTitle();
    if (currentTitle != null && !currentTitle.isEmpty()) {
        bundle.setTitle(String.format("%s — %s", currentTitle, CIVIFORM_TITLE));
    } else {
        bundle.setTitle(CIVIFORM_TITLE);
    }
    bundle.addFooterStyles(Styles.MT_24);
    Content rendered = super.render(bundle);
    if (!rendered.body().contains("<h1")) {
        logger.error("Page does not contain an <h1>, which is important for screen readers.");
    }
    if (Strings.countOccurrencesOf(rendered.body(), "<h1") > 1) {
        logger.error("Page contains more than one <h1>, which is detrimental to screen readers.");
    }
    return rendered;
}
Also used : Content(play.twirl.api.Content)

Example 14 with Content

use of play.twirl.api.Content in project civiform by seattle-uat.

the class ProgramApplicationView method render.

public Content render(long programId, String programName, long applicationId, String applicantNameWithApplicationId, ImmutableList<Block> blocks, ImmutableList<AnswerData> answers) {
    String title = "Program Application View";
    ListMultimap<Block, AnswerData> blockToAnswers = ArrayListMultimap.create();
    for (AnswerData answer : answers) {
        Block answerBlock = blocks.stream().filter(block -> block.getId().equals(answer.blockId())).findFirst().orElseThrow();
        blockToAnswers.put(answerBlock, answer);
    }
    Tag contentDiv = div().withId("application-view").withClasses(Styles.PX_20).with(h2("Program: " + programName).withClasses(Styles.MY_4), h1(applicantNameWithApplicationId).withClasses(Styles.MY_4), renderDownloadButton(programId, applicationId), each(blocks, block -> renderApplicationBlock(programId, block, blockToAnswers.get(block))));
    HtmlBundle htmlBundle = layout.getBundle().setTitle(title).addMainContent(contentDiv);
    return layout.render(htmlBundle);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) ListMultimap(com.google.common.collect.ListMultimap) Inject(com.google.inject.Inject) Styles(views.style.Styles) LinkElement(views.components.LinkElement) Content(play.twirl.api.Content) TagCreator.h1(j2html.TagCreator.h1) TagCreator.h2(j2html.TagCreator.h2) ImmutableList(com.google.common.collect.ImmutableList) Block(services.applicant.Block) HtmlBundle(views.HtmlBundle) BaseHtmlView(views.BaseHtmlView) TagCreator.p(j2html.TagCreator.p) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) TagCreator.each(j2html.TagCreator.each) Instant(java.time.Instant) TagCreator.a(j2html.TagCreator.a) StandardCharsets(java.nio.charset.StandardCharsets) ZoneId(java.time.ZoneId) URLEncoder(java.net.URLEncoder) LocalDate(java.time.LocalDate) ReferenceClasses(views.style.ReferenceClasses) TagCreator.div(j2html.TagCreator.div) AnswerData(services.applicant.AnswerData) Tag(j2html.tags.Tag) BaseHtmlLayout(views.BaseHtmlLayout) AnswerData(services.applicant.AnswerData) HtmlBundle(views.HtmlBundle) Block(services.applicant.Block) Tag(j2html.tags.Tag)

Example 15 with Content

use of play.twirl.api.Content in project fess-suggest by codelibs.

the class ApplicationTest method renderTemplate.

@Test
public void renderTemplate() {
    Content html = views.html.index.render("Your new application is ready.");
    assertThat(contentType(html)).isEqualTo("text/html");
    assertThat(contentAsString(html)).contains("Your new application is ready.");
}
Also used : Content(play.twirl.api.Content)

Aggregations

Content (play.twirl.api.Content)15 Tag (j2html.tags.Tag)7 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)6 TagCreator.div (j2html.TagCreator.div)6 TagCreator.each (j2html.TagCreator.each)6 TagCreator.p (j2html.TagCreator.p)6 ZoneId (java.time.ZoneId)6 Test (org.junit.Test)6 BaseHtmlView (views.BaseHtmlView)6 HtmlBundle (views.HtmlBundle)6 LinkElement (views.components.LinkElement)6 ReferenceClasses (views.style.ReferenceClasses)6 Styles (views.style.Styles)6 Inject (com.google.inject.Inject)5 controllers.admin.routes (controllers.admin.routes)5 TagCreator.h1 (j2html.TagCreator.h1)5 Optional (java.util.Optional)5 Http (play.mvc.Http)4 ProgramDefinition (services.program.ProgramDefinition)4 AdminLayout (views.admin.AdminLayout)4