Code Monkey home page Code Monkey logo

Comments (9)

casid avatar casid commented on August 15, 2024

Sounds complicated to me.

If I recall correctly there has been a similiar issue: #256 Maybe one of the solutions there would help?

from jte.

tschuehly avatar tschuehly commented on August 15, 2024

Ok, thanks for the pointer.
Will take a look next week!

from jte.

tschuehly avatar tschuehly commented on August 15, 2024

Hey @casid.

Finally got some time to try it out. I tried it out both with $unsafe and the custom Policy, but it does not behave like I would expect it

public static final String htmx = "hx-get=/helloWorld hx-swap=outerHTML";

This HTML:
<div ${htmx} >
is rendered to this:

this:
<div ${htmx} = "" >
is rendered to
<div hx-get="/helloWorld" hx-swap="outerHTML" =="" ""=""></div>

What do you think?

from jte.

casid avatar casid commented on August 15, 2024

Ugh, that's indeed unexpected!

Problem is, that $unsafe{htmx} / ${htmx} is parsed as attribute name and thus not evaluated by jte.

I've pushed a fix for this, could you have a try if this improves for you with the latest snapshot version?

from jte.

tschuehly avatar tschuehly commented on August 15, 2024

What is the maven Repository URL for snapshots?
I tried https://s01.oss.sonatype.org/content/repositories/snapshots/ but it didn't find it.

from jte.

casid avatar casid commented on August 15, 2024

@tschuehly you can give it a try via jitpack: https://jitpack.io/#casid/jte/-SNAPSHOT

from jte.

tschuehly avatar tschuehly commented on August 15, 2024

@casid
Works with the SNAPSHOT!

from jte.

checketts avatar checketts commented on August 15, 2024

@tschuehly I'm also interested in creating a helper for htmx attributes. Do you have an example of what is working for you?

My goal is to make something like this work:

@param hx: HtmxHelper

<div ${hx.get(url="/my/url/"+item.id, swap="outerHTML", target="someId")}>Click me</div>

That would generate:

<div hx-get="/my/url/123" hx-swap="outerHTML" hx-target="someId">Click me</div>

My helper would handle the escaping if $unsafe were needed.

from jte.

tschuehly avatar tschuehly commented on August 15, 2024

@checketts
Here I have an example of a config that works: tschuehly/htmx-spring-workshop@731c0f3

I'm not really sure how to approach this the best. I really come to like using static public final variables to make it easy to see what controller endpoint htmx is calling:

<button hx-get="${URI(GET_EDIT_USER_MODAL,uuid)}"
               hx-target="#${MODAL_CONTAINER_ID}">
          <img src="/edit.svg">
</button>
  public static final String GET_EDIT_USER_MODAL = "/save-user/modal/{uuid}";

  @GetMapping(GET_EDIT_USER_MODAL)
  public ViewContext editUserModal(@PathVariable UUID uuid) {
    return editUserComponent.render(uuid);
 }

UserRowComponent

For the templates you could create a HTMX object that is then stringified to htmx attributes.
In a Spring specific context I'm thinking of maybe creating a RequestMapping annotation that takes that HTMX object and creates a mapping. This way you still have the easy navigation where it is used.

maybe interesting to you aswell:
HtmxUtil.java

from jte.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.