Search code examples
javascriptjavawebwebserverpug

Jade4J for loop unable to evaluate


I can't seem to find an answer to this anywhere, the github for it is not being updated, and I'm about to throw my computer out the window.

I am trying to create a website via java, and am using Jade4J implentation to use Jade.

This is my simple jade file: (indents aren't appearning, they are there)

html
title Whatup
-for(var i = 0; i < 3; i++)
    h4 Haithere

And all I'm getting is this error:

unable to evaluate [for(var i = 0; i < 3; i++)] - Parsing de.neuland.jade4j.expression.JexlExpressionHandler.evaluateExpression@1:11 parsing error near '... r i = 0; i ...' in test.jade:3

This works just fine in Node or any other implementation of Jade...

Any ideas... please


Solution

  • It looks like this is a problem for others as well. You could write a native JavaScript function to create an array based off of a range of values.

    html
      title Whatup
      -function range(start, end) {
      -    var arr = [];
      -    for (var i = start; i < end; i++) arr.push(i);
      -    return arr;
      -  }
      each i in range(0, 3)
          h4 Haithere
    

    Produces:

    <html>
      <title>Whatup</title>
      <h4>Haithere</h4>
      <h4>Haithere</h4>
      <h4>Haithere</h4>
    </html>