22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5+ import 'package:analyzer/file_system/file_system.dart' ;
56import 'package:meta/meta.dart' ;
67import 'parser.dart' ;
78
@@ -13,10 +14,12 @@ abstract class RendererBase<T> {
1314 /// The renderer of the parent context, if any, otherwise `null` .
1415 final RendererBase parent;
1516
17+ final File template;
18+
1619 /// The output buffer into which [context] is rendered, using a template.
1720 final buffer = StringBuffer ();
1821
19- RendererBase (this .context, this .parent);
22+ RendererBase (this .context, this .parent, this .template );
2023
2124 void write (String text) => buffer.write (text);
2225
@@ -48,7 +51,7 @@ abstract class RendererBase<T> {
4851 throw MustachioResolutionError (
4952 "Failed to resolve '${e .name }' on ${e .contextType } while resolving "
5053 '${names .skip (1 )} as a property chain on any types in the context '
51- "chain: $contextChainString , after first resolving '${names .first }'"
54+ "chain: $contextChainString , after first resolving '${names .first }' "
5255 'to a property on $T ' );
5356 }
5457 } else if (parent != null ) {
@@ -118,20 +121,33 @@ abstract class RendererBase<T> {
118121 }
119122
120123 void partial (Partial node) {
121- // TODO(srawlins): Implement.
124+ var key = node.key;
125+ var partialPath = template.provider.pathContext.isAbsolute (key)
126+ ? key
127+ : template.provider.pathContext.join (template.parent.path, key);
128+ try {
129+ var file = template.provider
130+ .getFile (template.provider.pathContext.normalize (partialPath));
131+ var parser = MustachioParser (file.readAsStringSync ());
132+ var ast = parser.parse ();
133+ renderBlock (ast);
134+ } on FileSystemException catch (e) {
135+ throw MustachioResolutionError (
136+ 'FileSystemException when reading partial "$key " found in template "${template .path }": ${e .message }' );
137+ }
122138 }
123139}
124140
125- String renderSimple (Object context, List <MustachioNode > ast,
141+ String renderSimple (Object context, List <MustachioNode > ast, File template,
126142 {RendererBase parent}) {
127- var renderer = SimpleRenderer (context, parent);
143+ var renderer = SimpleRenderer (context, parent, template );
128144 renderer.renderBlock (ast);
129145 return renderer.buffer.toString ();
130146}
131147
132148class SimpleRenderer extends RendererBase <Object > {
133- SimpleRenderer (Object context, RendererBase <Object > parent)
134- : super (context, parent);
149+ SimpleRenderer (Object context, RendererBase <Object > parent, File template )
150+ : super (context, parent, template );
135151
136152 @override
137153 Property <Object > getProperty (String key) => null ;
0 commit comments