@@ -103,42 +103,38 @@ protected virtual ExpressionResult GetExpressionResult(Expression expression,
103103 }
104104
105105 /// <summary>
106- /// Renders a document and returns its result.
106+ /// Renders a document, macro or element and returns its result.
107107 /// </summary>
108- /// <returns>The document .</returns>
109- /// <param name="document">Document .</param>
110- /// <param name="context">Context .</param>
111- protected virtual string RenderDocument ( object document , IRenderingContext context )
108+ /// <returns>The rendered markup .</returns>
109+ /// <param name="targetToRender">The target item to render .</param>
110+ /// <param name="context">The current rendering context .</param>
111+ protected virtual string RenderDocument ( object targetToRender , IRenderingContext context )
112112 {
113- if ( document == null )
114- {
115- throw new ArgumentNullException ( nameof ( document ) ) ;
116- }
113+ if ( targetToRender == null )
114+ throw new ArgumentNullException ( nameof ( targetToRender ) ) ;
117115 if ( context == null )
118- {
119116 throw new ArgumentNullException ( nameof ( context ) ) ;
120- }
121117
122- if ( document is IZptDocument )
118+ if ( targetToRender is IZptDocument )
123119 {
124- return Render ( ( IZptDocument ) document , context ) ;
120+ return Render ( ( IZptDocument ) targetToRender , context ) ;
125121 }
126- else if ( document is TemplateFile )
122+ else if ( targetToRender is TemplateFile )
127123 {
128- return Render ( ( TemplateFile ) document , context ) ;
124+ return Render ( ( TemplateFile ) targetToRender , context ) ;
129125 }
130- else if ( document is MetalMacro )
126+ else if ( targetToRender is IMetalMacro )
131127 {
132- return Render ( ( MetalMacro ) document , context ) ;
128+ return Render ( ( IMetalMacro ) targetToRender , context ) ;
133129 }
134- else if ( document is IZptElement )
130+ else if ( targetToRender is IZptElement )
135131 {
136- return Render ( ( IZptElement ) document , context ) ;
132+ return Render ( ( IZptElement ) targetToRender , context ) ;
137133 }
138134 else
139135 {
140136 var message = String . Format ( Resources . ExceptionMessages . UnsupportedDocumentTypeFormat ,
141- document . GetType ( ) . FullName ,
137+ targetToRender . GetType ( ) . FullName ,
142138 String . Join ( ", " , SupportedTypes . Select ( x => x . FullName ) ) ) ;
143139 throw new UnsupportedDocumentTypeException ( message ) ;
144140 }
@@ -176,22 +172,24 @@ protected virtual string Render(TemplateFile document, IRenderingContext context
176172 throw new ArgumentNullException ( nameof ( document ) ) ;
177173 }
178174
179- return Render ( document . Document , context ) ;
175+ var doc = document . Document ;
176+ return Render ( doc , context ) ;
180177 }
181178
182179 /// <summary>
183180 /// Renders a <see cref="MetalMacro"/>.
184181 /// </summary>
185182 /// <param name="macro">Macro.</param>
186183 /// <param name="context">Context.</param>
187- protected virtual string Render ( MetalMacro macro , IRenderingContext context )
184+ protected virtual string Render ( IMetalMacro macro , IRenderingContext context )
188185 {
189186 if ( macro == null )
190187 {
191188 throw new ArgumentNullException ( nameof ( macro ) ) ;
192189 }
193190
194- return Render ( macro . Element , context ) ;
191+ var doc = macro . Element . Clone ( ) . CreateDocumentFromThisElement ( ) ;
192+ return Render ( doc , context ) ;
195193 }
196194
197195 /// <summary>
@@ -206,7 +204,8 @@ protected virtual string Render(IZptElement element, IRenderingContext context)
206204 throw new ArgumentNullException ( nameof ( element ) ) ;
207205 }
208206
209- return Render ( element . CreateDocumentFromThisElement ( ) , context ) ;
207+ var doc = element . Clone ( ) . CreateDocumentFromThisElement ( ) ;
208+ return Render ( doc , context ) ;
210209 }
211210
212211 #endregion
0 commit comments