Skip to content

Commit

Permalink
replay-tests: fasttags and gtfasttags on classpath example
Browse files Browse the repository at this point in the history
  • Loading branch information
xabolcs committed Feb 13, 2025
1 parent b15e858 commit 1e03656
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tags.fasttags;

import groovy.lang.Closure;
import play.templates.ExecutableTemplate;
import play.templates.FastTags;
import java.io.PrintWriter;
import java.util.Map;

@FastTags.Namespace("app")
public class HelloFromApp extends FastTags {

public static void _hello (Map<?, ?> args, Closure<String> body, PrintWriter out, ExecutableTemplate template, int fromLine) {
String name = args.containsKey("name") ? args.get("name").toString() : "";
if (name.isEmpty()) {
throw new play.exceptions.TagInternalException("name attribute cannot be empty for " + Thread.currentThread().getStackTrace()[1].getMethodName().substring(1) + " tag");
}

out.print("Hello from " + HelloFromApp.class.getAnnotation(FastTags.Namespace.class).value() + ", " + name + "!");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tags.fasttags;

import play.template2.GTContentRenderer;
import play.template2.GTFastTag;
import play.template2.GTJavaBase;
import java.util.Map;

@GTFastTag.TagNamespace("appGT")
public class HelloFromAppGT extends GTFastTag {
public static void tag_hello (GTJavaBase template, Map<String, Object> args, GTContentRenderer content) {
String name = args.containsKey("name") ? args.get("name").toString() : "";
if (name.isEmpty()) {
throw new play.exceptions.TagInternalException("name attribute cannot be empty for " + Thread.currentThread().getStackTrace()[1].getMethodName().substring(4) + " tag");
}

template.out.append("Hello from ")
.append(HelloFromAppGT.class.getAnnotation(GTFastTag.TagNamespace.class).value())
.append(", ").append(name).append("!");
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
package ui.hello;

import org.junit.jupiter.api.Test;

import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.open;

import hello.fasttags.HelloFromCore;
import hello.fasttags.HelloFromCoreGT;
import tags.fasttags.HelloFromApp;
import tags.fasttags.HelloFromAppGT;

import play.template2.GTFastTag;
import play.templates.FastTags;

import org.junit.jupiter.api.Test;

public class MultiModuleAppGotRenderStaticSpec extends BaseSpec {
@Test
public void openHelloWorldPage() {
open("/");
$("h1").shouldHave(text("Hello, world!"));

$("h1#fasttag_hello_app").shouldHave(text("Hello from "),
text(HelloFromApp.class.getAnnotation(FastTags.Namespace.class).value()));
$("h1#fasttag_hello_core").shouldHave(text("Hello from "),
text(HelloFromCore.class.getAnnotation(FastTags.Namespace.class).value()));

$("h1#gt_hello_app").shouldHave(text("Hello from "),
text(HelloFromAppGT.class.getAnnotation(GTFastTag.TagNamespace.class).value()));
$("h1#gt_hello_core").shouldHave(text("Hello from "),
text(HelloFromCoreGT.class.getAnnotation(GTFastTag.TagNamespace.class).value()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package hello.fasttags;

import groovy.lang.Closure;
import play.templates.ExecutableTemplate;
import play.templates.FastTags;
import java.io.PrintWriter;
import java.util.Map;

@FastTags.Namespace("core")
public class HelloFromCore extends FastTags {

public static void _hello (Map<?, ?> args, Closure<String> body, PrintWriter out, ExecutableTemplate template, int fromLine) {
String name = args.containsKey("name") ? args.get("name").toString() : "";
if (name.isEmpty()) {
throw new play.exceptions.TagInternalException("name attribute cannot be empty for " + Thread.currentThread().getStackTrace()[1].getMethodName().substring(1) + " tag");
}
out.print("Hello from " + HelloFromCore.class.getAnnotation(FastTags.Namespace.class).value() + ", " + name + "!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package hello.fasttags;

import play.template2.GTContentRenderer;
import play.template2.GTFastTag;
import play.template2.GTJavaBase;
import java.util.Map;

@GTFastTag.TagNamespace("coreGT")
public class HelloFromCoreGT extends GTFastTag {
public static void tag_hello (GTJavaBase template, Map<String, Object> args, GTContentRenderer content) {
String name = args.containsKey("name") ? args.get("name").toString() : "";
if (name.isEmpty()) {
throw new play.exceptions.TagInternalException("name attribute cannot be empty for " + Thread.currentThread().getStackTrace()[1].getMethodName().substring(4) + " tag");
}

template.out.append("Hello from ")
.append(HelloFromCoreGT.class.getAnnotation(GTFastTag.TagNamespace.class).value())
.append(", ").append(name).append("!");

}
}
5 changes: 4 additions & 1 deletion replay-tests/multi-module-app/core/app/views/hello.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#{include './meta.html'/}
</head>
<body>
<h1>Hello, ${who}!</h1>
<h1 id="fasttag_hello_app">#{app.hello name: who /}</h1>
<h1 id="gt_hello_app">#{appGT.hello name: who /}</h1>
<h1 id="fasttag_hello_core">#{core.hello name: who /}</h1>
<h1 id="gt_hello_core">#{coreGT.hello name: who /}</h1>
#{include './core.html'/}

</body>
Expand Down

0 comments on commit 1e03656

Please sign in to comment.