Skip to content

Commit

Permalink
Merge pull request #8229 from atomfrede/htmx-webjars
Browse files Browse the repository at this point in the history
add htmx webjars module
  • Loading branch information
pascalgrimaud authored Dec 7, 2023
2 parents 63de630 + 8362ea2 commit c20e241
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
return moduleBuilder(properties)
.javaDependencies()
.addDependency(SPRING_GROUP, artifactId("spring-boot-starter-thymeleaf"))
.addDependency(groupId("nz.net.ultraq.thymeleaf"), artifactId("thymeleaf-layout-dialect"))
.addDependency(javaDependency().groupId("nz.net.ultraq.thymeleaf").artifactId("thymeleaf-layout-dialect").versionSlug("thymeleaf-layout-dialect.version").build())
.and()
.build();
//@formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ public WebjarsApplicationService() {
webjarsModuleFactory = new WebjarsModuleFactory();
}

public JHipsterModule buildWebjarsModule(JHipsterModuleProperties properties) {
return webjarsModuleFactory.buildModule(properties);
public JHipsterModule buildWebjarsLocatorModule(JHipsterModuleProperties properties) {
return webjarsModuleFactory.buildWebjarsLocatorModule(properties);
}

public JHipsterModule buildWebjarsHtmxModule(JHipsterModuleProperties properties) {
return webjarsModuleFactory.buildWebjarsHtmxModule(properties);
}

public JHipsterModule buildWebjarsAlpineJSModule(JHipsterModuleProperties properties) {
return webjarsModuleFactory.buildWebjarsAlpineJSModule(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,40 @@

public class WebjarsModuleFactory {

private static final String PROPERTIES_FIELD = "properties";
private static final GroupId WEBJARS_GROUP = groupId("org.webjars");
private static final GroupId WEBJARS_NPM_GROUP = groupId("org.webjars.npm");

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);
public JHipsterModule buildWebjarsLocatorModule(JHipsterModuleProperties properties) {
Assert.notNull(PROPERTIES_FIELD, properties);

//@formatter:off
return moduleBuilder(properties)
.javaDependencies()
.addDependency(WEBJARS_GROUP, artifactId("webjars-locator"))
.addDependency(javaDependency().groupId(WEBJARS_GROUP).artifactId("webjars-locator").versionSlug("webjars-locator.version").build())
.and()
.build();
//@formatter:on
}

public JHipsterModule buildWebjarsHtmxModule(JHipsterModuleProperties properties) {
Assert.notNull(PROPERTIES_FIELD, properties);
//@formatter:off
return moduleBuilder(properties)
.javaDependencies()
.addDependency(javaDependency().groupId(WEBJARS_NPM_GROUP).artifactId("htmx.org").versionSlug("htmx-webjars.version").build())
.and()
.build();
//@formatter:on
}

public JHipsterModule buildWebjarsAlpineJSModule(JHipsterModuleProperties properties) {
Assert.notNull(PROPERTIES_FIELD, properties);

//@formatter:off
return moduleBuilder(properties)
.javaDependencies()
.addDependency(javaDependency().groupId(WEBJARS_NPM_GROUP).artifactId("alpinejs").versionSlug("alpinejs-webjars.version").build())
.and()
.build();
//@formatter:on
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tech.jhipster.lite.generator.server.webjars.infrastructure.primary;

import static tech.jhipster.lite.generator.slug.domain.JHLiteModuleSlug.SPRING_BOOT_THYMELEAF;
import static tech.jhipster.lite.generator.slug.domain.JHLiteModuleSlug.WEBJARS;
import static tech.jhipster.lite.generator.slug.domain.JHLiteModuleSlug.*;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -13,17 +12,49 @@
@Configuration
class WebjarsModuleConfiguration {

private static final String SERVER_TAG = "server";
private static final String WEB_TAG = "web";
private static final String WEBJARS_GROUP = "WebJars";

@Bean
public JHipsterModuleResource webjarsModule(WebjarsApplicationService webjarsModule) {
public JHipsterModuleResource webjarsLocatorModule(WebjarsApplicationService webjarsModule) {
return JHipsterModuleResource
.builder()
.slug(WEBJARS)
.slug(WEBJARS_LOCATOR)
.propertiesDefinition(
JHipsterModulePropertiesDefinition.builder().addBasePackage().addProjectBaseName().addConfigurationFormat().build()
)
.apiDoc("WebJars", "Add WebJars to the project")
.apiDoc(WEBJARS_GROUP, "Add webjars locator to the project")
.organization(JHipsterModuleOrganization.builder().addDependency(SPRING_BOOT_THYMELEAF).build())
.tags("server", "web")
.factory(webjarsModule::buildWebjarsModule);
.tags(SERVER_TAG, WEB_TAG)
.factory(webjarsModule::buildWebjarsLocatorModule);
}

@Bean
public JHipsterModuleResource webjarsHtmxModule(WebjarsApplicationService webjarsModule) {
return JHipsterModuleResource
.builder()
.slug(HTMX_WEBJARS)
.propertiesDefinition(
JHipsterModulePropertiesDefinition.builder().addBasePackage().addProjectBaseName().addConfigurationFormat().build()
)
.apiDoc(WEBJARS_GROUP, "Add HTMX webjar to the project")
.organization(JHipsterModuleOrganization.builder().addDependency(WEBJARS_LOCATOR).build())
.tags(SERVER_TAG, WEB_TAG)
.factory(webjarsModule::buildWebjarsHtmxModule);
}

@Bean
public JHipsterModuleResource webjarsAlpineJSModule(WebjarsApplicationService webjarsModule) {
return JHipsterModuleResource
.builder()
.slug(ALPINE_JS_WEBJARS)
.propertiesDefinition(
JHipsterModulePropertiesDefinition.builder().addBasePackage().addProjectBaseName().addConfigurationFormat().build()
)
.apiDoc(WEBJARS_GROUP, "Add alpine.js webjar to the project")
.organization(JHipsterModuleOrganization.builder().addDependency(WEBJARS_LOCATOR).build())
.tags(SERVER_TAG, WEB_TAG)
.factory(webjarsModule::buildWebjarsAlpineJSModule);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ public enum JHLiteModuleSlug implements JHipsterModuleSlugFactory {
SPRINGDOC_OAUTH_2_AUTH_0("springdoc-oauth2-auth0"),
SPRINGDOC_OAUTH_2_OKTA("springdoc-oauth2-okta"),
SPRINGDOC_WEBFLUX_OPENAPI("springdoc-webflux-openapi"),
WEBJARS("webjars"),
WEBJARS_LOCATOR("webjars-locator"),
HTMX_WEBJARS("htmx-webjars"),
ALPINE_JS_WEBJARS("alpinejs-webjars"),
SVELTE_CORE("svelte-core"),
TYPESCRIPT("typescript"),
VUE_CORE("vue-core"),
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/generator/dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
<cassandraunit.version>4.3.1.0</cassandraunit.version>
<thymeleaf-layout-dialect.version>3.3.0</thymeleaf-layout-dialect.version>
<webjars-locator.version>0.50</webjars-locator.version>
<htmx-webjars.version>1.9.9</htmx-webjars.version>
<alpinejs-webjars.version>3.13.3</alpinejs-webjars.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -272,6 +274,16 @@
<artifactId>webjars-locator</artifactId>
<version>${webjars-locator.version}</version>
</dependency>
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>htmx.org</artifactId>
<version>${htmx-webjars.version}</version>
</dependency>
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>alpinejs</artifactId>
<version>${alpinejs-webjars.version}</version>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
Expand Down
22 changes: 21 additions & 1 deletion src/test/features/server/webjars/webjars.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,25 @@ Feature: WebJars module
| maven-java |
| spring-boot |
| spring-boot-thymeleaf |
| webjars |
| webjars-locator |
Then I should have "<artifactId>webjars-locator</artifactId>" in "pom.xml"

Scenario: Should add HTMX webjar
When I apply modules to default project
| maven-java |
| spring-boot |
| spring-boot-thymeleaf |
| webjars-locator |
| htmx-webjars |
Then I should have "<artifactId>htmx.org</artifactId>" in "pom.xml"

Scenario: Should add alpine.js webjar
When I apply modules to default project
| maven-java |
| spring-boot |
| spring-boot-thymeleaf |
| webjars-locator |
| alpinejs-webjars |
Then I should have "<artifactId>alpinejs</artifactId>" in "pom.xml"


Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void shouldCreateSpringBootThymeleafModule() {
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>${thymeleaf-layout-dialect.version}</version>
</dependency>
"""
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class WebjarsModuleFactoryTest {
private static final WebjarsModuleFactory factory = new WebjarsModuleFactory();

@Test
void shouldCreateWebjarsModule() {
void shouldCreateWebjarsLocatorModule() {
JHipsterModuleProperties properties = JHipsterModulesFixture
.propertiesBuilder(TestFileUtils.tmpDirForTest())
.basePackage("com.jhipster.test")
.projectBaseName("myapp")
.build();

JHipsterModule module = factory.buildModule(properties);
JHipsterModule module = factory.buildWebjarsLocatorModule(properties);

assertThatModuleWithFiles(module, pomFile())
.hasFile("pom.xml")
Expand All @@ -32,6 +32,53 @@ void shouldCreateWebjarsModule() {
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>${webjars-locator.version}</version>
</dependency>
"""
);
}

@Test
void shouldCreateHtmxWebjarsModule() {
JHipsterModuleProperties properties = JHipsterModulesFixture
.propertiesBuilder(TestFileUtils.tmpDirForTest())
.basePackage("com.jhipster.test")
.projectBaseName("myapp")
.build();

JHipsterModule module = factory.buildWebjarsHtmxModule(properties);

assertThatModuleWithFiles(module, pomFile())
.hasFile("pom.xml")
.containing(
"""
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>htmx.org</artifactId>
<version>${htmx-webjars.version}</version>
</dependency>
"""
);
}

@Test
void shouldCreateAlpineJSWebjarsModule() {
JHipsterModuleProperties properties = JHipsterModulesFixture
.propertiesBuilder(TestFileUtils.tmpDirForTest())
.basePackage("com.jhipster.test")
.projectBaseName("myapp")
.build();

JHipsterModule module = factory.buildWebjarsAlpineJSModule(properties);

assertThatModuleWithFiles(module, pomFile())
.hasFile("pom.xml")
.containing(
"""
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>alpinejs</artifactId>
<version>${alpinejs-webjars.version}</version>
</dependency>
"""
);
Expand Down
5 changes: 4 additions & 1 deletion tests-ci/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ elif [[ $application == 'thymeleafapp' ]]; then
spring_boot_mvc
sonar_back

applyModules "spring-boot-thymeleaf"
applyModules \
"spring-boot-thymeleaf" \
"webjars-locator" \
"htmx-webjars"

else
echo "*** Unknown configuration..."
Expand Down

0 comments on commit c20e241

Please sign in to comment.