jte: Can't have unclosed tags after upgrading to 3.0.1

I have few separate KTE files used as components in other KTE pages. One of them is pair of “cardBegin.kte” and “cardEnd.kte”, which, omitting details, contain something like this:

<div ...>
  <div ...>
    <div ...>

and

    </div>
  </div>
</div>

Now I’m getting error like this from JTE plugin:

Execution failed for task ':my-project:generateJte'.
> There was a failure while executing work items
   > A failure occurred while executing gg.jte.gradle.GenerateJteWorker
      > Failed to compile tag/row/card/cardBegin.kte, error at line 10: Unclosed tag <div>.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 29 (22 by maintainers)

Commits related to this issue

Most upvoted comments

@stella6767 you can do it like this. This way IntelliJ should also not complain about an unclosed form tag.

!{var content = @`
   <div class="px-3 mb-2 mt-2">
            <textarea placeholder="comment" disabled="${!isLogin}"
                      name="content" form="comment-form"
                      class="w-full bg-gray-100 rounded border border-gray-400 leading-normal resize-none h-20 py-2 px-3 font-medium placeholder-gray-700 focus:outline-none focus:bg-white"></textarea>
        </div>
`;}

@if(idAncestor != 0)
<form class="bg-white rounded-lg border p-2 mx-auto "
      id="comment-form"
      hx-post="/comment"
      hx-target="#comment-card-${idAncestor}"
      hx-swap="beforeend"
>
   ${content}
</form>
@else

<form class="bg-white rounded-lg border p-2 mx-auto "
      id="comment-form"
     ...
>
   ${content}
</form>

@endif

Well, I’m not sure because it requires writing a lot of code instead of just markup. Also, I’m not sure about performance (but it’s not important in my case)

@casid thank you, but I’m afraid, I’ve already rewritten all 5 of my xmls to https://github.com/redundent/kotlin-xml-builder, sorry 😦

@stella6767 you can do it like this. This way IntelliJ should also not complain about an unclosed form tag.

!{var content = @`
   <div class="px-3 mb-2 mt-2">
            <textarea placeholder="comment" disabled="${!isLogin}"
                      name="content" form="comment-form"
                      class="w-full bg-gray-100 rounded border border-gray-400 leading-normal resize-none h-20 py-2 px-3 font-medium placeholder-gray-700 focus:outline-none focus:bg-white"></textarea>
        </div>
`;}

@if(idAncestor != 0)
<form class="bg-white rounded-lg border p-2 mx-auto "
      id="comment-form"
      hx-post="/comment"
      hx-target="#comment-card-${idAncestor}"
      hx-swap="beforeend"
>
   ${content}
</form>
@else

<form class="bg-white rounded-lg border p-2 mx-auto "
      id="comment-form"
     ...
>
   ${content}
</form>

@endif

Your solution makes me happy.

@casid well, maybe it should be a separate mode, on par with Plain and Html. And… Why not? It’s basically the same boilerplate we all would prefer not to see 😃

@asm0dey oh wow, I did not expect that jte would be used to generate XML 😃

I’ve adjusted the code, so that declaration tags are not expected to be closed.

Yes, I’m working with IntelliJ plugin.

Out of curiosity, are you working with the jte IntelliJ plugin? I’m quite happy with content block layouts.

content-block

Without the plugin, I agree it to be less readable.

I’d still feel quite nervous about this alternative though 😉

@template.layout.beginPage(page = page)
...
@template.layout.endPage(page = page)

I’m on the If a user has a bad time, it’s a bug side of things

We have this now because the behavior was different before. Given the exception message, I don’t think new users will have a problem here.

Libraries should make doing the correct thing easy and make making mistakes hard.

Unclosed tags always mean you’ll have to touch two files and know which one is the second file. This makes mistakes easy.

Hey @IvanPizhenko,

I can understand your frustration with this change. This feature was part of the major version bump from jte 2 to jte 3. I haven’t anticipated that it would have such an effect, and missed to notice it in the release notes, it was just mentioned in the issue: https://github.com/casid/jte/issues/194. I’ll add this to the release notes, with a hint how to migrate. I’ll also add a hint to the compile error, pointing to gg.jte.Content.

However, we did this change because we believe this will result in much cleaner templates, that will be better to maintain in the long run. Not only will this read better in IntelliJ, also users of such templates won’t be able to forget a closing template anymore.

For instance your example could be written as card.kte:

@import gg.jte.Content

@param Content content

<div ...>
  <div ...>
    <div ...>
       ${content}
    </div>
  </div>
</div>

If you don’t want to migrate right away, it is perfectly fine to stay on jte 2 until you are ready for the change. And maybe give gg.jte.Content a try for new templates. I’m very sure you’re gonna like it as much as we do!