Q:

Yeoman looping in template

I'm trying to use yeoman to take this JSON file:
{
  "models": {
    "user": {
      "properties": [
        {
          "name": {
            "type": "string"
          },
          "surname": {
            "type": "string"
          },
          "id": "number"
        }
      ]
    }
  }
}

And turn it into something like:
Class User {
  name : string
  surname : string
  id : number
}

Would it be possible to do some form of looping in the template? Here's what I have in mind...
  export class <%= entityName %> extends Model   {
      <% forEach (property in props) { %>
         <%= property.name %> : <% property.type %>;
      <% } %>
  }

A:

The template language can run any JS code. So just use normal for loop or iterations methods on arrays (arr.forEach())
export class <%= entityName %> extends Model   {
    <% for (property in props) { %>
         <%= property.name %> : <% property.type %>;
    <% } %>
}

Yeoman is using ejs as template engine. Visit their website for more information on the supported features.

