-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from xhaggi/missing-response-header-annotatio…
…n-support Add missing annotations for response headers
- Loading branch information
Showing
17 changed files
with
747 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.github.wimdeblauwe.htmx.spring.boot.mvc; | ||
|
||
/** | ||
* Holder for constant values. | ||
*/ | ||
public class HtmxValue { | ||
|
||
/** | ||
* Constant for use in annotations that support a {@code false} value to disable functions. | ||
*/ | ||
public static final String FALSE = "false"; | ||
|
||
/** | ||
* Constant for use in annotations that support a {@code true} value to enable functions. | ||
*/ | ||
public static final String TRUE = "true"; | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxLocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package io.github.wimdeblauwe.htmx.spring.boot.mvc; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.springframework.core.annotation.AliasFor; | ||
|
||
/** | ||
* Annotation to do a client side redirect that does not do a full page reload. | ||
* <p> | ||
* Note that this annotation does not provide support for specifying {@code values} or {@code headers}. | ||
* If you want to do this, use {@link HtmxResponse} instead. | ||
* | ||
* @see <a href="https://htmx.org/headers/hx-location/">HX-Location Response Header</a> | ||
*/ | ||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface HxLocation { | ||
|
||
/** | ||
* The url path to make the redirect. | ||
* <p>This is an alias for {@link #path}. For example, | ||
* {@code @HxLocation("/foo")} is equivalent to | ||
* {@code @HxLocation(path="/foo")}. | ||
*/ | ||
@AliasFor("path") | ||
String value() default ""; | ||
/** | ||
* The url path to make the redirect. | ||
*/ | ||
String path() default ""; | ||
/** | ||
* The source element of the request | ||
*/ | ||
String source() default ""; | ||
/** | ||
* An event that "triggered" the request | ||
*/ | ||
String event() default ""; | ||
/** | ||
* A callback that will handle the response HTML. | ||
*/ | ||
String handler() default ""; | ||
/** | ||
* The target to swap the response into. | ||
*/ | ||
String target() default ""; | ||
/** | ||
* How the response will be swapped in relative to the target | ||
*/ | ||
String swap() default ""; | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxPushUrl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.github.wimdeblauwe.htmx.spring.boot.mvc; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation to push a URL into the browser | ||
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/History_API">location history</a>. | ||
* <p> | ||
* The possible values are: | ||
* <ul> | ||
* <li>{@link HtmxValue#TRUE}, which pushes the fetched URL into history.</li> | ||
* <li>{@link HtmxValue#FALSE}, which disables pushing the fetched URL if it would otherwise be pushed.</li> | ||
* <li>A URL to be pushed into the location bar. This may be relative or absolute, | ||
* as per <a href="https://developer.mozilla.org/en-US/docs/Web/API/History/pushState">history.pushState()</a>.</li> | ||
* </ul> | ||
* | ||
* @see <a href="https://htmx.org/headers/hx-push-url/">HX-Push-Url Response Header</a> | ||
*/ | ||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface HxPushUrl { | ||
|
||
/** | ||
* The value for the {@code HX-Push-Url} response header. | ||
*/ | ||
String value() default HtmxValue.TRUE; | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxRedirect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.github.wimdeblauwe.htmx.spring.boot.mvc; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation to do a client-side redirect to a new location. | ||
* | ||
* @see <a href="https://htmx.org/reference/#response_headers">HX-Redirect</a> | ||
*/ | ||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface HxRedirect { | ||
|
||
/** | ||
* The URL to use to do a client-side redirect to a new location. | ||
*/ | ||
String value(); | ||
|
||
} |
Oops, something went wrong.