Skip to content

Commit

Permalink
Merge branch 'master' into loomClient
Browse files Browse the repository at this point in the history
  • Loading branch information
SentryMan authored Sep 6, 2024
2 parents 68f54a1 + 9a6cad8 commit b2260f0
Show file tree
Hide file tree
Showing 88 changed files with 1,566 additions and 200 deletions.
7 changes: 5 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ updates:
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "weekly"
interval: weekly
open-pull-requests-limit: 10
groups:
dependencies:
patterns:
- "*"
labels:
- "dependencies"
target-branch: "master"


- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/jdk-ea-stable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

name: JDK EA Stable

on:
push:
pull_request:
workflow_dispatch:
schedule:
- cron: '39 1 * * 1,3,5'

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
- name: Set up Java
uses: oracle-actions/setup-java@v1
with:
website: jdk.java.net
release: ea
version: stable
- name: Maven cache
uses: actions/cache@v4
env:
cache-name: maven-cache
with:
path:
~/.m2
key: build-${{ env.cache-name }}
- name: Maven version
run: mvn --version
- name: Build with Maven
run: mvn clean verify package -Ptest
1 change: 1 addition & 0 deletions .github/workflows/jdk-ea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name: avaje-http EA

on:
pull_request:
workflow_dispatch:
schedule:
- cron: '39 1 * * 2,5'
Expand Down
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,13 @@ Use source code generation to adapt annotated REST controllers `@Path, @Get, @Po
</dependency>
```

### JDK 22+
### JDK 23+

In JDK 22+, annotation processors are disabled by default, you will need to add a flag to re-enable.
In JDK 23+, annotation processors are disabled by default, you will need to add a flag to re-enable.
```xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-proc:full</compilerArgument>
</configuration>
</plugin>
<properties>
<maven.compiler.proc>full</maven.compiler.proc>
</properties>
```

## Define a Controller (These APT processors work with both Java and Kotlin)
Expand Down
25 changes: 25 additions & 0 deletions htmx-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.avaje</groupId>
<artifactId>avaje-http-parent</artifactId>
<version>2.8-RC1</version>
</parent>

<artifactId>avaje-htmx-api</artifactId>

<properties>
</properties>

<dependencies>
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-lang</artifactId>
<version>1.1</version>
</dependency>
</dependencies>

</project>
16 changes: 16 additions & 0 deletions htmx-api/src/main/java/io/avaje/htmx/api/ContentCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.avaje.htmx.api;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Mark a controller method as using a content cache.
*/
@Target(METHOD)
@Retention(RUNTIME)
public @interface ContentCache {

}
141 changes: 141 additions & 0 deletions htmx-api/src/main/java/io/avaje/htmx/api/DHxRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package io.avaje.htmx.api;

import io.avaje.lang.Nullable;

final class DHxRequest implements HtmxRequest {

private final boolean htmxRequest;

private final boolean boosted;
private final String currentUrl;
private final boolean historyRestoreRequest;
private final String promptResponse;
private final String target;
private final String triggerName;
private final String triggerId;

DHxRequest() {
this.htmxRequest = false;
this.boosted = false;
this.currentUrl = null;
this.historyRestoreRequest = false;
this.promptResponse = null;
this.target = null;
this.triggerName = null;
this.triggerId = null;
}

DHxRequest(boolean boosted, String currentUrl, boolean historyRestoreRequest, String promptResponse, String target, String triggerName, String triggerId) {
this.htmxRequest = true;
this.boosted = boosted;
this.currentUrl = currentUrl;
this.historyRestoreRequest = historyRestoreRequest;
this.promptResponse = promptResponse;
this.target = target;
this.triggerName = triggerName;
this.triggerId = triggerId;
}

@Override
public boolean isHtmxRequest() {
return htmxRequest;
}

@Override
public boolean isBoosted() {
return boosted;
}

@Nullable
@Override
public String currentUrl() {
return currentUrl;
}

@Override
public boolean isHistoryRestoreRequest() {
return historyRestoreRequest;
}

@Nullable
@Override
public String promptResponse() {
return promptResponse;
}

@Nullable
@Override
public String target() {
return target;
}

@Nullable
@Override
public String triggerName() {
return triggerName;
}

@Nullable
public String triggerId() {
return triggerId;
}

static final class DBuilder implements Builder {

private boolean boosted;
private String currentUrl;
private boolean historyRestoreRequest;
private String promptResponse;
private String target;
private String triggerName;
private String triggerId;

@Override
public DBuilder boosted(boolean boosted) {
this.boosted = boosted;
return this;
}

@Override
public DBuilder currentUrl(String currentUrl) {
this.currentUrl = currentUrl;
return this;
}

@Override
public DBuilder historyRestoreRequest(boolean historyRestoreRequest) {
this.historyRestoreRequest = historyRestoreRequest;
return this;
}

@Override
public DBuilder promptResponse(String promptResponse) {
this.promptResponse = promptResponse;
return this;
}

@Override
public DBuilder target(String target) {
this.target = target;
return this;
}

@Override
public DBuilder triggerName(String triggerName) {
this.triggerName = triggerName;
return this;
}

@Override
public DBuilder triggerId(String triggerId) {
this.triggerId = triggerId;
return this;
}

@Override
public HtmxRequest build() {
return new DHxRequest(boosted, currentUrl, historyRestoreRequest, promptResponse, target, triggerName, triggerId);
}
}

}
18 changes: 18 additions & 0 deletions htmx-api/src/main/java/io/avaje/htmx/api/Html.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.avaje.htmx.api;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Mark a controller as producing HTML by default and using "Templating"
* meaning that response objects are expected to a "Model View" passed to
* the "Templating" library.
*/
@Target(TYPE)
@Retention(RUNTIME)
public @interface Html {

}
106 changes: 106 additions & 0 deletions htmx-api/src/main/java/io/avaje/htmx/api/HtmxRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package io.avaje.htmx.api;

import io.avaje.lang.Nullable;

/**
* This class can be used as a controller method argument to access
* the <a href="https://htmx.org/reference/#request_headers">htmx Request Headers</a>.
*
* <pre>{@code
*
* @HxRequest
* @Get("/users")
* String users(HtmxRequest htmxRequest) {
* if (htmxRequest.isBoosted()) {
* ...
* }
* }
*
* }</pre>
*
* @see <a href="https://htmx.org/reference/#request_headers">Request Headers Reference</a>
*/
public interface HtmxRequest {

/**
* Represents a non-Htmx request.
*/
HtmxRequest EMPTY = new DHxRequest();

/**
* Return a new builder for the HtmxRequest.
*/
static Builder builder() {
return new DHxRequest.DBuilder();
}

/**
* Return true if this is an Htmx request.
*/
boolean isHtmxRequest();

/**
* Indicates that the request is via an element using hx-boost.
*
* @return true if the request was made via HX-Boost, false otherwise
*/
boolean isBoosted();

/**
* Return the current URL of the browser when the htmx request was made.
*/
@Nullable
String currentUrl();

/**
* Indicates if the request is for history restoration after a miss in the local history cache
*
* @return true if this request is for history restoration, false otherwise
*/
boolean isHistoryRestoreRequest();

/**
* Return the user response to an HX-Prompt.
*/
@Nullable
String promptResponse();

/**
* Return the id of the target element if it exists.
*/
@Nullable
String target();

/**
* Return the name of the triggered element if it exists.
*/
@Nullable
String triggerName();

/**
* Return the id of the triggered element if it exists.
*/
@Nullable
String triggerId();

/**
* Builder for {@link HtmxRequest}.
*/
interface Builder {
Builder boosted(boolean boosted);

Builder currentUrl(String currentUrl);

Builder historyRestoreRequest(boolean historyRestoreRequest);

Builder promptResponse(String promptResponse);

Builder target(String target);

Builder triggerName(String triggerName);

Builder triggerId(String triggerId);

HtmxRequest build();
}
}
Loading

0 comments on commit b2260f0

Please sign in to comment.