Comments (11)
Hi, I've only briefly looked into Qute so far and that was half a year ago.
But I think the key differences are:
- jte has no own expression language you have to learn, it's just Java.
- Thus you get almost everything you have in IntelliJ for Java for jte templates as well, if you use the jte plugin.
- jte analyzes the HTML you're building at compile time and does context-sensitive output escaping for you automatically.
You can easily call your own extensions by calling Java code :-) For instance, I usually have some kind of ViewContext
that I call from templates for localizing stuff. This way you can reuse the same localization logic you use in other parts of the application.
Something like this:
@import static my.ViewContext.*
<p>
${localize("my.key")}
</p>
public final class ViewContext {
public static gg.jte.Content localize(String key) {
// access request context via thread local and localize...
}
}
The cool thing about that is that there's no magic, just code. And IntelliJ can resolve all those references, if you want to know what's happening. Just ctrl+click on that localize method and you're instantly there. Other template engines have a lot more magic involved there and it's a lot harder to find out what's really going on.
Of course you can pass such a context as template parameters as well, that's up to your taste. Personally I find the static helper method quite productive ;-)
I don't know ERB, but I think this should be done quite easily. For such stuff the gg.jte.Content interface is pretty awesome :-)
Also, I'm following hotwire and htmx with great interest! I think they should work great together with jte. It's still on my todo list to make a demo like you linked, but haven't found the time so far.
Also, thanks for your interest in jte and asking all those questions!
from jte.
Hey awesome explanation had no idea it was that easy and was just a static method call away to format anything I want super neat. I guess for the example for a nicely formatted date time I can just create a static method and return jte.gg.Content ? Will need to see what that holds in the docs.
Would love to see the htmx or hotwire integration also! Following them super closely at the moment also, seems like a perfect stack with jte too!!
What do you mean by title 'automatically be escaped as HTML attribute, not just get a generic HTML output escaping.' what is the difference? Also for the example of Just seen docs exactly as I thought, awesome.value="${update ? todo.title : null}"
if null gets hit does 'value=null'
show up in the HTML result?
Thanks for fielding these questions will have to dive deeper into jte :)
from jte.
Also can I say how amazing the speed of https://mazebert.com/ is, I'm getting responses in less that 45ms on some pages from the UK, crazy when you come from a Ruby landscape.
Can you share any tricks you are using or do you have any caching in place? Super interested on how you are doing the https://mazebert.com/stats/ page, it has content that is frequently updated minutes ago.
from jte.
Thanks! Most pages on https://mazebert.com/ are statically rendered to files at startup and served by nginx. There's a scheduled thread pool executor that periodically checks / renders pages like /stats:
executorService = Executors.newScheduledThreadPool(1);
executorService.scheduleWithFixedDelay(this::refreshStats, 5L, 5L, TimeUnit.MINUTES);
executorService.scheduleWithFixedDelay(this::refreshSeasonPages, 1L, 1L, TimeUnit.SECONDS);
And there are a few pages that are not pre-rendered, because there are so many of them, like the player page:
https://mazebert.com/player/115/
from jte.
gg.jte.Content
is an interface you can use if you want to programmatically do template output. If you'd use String
for that, you'd need to do the output with $unsafe{myCachedContent()}
, which is pretty ugly and error prone.
For instance, the built-in localization support preserves all HTML tags from localization keys but still escapes all user provided parameters. Maybe that's a good starting point.
from jte.
I had a look at the qute example project you posted.
Here's a good example about what I meant that jte understands HTML:
<input type="text" name="title" class="form-control" id="title" placeholder="Title" required {#if update}value="{todo.title}"{/if}>
<input type="checkbox" name="completed" class="form-check-input" id="completed" {#if update}{#if todo.completed}checked{/if}{/if}>
Especially when you have more than just one attribute, this becomes very ugly. In jte you can simply write this for the same result:
<input type="text" name="title" class="form-control" id="title" placeholder="Title" required value="${update ? todo.title : null}">
<input type="checkbox" name="completed" class="form-check-input" id="completed" checked="${update && todo.completed}">
Since checked is a boolean attribute, jte even fails compilation if you don't provide a boolean expression for it :-)
Also, the output for todo.title will automatically be escaped as HTML attribute, not just get a generic HTML output escaping.
from jte.
@rosscarlisle did you manage to make jte
work with Quarkus? Could you share the example?
from jte.
@renannprado I think Quarkus uses vert.x under the hood. Maybe this is a starting point for the integration?
https://github.com/vert-x3/vertx-web/tree/master/vertx-template-engines/vertx-web-templ-jte
from jte.
@casid quarkus AFAIK uses Undertow under the hood, but not vertx, so I'm not sure if it will help, but I'll have a look. Thanks!
Edit: TIL that quarkus is based on vertx. :)
from jte.
@renannprado Apologies, but not got around trying to integrate it yet.
from jte.
@casid @rosscarlisle I've created issue #61 issue to track the Quarkus integration as this was not really the purpose of this issue.
from jte.
Related Issues (20)
- For Loops won't compile for Kotlin HOT 2
- internationalization with MessageFormat HOT 6
- HTML Comments Inside Content Blocks Cause Compilation Failure in gg.jte.gradle v3.1.7+ HOT 2
- Allow expressions in HTML attribute names for certain types HOT 9
- Spring Boot integration and binary rendering HOT 6
- ${"\\"} Causes "Unexpected end of template expression" HOT 1
- Pass dynamic HTML Content to template HOT 2
- Support JTE project HOT 2
- Failed to compile with module-info.java HOT 2
- Support for read-only filesystem HOT 1
- template define with generic type HOT 1
- Generic template HOT 3
- Html Template Output HOT 2
- Add kotlin and kte documentation HOT 1
- String input instead of file input HOT 6
- Provide jte-jsp-converter for Jakarta HOT 1
- Comments break JTE HOT 5
- intellij "Cannot resolve MVC view" HOT 4
- Unable to handle model properties that contain dots (`.`) HOT 3
- KTE runtime dependencies HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jte.