Holy cow. I think I have subtemplates and renderers working.

This commit is contained in:
Elf M. Sternberg 2013-04-17 22:37:49 -07:00
parent 7efcbb6b40
commit da5506f1df
2 changed files with 50 additions and 10 deletions

View File

@ -1,7 +1,8 @@
{ {
var _ = require('underscore'), var _ = require('underscore'),
depth = 0, depth = 0,
parts, variable, conditional, descendant, iterative, sections; parts, variable, conditional, descendant,
iterative, templatize, renderer, sections;
var Contexter = function(c) { var Contexter = function(c) {
@ -132,7 +133,22 @@
return sections(ps, content); return sections(ps, content);
}); });
} }
};
templatize = function(t, ps) {
return function(content) {
content.templatize(t, function(content) {
return sections(ps, content);
});
return "";
} }
};
renderer = function(t) {
return function(content) {
return content.template_render(t);
}
};
} }
document document
@ -170,6 +186,15 @@ loopblock_tag_end
= ld "/many:" n:tagname rd = ld "/many:" n:tagname rd
{ return n; } { return n; }
template_tag_start "tag_start"
= ld "template:" n:tagname rd
{ return n; }
template_tag_end
= ld "/template:" n:tagname rd
{ return n; }
tag_start "tag_start" tag_start "tag_start"
= ld n:tagname = ld n:tagname
@ -202,19 +227,22 @@ eol
text text
= bs:(!tag c:. {return c})+ { = bs:(!tag c:. {return c})+
return text(bs); { return text(bs); }
}
renderer
= ld "render:" n:tagname rd
{ return renderer(n); }
variable "variable" variable "variable"
= t:tag_start rd { = t:tag_start rd
return variable(t); &{ return (t != "render") }
} { return variable(t); }
document_part document_part
= iterative / descendant / conditional / variable / text = renderer / template / iterative / descendant / conditional / variable / text
simple_part simple_part
@ -227,6 +255,12 @@ conditional
{ return conditional(t, ps); } { return conditional(t, ps); }
template
= t:template_tag_start ps:simple_part* n:template_tag_end
&{ return (t == n) }
{ return templatize(t, ps); }
descendant descendant
= t:blockblock_tag_start ps:simple_part* n:blockblock_tag_end = t:blockblock_tag_start ps:simple_part* n:blockblock_tag_end
&{ return (t == n) } &{ return (t == n) }

View File

@ -84,6 +84,12 @@ test_data = [
'description': "an iterative block with ascent" 'description': "an iterative block with ascent"
} }
{
'input': "{template:a}{name}{/template:a}F{render:a}"
'output': "FG"
'data': {'name': 'G'}
'description': "A templatized block"
}
] ]