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

linebreak is trimmed #126

Closed
Zane-XY opened this issue Dec 14, 2020 · 2 comments
Closed

linebreak is trimmed #126

Zane-XY opened this issue Dec 14, 2020 · 2 comments

Comments

@Zane-XY
Copy link

Zane-XY commented Dec 14, 2020

Trying to modify the template in the swagger code generator. The template is like

{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}}
  public {{{datatypeWithEnum}}} {{getter}}() {
    return {{name}};
  }

the expected result is

  @Min(1) @Max(99999)
  public Integer getZip() {
    return zip;
  }

however this gives

 @Min(1) @Max(99999)  public Integer getZip() {
    return zip;
  }

the line break after {{/useBeanValidation}} is not preserved.

@agentgt
Copy link
Contributor

agentgt commented Apr 5, 2022

First see this: https://github.com/samskivert/jmustache#newline-trimming

Second I could not reproduce your problem.

     @Test
    public void testTrim()
            throws Exception {
        String template = //
                """
                        {{#useBeanValidation}}{{> beanValidation}}{{/useBeanValidation}}
                        public Integer getZip() {
                          return zip;
                        }""";
        
        var m = Map.of("useBeanValidation", true, "beanValidation", "@Validation");
        
        StringReader sr = new StringReader("@Min(1) @Max(99999)");
        Mustache.TemplateLoader loader = name -> sr;
        
        String actual = Mustache.compiler()
                .withLoader(loader)
                .compile(template).execute(m);
        
        String expected = "@Min(1) @Max(99999)\n" //  notice new line
                + "public Integer getZip() {\n"
                + "  return zip;\n"
                + "}";
        
        assertEquals(expected, actual);
    }

@agentgt
Copy link
Contributor

agentgt commented Dec 4, 2023

@samskivert

I could not reproduce this. I think we can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants