Skip to content

Commit

Permalink
Add htmx dependency
Browse files Browse the repository at this point in the history
Closes gh-1549
  • Loading branch information
mhalbritter committed Aug 20, 2024
1 parent 9164f41 commit df8b128
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.start.site.extension.dependency.htmx;

import io.spring.initializr.generator.buildsystem.Build;
import io.spring.initializr.generator.buildsystem.Dependency;
import io.spring.initializr.generator.spring.build.BuildCustomizer;

/**
* A {@link BuildCustomizer} that replaces {@code htmx-spring-boot} with
* {@code htmx-spring-boot-thymeleaf} if Thymeleaf is selected.
*
* @author Moritz Halbritter
*/
class HtmxBuildCustomizer implements BuildCustomizer<Build> {

@Override
public void customize(Build build) {
if (build.dependencies().has("thymeleaf")) {
Dependency htmx = build.dependencies().get("htmx");
build.dependencies().remove("htmx");
build.dependencies()
.add("htmx-thymeleaf",
Dependency.withCoordinates(htmx.getGroupId(), "htmx-spring-boot-thymeleaf")
.version(htmx.getVersion())
.build());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.start.site.extension.dependency.htmx;

import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configuration for generation of projects that depend on htmx.
*
* @author Moritz Halbritter
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnRequestedDependency("htmx")
class HtmxProjectGenerationConfiguration {

@Bean
HtmxBuildCustomizer htmxBuildCustomizer() {
return new HtmxBuildCustomizer();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Extensions for generation of projects that depend on htmx.
*/
package io.spring.start.site.extension.dependency.htmx;
1 change: 1 addition & 0 deletions start-site/src/main/resources/META-INF/spring.factories
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ io.spring.start.site.extension.dependency.elasticsearch.ElasticsearchProjectGene
io.spring.start.site.extension.dependency.flyway.FlywayProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.graalvm.GraalVmProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.graphql.SpringGraphQlProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.htmx.HtmxProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.mariadb.MariaDbProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.mongodb.MongoDbProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.mysql.MysqlProjectGenerationConfiguration,\
Expand Down
15 changes: 15 additions & 0 deletions start-site/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,21 @@ initializr:
links:
- rel: reference
href: https://netflix.github.io/dgs/
- name: htmx
id: htmx
facets:
- web
starter: false
groupId: io.github.wimdeblauwe
artifactId: htmx-spring-boot
description: Build modern user interfaces with the simplicity and power of hypertext.
compatibilityRange: "[3.2.0,3.4.0-M1)"
version: 3.4.1
links:
- rel: reference
href: https://github.com/wimdeblauwe/htmx-spring-boot
- rel: guide
href: https://www.youtube.com/watch?v=j-rfPoXe5aE
- name: Template Engines
content:
- name: Thymeleaf
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.start.site.extension.dependency.htmx;

import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link HtmxBuildCustomizer}.
*
* @author Moritz Halbritter
*/
class HtmxBuildCustomizerTests extends AbstractExtensionTests {

private final Dependency htmx = Dependency.withId("htmx", "io.github.wimdeblauwe", "htmx-spring-boot");

private final Dependency htmxThymeleaf = Dependency.withId("htmx", "io.github.wimdeblauwe",
"htmx-spring-boot-thymeleaf");

@Test
void shouldUseHtmxThymleafIfThymeleafIsSelected() {
ProjectRequest request = createProjectRequest("htmx", "thymeleaf");
assertThat(mavenPom(request)).doesNotHaveDependency(this.htmx.getGroupId(), this.htmx.getArtifactId())
.hasDependency(this.htmxThymeleaf);
}

@Test
void shouldUsePlainHtmxIfThymeleafIsNotSelected() {
ProjectRequest request = createProjectRequest("htmx");
assertThat(mavenPom(request))
.doesNotHaveDependency(this.htmxThymeleaf.getGroupId(), this.htmxThymeleaf.getArtifactId())
.hasDependency(this.htmx);
}

@Test
void shouldNotAddHtmx() {
ProjectRequest request = createProjectRequest("web");
assertThat(mavenPom(request)).doesNotHaveDependency(this.htmx.getGroupId(), this.htmx.getArtifactId())
.doesNotHaveDependency(this.htmxThymeleaf.getGroupId(), this.htmxThymeleaf.getArtifactId());
}

}

0 comments on commit df8b128

Please sign in to comment.