Skip to content

Commit

Permalink
update release.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Schuehly committed Aug 27, 2023
1 parent 143a25e commit a1c5176
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 119 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,12 @@ jobs:
./gradlew :core:publishToMavenLocal
./gradlew :thymeleaf:publishToMavenLocal
./gradlew :jte:publishToMavenLocal
test-kotlin:
needs:
setup-test
runs-on: ubuntu-latest
steps:
- name: run thymeleaf kotlin tests
run: |
cd ./examples/thymeleaf-kotlin-example
chmod +x ./gradlew
./gradlew test
test-java:
needs:
setup-test
runs-on: ubuntu-latest
steps:
- name: run thymeleaf kotlin tests
- name: run thymeleaf java tests
run: |
cd ./examples/thymeleaf-java-example
chmod +x ./mavenw
Expand Down
150 changes: 48 additions & 102 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,16 @@ class Router(
}
```

## ViewAction: Interactivity with HTMX

With ViewActions you can create interactive ViewComponents based on [htmx](https://htmx.org/) without having to reload the page.
## Local Development

ViewAction integration needs to enable in your application.properties:
```
spring.view-component.view-action.enabled=true
You can enable hot-reloading of the templates in development:
```properties
spring.view-component.local-development=true
```

Here you can see a ViewComponent with a ViewAction that increments a counter.
## ViewAction: Interactivity with HTMX

With ViewActions you can create interactive ViewComponents based on [htmx](https://htmx.org/) without having to reload the page.

You define a ViewAction inside your HTML template with the `view:action` attribute.
A ViewAction enabled ViewComponent always needs to have one root element.
Expand Down Expand Up @@ -293,22 +293,22 @@ The hx-get attribute will create a http get request to the `/actionviewcomponent

The `/actionviewcomponent/countup` endpoint will return the re-rendered ActionViewComponent template.

The `hx-target="#actionviewcomponent"` and the `hx-swap="outerHTML"` attributes will then swap the returned HTML to the div with the `id="actionviewcomponent"` that is automatically added to the root div.
The `hx-target="#actionviewcomponent"` attribute will swap the returned HTML to the div with the `id="actionviewcomponent"` that is automatically added to the root div.


```html
<div id="actionviewcomponent">
<script defer src="https://unpkg.com/[email protected]"></script>
<h2>ViewAction Get CountUp</h2>
<button hx-get="/actionviewcomponent/countup" hx-target="#actionviewcomponent" hx-swap="outerHTML">
<button hx-get="/actionviewcomponent/countup" hx-target="#actionviewcomponent">
Default ViewAction [GET]
</button>
</div>
```

You can also pass a custom path as annotation parameter: `@PostViewAction("/customPath/addItemAction")`

You can use different ViewAction Annotations that map to the corresponding htmx ajax methods: https://htmx.org/docs/#ajax
You can use different ViewAction Annotations that map to the corresponding [htmx ajax methods](https://htmx.org/docs/#ajax):

- `@GetViewAction`
- `@PostViewAction`
Expand Down Expand Up @@ -401,32 +401,7 @@ class HomeViewComponent(
)
}
```
## Gradle Installation

Add this snippet to your build.gradle.kts:
```kotlin
// build.gradle.kts
tasks.withType<Jar>{
from(sourceSets.main.get().output.resourcesDir)
}

sourceSets {
test {
resources {
srcDir("src/test/kotlin")
exclude("**/*.kt")
}
}
main {
resources {
srcDir("src/main/kotlin")
exclude("**/*.kt")
}
}

}

```
### Thymeleaf Dependency

[LATEST_VERSION](https://central.sonatype.com/artifact/de.tschuehly/spring-view-component-thymeleaf) on Maven Central
Expand All @@ -435,6 +410,7 @@ sourceSets {
// build.gradle.kts
dependencies {
implementation("de.tschuehly:spring-view-component-thymeleaf:LATEST_VERSION")
kapt("de.tschuehly:spring-view-component-core:LATEST_VERSION")
}
```
### JTE Dependency
Expand Down Expand Up @@ -463,16 +439,12 @@ dependencies {
// HomeViewComponent.java
@ViewComponent
public class HomeViewComponent {
private final ExampleService exampleService;

public HomeViewComponent(ExampleService exampleService) {
this.exampleService = exampleService;
}

@Autowired
private ExampleService exampleService;

public ViewContext render() {
return new ViewContext(
ViewProperty.of("helloWorld", "Hello World"),
ViewProperty.of("coffee", exampleService.getCoffee())
return ViewContext.of(
ViewProperty.of("helloWorld", "Hello World")
);
}
}
Expand All @@ -484,11 +456,8 @@ public class HomeViewComponent {
// Router.java
@Controller
public class Router {
private final HomeViewComponent homeViewComponent;

public Router(HomeViewComponent homeViewComponent) {
this.HomeViewComponent = homeViewComponent;
}
@Autowired
private HomeViewComponent homeViewComponent;

@GetMapping("/")
ViewContext homeView() {
Expand All @@ -500,37 +469,30 @@ public class Router {
## Parameter components with Java

```java

@ViewComponent
public class ParameterViewComponent {
public ViewContext render(String parameter) throws Exception {
if (parameter == null) {
throw new Exception("You need to pass in a parameter");
}
return new ViewContext(
return ViewContext.of(
ViewProperty.of("office", parameter)
);
}
}

```


```java
// HomeViewComponent.java
@ViewComponent
public class HomeViewComponent {
private final ExampleService exampleService;

public HomeViewComponent(ExampleService exampleService) {
this.exampleService = exampleService;
}
@Autowired
private ExampleService exampleService;

public ViewContext render() {
return new ViewContext(
ViewProperty.of("helloWorld", "Hello World"),
ViewProperty.of("coffee", exampleService.getCoffee()),
ViewProperty.of("office", exampleService.getOfficeHours())
return ViewContext.of(
ViewProperty.of("helloWorld", "Hello World")
);
}
}
Expand All @@ -543,17 +505,14 @@ public class HomeViewComponent {
// Router.java
@Controller
public class Router {
private final NavigationViewComponent navigationViewComponent;
private final TableViewComponent tableViewComponent;

public Router(NavigationViewComponent navigationViewComponent, TableViewComponent tableViewComponent) {
this.navigationViewComponent = navigationViewComponent;
this.tableViewComponent = tableViewComponent;
}

@Autowired
private NavigationViewComponent navigationViewComponent;
@Autowired
private TableViewComponent tableViewComponent;

@GetMapping("/multi-component")
ViewContextContainer multipleComponent() {
return new ViewContextContainer(
return ViewContextContainer.of(
this.navigationViewComponent.render(),
this.tableViewComponent.render()
);
Expand All @@ -567,18 +526,13 @@ public class Router {
// HomeViewComponent.java
@ViewComponent
public class HomeViewComponent implements Supplier<ViewContext> {
private final ExampleService exampleService;

public HomeViewComponent(ExampleService exampleService) {
this.exampleService = exampleService;
}
@Autowired
private ExampleService exampleService;

@Override
public ViewContext get() {
return new ViewContext(
ViewProperty.of("helloWorld", "Hello World"),
ViewProperty.of("coffee", exampleService.getCoffee()),
ViewProperty.of("office", exampleService.getOfficeHours())
return ViewContext.of(
ViewProperty.of("helloWorld", "Hello World")
);
}
}
Expand All @@ -592,19 +546,22 @@ Add this to your pom.xml:

<project>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.html</include>
<include>**/*.jte</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>5
<version>3.3.0</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>17</source>
<target>17</target>
<annotationProcessorPaths>
<path>
<groupId>de.tschuehly</groupId>
<artifactId>spring-view-component-core</artifactId>
<version>${de.tschuehly.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
Expand All @@ -631,15 +588,4 @@ Add this to your pom.xml:
<artifactId>spring-view-component-jte</artifactId>
<version>LATEST_VERSION</version>
</dependency>
```

# General Configuration


## Local Development

To enable live reload of the components on each save without rebuilding the application add this configuration:

```properties
spring.view-component.localDevelopment=true
```
```
1 change: 0 additions & 1 deletion examples/thymeleaf-java-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
</annotationProcessorPaths>
</configuration>
</plugin>

</plugins>
</build>

Expand Down
5 changes: 1 addition & 4 deletions examples/thymeleaf-kotlin-example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
Expand Down Expand Up @@ -54,7 +52,6 @@ tasks.withType<KotlinCompile> {
tasks.withType<Test> {
useJUnitPlatform()
testLogging {
events("passed","skipped","failed")
events("passed", "skipped", "failed")
}

}

0 comments on commit a1c5176

Please sign in to comment.