Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
tschuehly committed Aug 31, 2023
1 parent 4f7dcd9 commit d448d89
Show file tree
Hide file tree
Showing 151 changed files with 2,306 additions and 1,429 deletions.
39 changes: 33 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,40 @@ name: Publish package to the Maven Central Repository
on:
push:
branches:
- '**-snapshot'
- '**-SNAPSHOT'
tags:
- v*
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
- name: publish local
run: |
./gradlew :core:publishToMavenLocal
./gradlew :thymeleaf:publishToMavenLocal
./gradlew :jte:publishToMavenLocal
- name: run thymeleaf kotlin tests
run: |
cd ./examples/thymeleaf-kotlin-example
chmod +x ./gradlew
./gradlew test
- name: run thymeleaf java tests
run: |
cd ./examples/thymeleaf-java-example
chmod +x ./mvnw
./mvnw test
publish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -20,7 +47,7 @@ jobs:
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
- name: Publish thymeleaf package to staging
run: ./gradlew :thymeleaf:publish --stacktrace
run: ./gradlew :thymeleaf:publish
- name: Publish thymeleaf package to maven central
env:
JRELEASER_NEXUS2_USERNAME: ${{ secrets.JRELEASER_NEXUS2_USERNAME }}
Expand All @@ -29,9 +56,9 @@ jobs:
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew :thymeleaf:jreleaserDeploy -DaltDeploymentRepository=local::file:./thymeleaf/build/staging-deploy --stacktrace
run: ./gradlew :thymeleaf:jreleaserDeploy -DaltDeploymentRepository=local::file:./thymeleaf/build/staging-deploy
- name: Publish jte package to staging
run: ./gradlew :jte:publish --stacktrace
run: ./gradlew :jte:publish
- name: Publish jte package to maven central
env:
JRELEASER_NEXUS2_USERNAME: ${{ secrets.JRELEASER_NEXUS2_USERNAME }}
Expand All @@ -40,7 +67,7 @@ jobs:
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew :jte:jreleaserDeploy -DaltDeploymentRepository=local::file:./jte/build/staging-deploy --stacktrace
run: ./gradlew :jte:jreleaserDeploy -DaltDeploymentRepository=local::file:./jte/build/staging-deploy
- name: Publish core package to staging
run: ./gradlew :core:publish
- name: Publish core package to maven central
Expand All @@ -51,4 +78,4 @@ jobs:
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew :core:jreleaserDeploy -DaltDeploymentRepository=local::file:./core/build/staging-deploy --stacktrace
run: ./gradlew :core:jreleaserDeploy -DaltDeploymentRepository=local::file:./core/build/staging-deploy --stacktrace
146 changes: 48 additions & 98 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,28 +401,7 @@ class HomeViewComponent(
)
}
```
## Gradle Installation

Add this snippet to your build.gradle.kts:
```kotlin
// build.gradle.kts
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 @@ -431,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 @@ -459,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 @@ -480,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 @@ -496,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 @@ -539,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 @@ -563,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 @@ -588,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 @@ -627,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
```
```
7 changes: 4 additions & 3 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jreleaser.model.Active

plugins {
id("org.springframework.boot") version "3.1.0"
id("io.spring.dependency-management") version "1.1.0"
id("org.springframework.boot") version "3.1.2"
id("io.spring.dependency-management") version "1.1.2"
kotlin("jvm") version "1.8.21"
kotlin("plugin.spring") version "1.8.21"

Expand All @@ -13,7 +13,7 @@ plugins {
}

group = "de.tschuehly"
version = "0.6.0"
version = "0.6.2-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
Expand All @@ -28,6 +28,7 @@ dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("it.skrape:skrapeit-html-parser:1.2.2")
testImplementation("org.springframework.boot:spring-boot-starter-test")
implementation("org.jsoup:jsoup:1.16.1")
}
Expand Down
2 changes: 1 addition & 1 deletion core/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = "spring-view-component-core"
rootProject.name = "spring-view-component-core"
Loading

0 comments on commit d448d89

Please sign in to comment.