diff --git a/.dokerignore b/.dokerignore index c16f915..0dc23a6 100644 --- a/.dokerignore +++ b/.dokerignore @@ -1,3 +1,5 @@ .gradle build/ .idea +connection.txt +jte-classes \ No newline at end of file diff --git a/.gitignore b/.gitignore index c16f915..0dc23a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .gradle build/ .idea +connection.txt +jte-classes \ No newline at end of file diff --git a/build.gradle b/build.gradle index 5260353..eafdbd3 100644 --- a/build.gradle +++ b/build.gradle @@ -19,10 +19,12 @@ dependencies { testImplementation platform('org.junit:junit-bom:5.10.2') testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2' implementation 'io.javalin:javalin:6.1.6' + implementation 'io.javalin:javalin-rendering:6.1.6' implementation 'org.slf4j:slf4j-simple:2.0.13' implementation 'com.zaxxer:HikariCP:5.1.0' // implementation 'com.h2database:h2:2.2.224' implementation 'org.postgresql:postgresql:42.7.3' + implementation 'gg.jte:jte:3.1.12' } test { diff --git a/src/main/java/hexlet/code/App.java b/src/main/java/hexlet/code/App.java index 2a766c9..8cb0c44 100644 --- a/src/main/java/hexlet/code/App.java +++ b/src/main/java/hexlet/code/App.java @@ -2,10 +2,14 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; +import gg.jte.ContentType; +import gg.jte.TemplateEngine; +import gg.jte.resolve.ResourceCodeResolver; import hexlet.code.model.Url; import hexlet.code.repository.BaseRepository; import hexlet.code.repository.UrlRepository; import io.javalin.Javalin; +import io.javalin.rendering.template.JavalinJte; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -30,6 +34,13 @@ private static String getDBUrl() { // return Integer.parseInt(port); // } + private static TemplateEngine createTemplateEngine() { + ClassLoader classLoader = App.class.getClassLoader(); + ResourceCodeResolver codeResolver = new ResourceCodeResolver("templates", classLoader); + TemplateEngine templateEngine = TemplateEngine.create(codeResolver, ContentType.Html); + return templateEngine; + } + public static Javalin getApp() throws SQLException { var hikariConfig = new HikariConfig(); var dbUrl = getDBUrl(); @@ -54,9 +65,13 @@ public static Javalin getApp() throws SQLException { throw new SQLException("DB structure was not provided!"); } - var app = Javalin.create(config -> config.bundledPlugins.enableDevLogging()); + var app = Javalin.create(config -> { + config.bundledPlugins.enableDevLogging(); + config.fileRenderer(new JavalinJte(createTemplateEngine())); + }); - app.get("/", ctx -> ctx.result(UrlRepository.getUrls().stream() + app.get("/", ctx -> ctx.render("main.jte")); + app.get("/list", ctx -> ctx.result(UrlRepository.getUrls().stream() .map(Object::toString) .collect(Collectors.joining("\n")))); app.get("/create", ctx -> { diff --git a/src/main/resources/templates/.jteroot b/src/main/resources/templates/.jteroot new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/templates/layout.jte b/src/main/resources/templates/layout.jte new file mode 100644 index 0000000..d4884f4 --- /dev/null +++ b/src/main/resources/templates/layout.jte @@ -0,0 +1,42 @@ +@import gg.jte.Content + +@param Content content + + + + + + + + + Page analyzer 📊 + + +
+

+ Page analyzer + Main page + Sites list +

+
+
+ ${content} +
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/main.jte b/src/main/resources/templates/main.jte new file mode 100644 index 0000000..f2d259f --- /dev/null +++ b/src/main/resources/templates/main.jte @@ -0,0 +1,14 @@ + +@template.layout( + content = @` +
+

Page analyzer

+

Check SEO information for free

+
+ + +
+

Example: https://mail.ru

+
+ ` +) \ No newline at end of file