Skip to content

Commit

Permalink
extract script tags and needles to constants
Browse files Browse the repository at this point in the history
  • Loading branch information
atomfrede committed Dec 11, 2023
1 parent fc3e484 commit 06cb484
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class ThymeleafTemplateModuleFactory {
private static final JHipsterProjectFilePath MAIN_RESOURCES_PATH = path("src/main/resources");
private static final JHipsterDestination DESTINATION = to(MAIN_RESOURCES_PATH.get());

private static final String MAIN_SCRIPT_NEEDLE = "<!-- jhipster-needle-thymeleaf-main-script -->";

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
Assert.notNull(PROPERTIES, properties);

Expand All @@ -41,7 +43,7 @@ public JHipsterModule buildHtmxWebjarsModule(JHipsterModuleProperties properties
return moduleBuilder(properties)
.mandatoryReplacements()
.in(MAIN_RESOURCES_PATH.append(TEMPLATES_LAYOUT).append(MAIN_HTML))
.add(lineBeforeText("<!-- jhipster-needle-thymeleaf-main-script -->"), "<script type=\"text/javascript\" th:src=\"@{/webjars/htmx.org/dist/htmx.min.js}\"></script>")
.add(lineBeforeText(MAIN_SCRIPT_NEEDLE), webjarsScriptTag("htmx.org/dist/htmx.min.js"))
.and()
.and()
.build();
Expand All @@ -55,10 +57,14 @@ public JHipsterModule buildAlpineWebjarsModule(JHipsterModuleProperties properti
return moduleBuilder(properties)
.mandatoryReplacements()
.in(MAIN_RESOURCES_PATH.append(TEMPLATES_LAYOUT).append(MAIN_HTML))
.add(lineBeforeText("<!-- jhipster-needle-thymeleaf-main-script -->"), "<script type=\"text/javascript\" th:src=\"@{/webjars/alpinejs/dist/cdn.js}\"></script>")
.add(lineBeforeText(MAIN_SCRIPT_NEEDLE), webjarsScriptTag("alpinejs/dist/cdn.js"))
.and()
.and()
.build();
//@formatter:on
}

private String webjarsScriptTag(String webjarsLocation) {
return "<script type=\"text/javascript\" th:src=\"@{/webjars/%s}\"></script>".formatted(webjarsLocation);
}
}

0 comments on commit 06cb484

Please sign in to comment.