I try to write a simple web template engine in ruby that take an input, a json file and produce a html file. The content to be replaced will have syntax like this <* place_holder *>
for example the template look like this:
<body>
<h1><* teacher.name *></h1>
<* EACH students student *>
<* student.name *>
<* ENDEACH *>
the json is :
{
"page": {
"title": "Templating Example"
},
"teacher": {
"name": "Mr. John"
},
"students": [
{ "name": "Bruce Wayne", "nicknames": ["Batman"] },
{ "name": "Peter Parker", "nicknames": ["Spidey", "Spiderman", "Spider-Man"] }
]
}
and the output will be
<body>
<h1>Mr. John</h1>
Bruce Wayne
<p>Batman</p>
Peter Parker
<p>Spidey</p>
<p>Spiderman</p>
<p>Spider-Man</p>
I tried but still not figure out how to replace the loop in the template, please help.
Aucun commentaire:
Enregistrer un commentaire