Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qute standalone - format functions for java.time.ZonedDateTime #19555

Closed
maxandersen opened this issue Aug 20, 2021 · 10 comments
Closed

Qute standalone - format functions for java.time.ZonedDateTime #19555

maxandersen opened this issue Aug 20, 2021 · 10 comments
Labels
area/qute The template engine kind/enhancement New feature or request

Comments

@maxandersen
Copy link
Member

Description

docs at https://quarkus.io/guides/qute-reference#built-in-template-extension says format exits for ZonedDateTime but when calling it i get:

Exception in thread "main" io.quarkus.qute.TemplateException: Method "format('d MMM uuuu')" not found on the base object "java.time.ZonedDateTime" in expression {post.pubDateZonedDateTime.get().format('d MMM uuuu')} in template 1 on line 23

note: i'm using qute standalone if that matters

Implementation ideas

No response

@maxandersen maxandersen added the kind/enhancement New feature or request label Aug 20, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Aug 20, 2021

/cc @mkouba

@quarkus-bot quarkus-bot bot added the area/qute The template engine label Aug 20, 2021
@maxandersen
Copy link
Member Author

reproducer:

update.java:

///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS io.quarkus.qute:qute-core:2.2.0.CR1
//DEPS https://github.com/w3stling/rssreader/tree/v2.5.0
//JAVA 16+

import com.apptastic.rssreader.Item;
import com.apptastic.rssreader.RssReader;
import io.quarkus.qute.Engine;
import io.quarkus.qute.EvalContext;
import io.quarkus.qute.ReflectionValueResolver;
import io.quarkus.qute.ValueResolver;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class update {

    public static void main(String... args) throws IOException {

        String bio = """
                blah
		""";


        RssReader reader = new RssReader();
        Stream<Item> rssFeed = reader.read("https://xam.dk/blog/feed.atom");
        List<Item> posts = rssFeed.collect(Collectors.toList());
        var x = posts.get(0).getPubDateZonedDateTime();
        Engine engine = Engine.builder()
                .removeStandaloneLines(true)
                .addValueResolver(new ReflectionValueResolver())
                .addDefaults()
                .build();
        Files.writeString(Path.of("readme.adoc"), engine.parse(Files.readString(Path.of("template.adoc.qute")))
                .data("bio", bio)
                .data("posts", posts)
                .render());


    }
}

and template.adoc.qute:

{bio}

## ✍️ Most recent blog posts

{#for post in posts}
{post.title.get()} ({post.pubDateZonedDateTime.get().format("d MMM uuuu")})::
{post.description.get()}
{/for}

jbang update.java

@maxandersen
Copy link
Member Author

hmm - even time: namespace are not available.

Is this a case of quarkus configures qute to have these but they are not available in the standalone setup ?

@gastaldi
Copy link
Contributor

AFAIK you need to add a ValueResolver to your Engine. I faced something similar while trying to use the inject namespace in the dev UI qute template 😝

@maxandersen
Copy link
Member Author

yes thats fine but then imo the docs should not say its there by default and preferably say what resolver to add to get it....in this case though its hidden inside the quarkus extension not in qute itself.

@mkouba
Copy link
Contributor

mkouba commented Aug 26, 2021

Well, this feature is implemented via template extension methods and it's listed under the Quarkus Integration section.

There's no built-in value resolver that could be used for a standalone Engine instance.

@maxandersen
Copy link
Member Author

What are the reasons why all the basic defaults are only in quarkus ? Would at least be helpful docs would point out what is in qute and what is uniquely quarkus.

@mkouba
Copy link
Contributor

mkouba commented Aug 30, 2021

What are the reasons why all the basic defaults are only in quarkus ?

Well, Qute is primarily intended to be used as a Quarkus extension. It is possible to use it standalone but then many features (such as type-safe templates) are not available because we're not able to perform the pre-processing during the build phase. Some of those features could be ported to a runtime-only environment but this approach has its drawbacks. First of all, we would have to maintain two implementations of the same feature. And that's something we'd like to avoid.

Would at least be helpful docs would point out what is in qute and what is uniquely quarkus.

Quarkus-specific features are described under the 3. Quarkus Integration section.

@mkouba
Copy link
Contributor

mkouba commented Jan 17, 2022

FTR the limitations of Qute standalone are described here: https://quarkus.io/guides/qute-reference#standalone

@mkouba mkouba changed the title Qute format functions for java.time.ZonedDateTime Qute standalone - format functions for java.time.ZonedDateTime Jan 17, 2022
@mkouba
Copy link
Contributor

mkouba commented Apr 8, 2022

Qute standalone is not our primary target. Therefore, I'm going to list the default value resolvers in the Qute Used as a Standalone Library section and close this issue.

mkouba added a commit to mkouba/quarkus that referenced this issue Apr 8, 2022
@mkouba mkouba closed this as completed Apr 8, 2022
mkouba added a commit to mkouba/quarkus that referenced this issue Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/qute The template engine kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants