Skip to content

Commit

Permalink
Merge 9c20e7e into 12adc15
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins committed Jun 10, 2021
2 parents 12adc15 + 9c20e7e commit e3ecdf3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
1 change: 0 additions & 1 deletion lib/src/mustachio/parser.dart
Expand Up @@ -255,7 +255,6 @@ class MustachioParser {
keySpanEndOffset - lastName.length, keySpanEndOffset);
var section = Section([lastName], children,
invert: invert, span: span, keySpan: lastNameSpan);
//for (var sectionKey in parsedKey.names.reversed.skip(1)) {
for (var i = parsedKey.names.length - 2; i >= 0; i--) {
var sectionKey = parsedKey.names[i];
// To find the start offset of the ith name, take the length of all of
Expand Down
14 changes: 12 additions & 2 deletions lib/src/mustachio/renderer_base.dart
Expand Up @@ -145,7 +145,7 @@ abstract class RendererBase<T> {
Template _template;

/// The output buffer into which [context] is rendered, using a template.
final buffer = StringBuffer();
StringBuffer buffer = StringBuffer();

final Set<String> _invisibleGetters;

Expand Down Expand Up @@ -234,7 +234,7 @@ abstract class RendererBase<T> {
"Failed to resolve '$key' as a property on any types in the "
'current context'));
} else {
return parent.section(node);
return parent.withBuffer(buffer, () => parent.section(node));
}
}

Expand Down Expand Up @@ -279,6 +279,16 @@ abstract class RendererBase<T> {
renderBlock(partialTemplate.ast);
_template = outerTemplate;
}

/// Executes [fn] after replacing [buffer] with [newBuffer].
///
/// Replaces the previous buffer as [buffer].
void withBuffer(StringBuffer newBuffer, void Function() fn) {
var previousBuffer = buffer;
buffer = newBuffer;
fn();
buffer = previousBuffer;
}
}

String renderSimple(Object context, List<MustachioNode> ast, Template template,
Expand Down
9 changes: 9 additions & 0 deletions test/mustachio/aot_compiler_render_test.dart
Expand Up @@ -259,6 +259,15 @@ void main() {
expect(output, equals('Text Foo: hello'));
});

test('Renderer renders a value section node keyed lower in the stack',
() async {
var output = await renderBar({
'foo|lib/templates/html/bar.html':
'Text {{#foo}}One {{#s2}}Two{{/s2}}{{/foo}}',
}, '_i1.Bar()..foo = _i1.Foo()..s2 = "hello"');
expect(output, equals('Text One Two'));
});

test('Renderer renders a null value section node as blank', () async {
var output = await renderFoo({
'foo|lib/templates/html/foo.html':
Expand Down
11 changes: 11 additions & 0 deletions test/mustachio/runtime_renderer_render_test.dart
Expand Up @@ -202,6 +202,17 @@ void main() {
expect(renderBar(bar, barTemplate), equals('Text Foo: hello'));
});

test('Renderer renders a value section node keyed lower in the stack',
() async {
var barTemplateFile = getFile('/project/bar.mustache')
..writeAsStringSync('Text {{#foo}}One {{#s2}}Two{{/s2}}{{/foo}}');
var barTemplate = await Template.parse(barTemplateFile);
var bar = Bar()
..foo = Foo()
..s2 = 'hello';
expect(renderBar(bar, barTemplate), equals('Text One Two'));
});

test('Renderer renders a null value section node as blank', () async {
var fooTemplateFile = getFile('/project/foo.mustache')
..writeAsStringSync('Text {{#s1}}"{{.}}" ({{length}}){{/s1}}');
Expand Down

0 comments on commit e3ecdf3

Please sign in to comment.