Commit deb80660 by Harold L Marzan Committed by josé bollo

Add single dot for collection of primitives

This will allow to write

{{#age}}Age: {{.}}{{/age}}

When age is an integer.
It obviously work for string, boolean, int, float
and items of array.
parent 8d7521cb
......@@ -87,20 +87,25 @@ static struct json_object *find(struct expl *e, const char *name)
#if !defined(NO_EXTENSION_FOR_MUSTACH) && !defined(NO_EQUAL_VALUE_EXTENSION_FOR_MUSTACH)
v = keyval(n);
#endif
c = key(&n);
if (c == NULL)
return NULL;
o = NULL;
i = e->depth;
while (i >= 0 && !json_object_object_get_ex(e->stack[i].obj, c, &o))
i--;
if (i < 0)
return NULL;
c = key(&n);
while(c) {
if (!json_object_object_get_ex(o, c, &o))
if (n[0] == '.' && !n[1]) {
/* case of . alone */
o = e->stack[e->depth].obj;
} else {
c = key(&n);
if (c == NULL)
return NULL;
o = NULL;
i = e->depth;
while (i >= 0 && !json_object_object_get_ex(e->stack[i].obj, c, &o))
i--;
if (i < 0)
return NULL;
c = key(&n);
while(c) {
if (!json_object_object_get_ex(o, c, &o))
return NULL;
c = key(&n);
}
}
if (v) {
i = v[0] == '!';
......
{
"name": "Chris",
"company": "<b>GitHub & Co</b>"
"company": "<b>GitHub & Co</b>",
"names": ['Chris', 'Kross'],
"skills": ['JavaScript', 'PHP', 'Java'],
"age": 18
}
......@@ -7,3 +7,9 @@
* <%company%>
* <%&company%>
* <%{company}%>
<%={{ }}=%>
* <ul>{{#names}}<li>{{.}}</li>{{/names}}</ul>
* skills: <ul>{{#skills}}<li>{{.}}</li>{{/skills}}</ul>
{{#age}}* age: {{.}}{{/age}}
* Chris
*
* 18
* &lt;b&gt;GitHub &amp; Co&lt;/b&gt;
* <b>GitHub & Co</b>
* <b>GitHub & Co</b>
......@@ -7,3 +7,9 @@
* &lt;b&gt;GitHub &amp; Co&lt;/b&gt;
* <b>GitHub & Co</b>
* <b>GitHub & Co</b>
* <ul><li>Chris</li><li>Kross</li></ul>
* skills: <ul><li>JavaScript</li><li>PHP</li><li>Java</li></ul>
* age: 18
......@@ -6,7 +6,7 @@ Command: ../mustach json must
HEAP SUMMARY:
in use at exit: 0 bytes in 0 blocks
total heap usage: 21 allocs, 21 frees, 6,339 bytes allocated
total heap usage: 46 allocs, 46 frees, 7,821 bytes allocated
All heap blocks were freed -- no leaks are possible
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment