Skip to content

Add native support for Jstachio #566

@SentryMan

Description

@SentryMan

I'm thinking of something like

@Controller("/widgets")
public class WidgetController {
  private final HelloComponent hello;
  public WidgetController(HelloComponent hello) {
    this.hello = hello;
  }

  @Get("/{id}")
  HelloWorld getById(int id) {
    //...
  }

  @JStache(
      template =
          """
          {{#people}}
          {{.}}! You are
          {{#-last}}
          That is all for now!
          {{/-last}}
          {{/people}}
          """)
  public record HelloWorld(List<String> people) {}
}

we should read the jstache annotation and generate something like

@Generated("avaje-helidon-generator")
@Component
public class WidgetController$Route implements HttpFeature {

  private final WidgetController controller;

  public WidgetController$Route(WidgetController controller) {
    this.controller = controller;
  }

  @Override
  public void setup(HttpRouting.Builder routing) {
    routing.get("/widgets/{id}", this::_getById);
  }

  private void _getById(ServerRequest req, ServerResponse res) throws Exception {
    res.status(OK_200);
    var pathParams = req.path().pathParameters();
    var id = asInt(pathParams.contains("id") ? pathParams.get("id") : null);
    var result = controller.getById(id);
    res.send(Jstachio.render(result)); // or the generated renderer if running in zero dependency mode
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions