wimdeblauwe / htmx-spring-boot

Spring Boot and Thymeleaf helpers for working with htmx
Apache License 2.0
436 stars 41 forks source link

Add #htmxRequest as an expression utility object #25

Closed checketts closed 1 year ago

checketts commented 2 years ago

See https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#expression-utility-objects

This adds a #htmxRequest object that can be used similar to #request in Thymeleaf templates.

<div id="htmxRequest" th:if="${#htmxRequest.isHtmxRequest()}">It is an htmx Request</div>

This change subclasses the SpringStandardExpressionObjectFactory to extend it. I'm not sure if there is a better extension technique.

wimdeblauwe commented 2 years ago

Sorry I did not have time sooner to look into this. I had a look now and I also looked at Java8TimeExpressionFactory.java. I am wondering why we need to extend from SpringStandardExpressionObjectFactory. Can't we just implement the interface like Java8TimeExpressionFactory does?

There is also a small typo in the class name HtmxSpringStandardExressionObjectFactory -> Exression should be Expression

wimdeblauwe commented 2 years ago

Sorry I did not have time sooner to look into this. I had a look now and I also looked at Java8TimeExpressionFactory.java. I am wondering why we need to extend from SpringStandardExpressionObjectFactory. Can't we just implement the interface like Java8TimeExpressionFactory does?

There is also a small typo in the class name HtmxSpringStandardExressionObjectFactory -> Exression should be Expression

checketts commented 2 years ago

OK I think you are right. I'll try that approach. Thanks for the recommendation.

wimdeblauwe commented 1 year ago

I suppose this can be merged, or is there anything you still want to change?

checketts commented 1 year ago

It can be merged.