branaway / Japid

A Java-based statically-typed fast template engine that can be used in any Java code. It has special adapter for use with the Play! Framework.
113 stars 18 forks source link

[bug report] parse/tranformation problem when using _index of open-for loop within single quotes #27

Closed tunggad closed 13 years ago

tunggad commented 13 years ago

template

`import com.mongodb.DBObject;`
`import com.mongodb.util.JSON;`

`(  List<DBObject> dtdList )

<ul>
  `for DBObject dtd : dtdList
    <li>
      <h5 class='hideshowDTD {index:$_index}'>${dtd.get("package") + "." + dtd.get("name")}</h5>
      <p id='json_$_index' class='hide'>${JSON.serialize(dtd)}</p>
      <div class='align_right'>
        <a href='#' class='loadDTD {index:$_index}'>load</a> |
        <a href='#' class='hideshowDTD {index:$_index}'>hide/show</a>
      </div>
    </li>
  `
</ul>

generated code

@Override protected void doLayout() {
...

_Each0.render(dtdList, new Each.DoBody<DBObject>(){
public void render(final DBObject dtd, final int _size, final int _index, final boolean _isOdd, final String _parity, final boolean _isFirst, final boolean _isLast) {
// line 7
p("        <li>\n" + 
"          <h5 class='hideshowDTD {index:");// line 7
p(_index);// line 9
p("}'>");// line 9
p(dtd.get("package") + "." + dtd.get("name"));// line 9
p("</h5>\n" + 
"          <p id='json_");// line 9
p(_index' class='hide'>${JSON.serialize(dtd)}</p>  // HERE THE PROBLEM BEGINs
          <div class='align_right'>
            <a href=');// line 10
p("#' class='loadDTD {index:");// line 12
p(_index);// line 12
p("}'>load</a> |\n" + 
"            <a href='#' class='hideshowDTD {index:");// line 12
p(_index);// line 13
p("}'>hide/show</a>\n" + 
"          </div>\n" + 
"        </li>\n" + 
"      ");// line 13

}
}
);
// line 7
p("    </ul>");// line 16

  }

}
branaway commented 13 years ago

Please use ${_index} in this case. $ without {} is not bullet proof.

tunggad commented 13 years ago

worked!