Search in sources :

Example 1 with Content

use of play.twirl.api.Content in project deployment-examples by Rookout.

the class FunctionalTest method renderTemplate.

@Test
public void renderTemplate() {
    // If you are calling out to Assets, then you must instantiate an application
    // because it makes use of assets metadata that is configured from
    // the application.
    Content html = views.html.index.render("Your new application is ready.");
    assertThat("text/html").isEqualTo(html.contentType());
    assertThat(html.body()).contains("Your new application is ready.");
}
Also used : Content(play.twirl.api.Content) Test(org.junit.Test)

Example 2 with Content

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

the class ProgramAdministratorProgramListView method render.

public Content render(ActiveAndDraftPrograms programs, List<String> authorizedPrograms, Optional<CiviFormProfile> civiformProfile) {
    if (civiformProfile.isPresent() && civiformProfile.get().isProgramAdmin() && !civiformProfile.get().isCiviFormAdmin()) {
        layout.setOnlyProgramAdminType();
    }
    String title = "Your programs";
    Tag contentDiv = div().withClasses(Styles.PX_20).with(h1(title).withClasses(Styles.MY_4), each(programs.getProgramNames().stream().filter(programName -> authorizedPrograms.contains(programName)).map(name -> this.renderProgramListItem(programs.getActiveProgramDefinition(name), programs.getDraftProgramDefinition(name)))));
    HtmlBundle htmlBundle = layout.getBundle().setTitle(title).addMainContent(contentDiv);
    return layout.renderCentered(htmlBundle);
}
Also used : TagCreator.p(j2html.TagCreator.p) Config(com.typesafe.config.Config) Styles(views.style.Styles) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) LinkElement(views.components.LinkElement) TagCreator.each(j2html.TagCreator.each) StyleUtils(views.style.StyleUtils) TagCreator.label(j2html.TagCreator.label) Content(play.twirl.api.Content) TagCreator.h1(j2html.TagCreator.h1) CiviFormProfile(auth.CiviFormProfile) controllers.admin.routes(controllers.admin.routes) ProgramDefinition(services.program.ProgramDefinition) Inject(javax.inject.Inject) ActiveAndDraftPrograms(services.program.ActiveAndDraftPrograms) List(java.util.List) HtmlBundle(views.HtmlBundle) AdminLayout(views.admin.AdminLayout) BaseHtmlView(views.BaseHtmlView) Optional(java.util.Optional) ReferenceClasses(views.style.ReferenceClasses) TagCreator.div(j2html.TagCreator.div) TagCreator.input(j2html.TagCreator.input) Tag(j2html.tags.Tag) HtmlBundle(views.HtmlBundle) Tag(j2html.tags.Tag)

Example 3 with Content

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

the class ProgramApplicationListView method render.

public Content render(Http.Request request, ProgramDefinition program, PaginationResult<Application> paginatedApplications, Optional<String> search) {
    Tag contentDiv = div().withClasses(Styles.PX_20).with(h1(program.adminName()).withClasses(Styles.MY_4), renderPaginationDiv(paginatedApplications.getCurrentPage(), paginatedApplications.getNumPages(), pageNumber -> routes.AdminApplicationController.index(program.id(), search, Optional.of(pageNumber))).withClasses(Styles.MB_2), br(), renderSearchForm(request, search, routes.AdminApplicationController.index(program.id(), Optional.empty(), Optional.empty()), Optional.of(Styles.W_FULL), Optional.of("Search first name, last name, or application ID")).withClasses(Styles.MT_6), each(paginatedApplications.getPageContents(), this::renderApplicationListItem), br(), renderDownloadButton(program.id())).withClasses(Styles.MB_16, Styles.MR_2);
    Tag applicationShowDiv = div().withClasses(Styles.W_FULL, Styles.H_FULL).with(iframe().withId("application-display-frame").withClasses(Styles.W_FULL, Styles.H_FULL));
    HtmlBundle htmlBundle = layout.getBundle().setTitle(program.adminName() + " - Applications").addFooterScripts(layout.viewUtils.makeLocalJsTag("admin_applications")).addMainStyles(Styles.FLEX).addMainContent(contentDiv, applicationShowDiv);
    return layout.renderCentered(htmlBundle);
}
Also used : Inject(com.google.inject.Inject) Styles(views.style.Styles) LoggerFactory(org.slf4j.LoggerFactory) LinkElement(views.components.LinkElement) Content(play.twirl.api.Content) TagCreator.h1(j2html.TagCreator.h1) HtmlBundle(views.HtmlBundle) TagCreator.br(j2html.TagCreator.br) BaseHtmlView(views.BaseHtmlView) Application(models.Application) TagCreator.p(j2html.TagCreator.p) Logger(org.slf4j.Logger) TagCreator.span(j2html.TagCreator.span) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PaginationResult(services.PaginationResult) TagCreator.each(j2html.TagCreator.each) controllers.admin.routes(controllers.admin.routes) ZoneId(java.time.ZoneId) ProgramDefinition(services.program.ProgramDefinition) AdminLayout(views.admin.AdminLayout) DateTimeFormatter(java.time.format.DateTimeFormatter) TagCreator.iframe(j2html.TagCreator.iframe) Optional(java.util.Optional) ReferenceClasses(views.style.ReferenceClasses) TagCreator.div(j2html.TagCreator.div) Http(play.mvc.Http) Tag(j2html.tags.Tag) HtmlBundle(views.HtmlBundle) Tag(j2html.tags.Tag)

Example 4 with Content

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

the class BaseHtmlLayoutTest method addsDefaultContent.

@Test
public void addsDefaultContent() {
    HtmlBundle bundle = layout.getBundle();
    Content content = layout.render(bundle);
    assertThat(content.body()).contains("<!DOCTYPE html><html>");
    assertThat(content.body()).contains("<link href=\"/assets/stylesheets/tailwind.css\" rel=\"stylesheet\">");
    assertThat(content.body()).contains("<script src=\"/assets/javascripts/main.js\" type=\"text/javascript\"></script>");
    assertThat(content.body()).contains("<script src=\"/assets/javascripts/radio.js\" type=\"text/javascript\"></script>");
    assertThat(content.body()).contains("<main></main>");
}
Also used : Content(play.twirl.api.Content) Test(org.junit.Test)

Example 5 with Content

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

the class HtmlBundleTest method rendersContentInOrder.

@Test
public void rendersContentInOrder() {
    HtmlBundle bundle = new HtmlBundle();
    bundle.addMainContent(div("One"));
    bundle.addMainContent(div("Two"));
    Content content = bundle.render();
    assertThat(content.body()).contains("<main><div>One</div><div>Two</div></main>");
}
Also used : Content(play.twirl.api.Content) Test(org.junit.Test)

Aggregations

Content (play.twirl.api.Content)13 Test (org.junit.Test)6 Tag (j2html.tags.Tag)5 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)4 TagCreator.div (j2html.TagCreator.div)4 TagCreator.each (j2html.TagCreator.each)4 TagCreator.p (j2html.TagCreator.p)4 BaseHtmlView (views.BaseHtmlView)4 HtmlBundle (views.HtmlBundle)4 LinkElement (views.components.LinkElement)4 ReferenceClasses (views.style.ReferenceClasses)4 Styles (views.style.Styles)4 Inject (com.google.inject.Inject)3 controllers.admin.routes (controllers.admin.routes)3 TagCreator.h1 (j2html.TagCreator.h1)3 Optional (java.util.Optional)3 ImmutableList (com.google.common.collect.ImmutableList)2 ZoneId (java.time.ZoneId)2 List (java.util.List)2 Http (play.mvc.Http)2