Skip to content

Commit 8cae1ef

Browse files
committed
Merge branch 'release/1.0.3' into production
2 parents 7185616 + adbf94e commit 8cae1ef

5 files changed

Lines changed: 102 additions & 25 deletions

File tree

ExpressionEvaluators/CSF.Zpt.ExpressionEvaluators.LoadExpressions/LoadExpressionEvaluator.cs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<html>
2+
<head>
3+
<title>Load plugin test 5</title>
4+
</head>
5+
<body>
6+
<div>
7+
<ul>
8+
<li>
9+
<div>
10+
<p>Content from the macro, before the slot-filler</p>
11+
<p>
12+
This is slot content from macro 'test2'.
13+
The item name is <strong>One</strong>.
14+
</p>
15+
<p>Content from the macro, after the slot-filler</p>
16+
</div>
17+
</li>
18+
<li>
19+
<div>
20+
<p>Content from the macro, before the slot-filler</p>
21+
<p>
22+
This is slot content from macro 'test2'.
23+
The item name is <strong>Two</strong>.
24+
</p>
25+
<p>Content from the macro, after the slot-filler</p>
26+
</div>
27+
</li>
28+
<li>
29+
<div>
30+
<p>Content from the macro, before the slot-filler</p>
31+
<p>
32+
This is slot content from macro 'test2'.
33+
The item name is <strong>Three</strong>.
34+
</p>
35+
<p>Content from the macro, after the slot-filler</p>
36+
</div>
37+
</li>
38+
39+
</ul>
40+
</div>
41+
42+
</body>
43+
</html>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<html>
2+
<head>
3+
<title>Load plugin test 5</title>
4+
</head>
5+
<body>
6+
<div>
7+
<ul tal:define="myMacro here/Documents/test05/macros/test2">
8+
<li tal:repeat="item here/Items">
9+
<div tal:define="doc load:myMacro"
10+
tal:replace="structure doc">
11+
This content should be replaced by the rendered document
12+
</div>
13+
</li>
14+
</ul>
15+
</div>
16+
<div class="macros" tal:condition="nothing">
17+
<div metal:define-macro="test1">
18+
<p>Content from the macro, before the slot-filler</p>
19+
<p metal:define-slot="first">Default slot content here</p>
20+
<p>Content from the macro, after the slot-filler</p>
21+
</div>
22+
<div metal:extend-macro="test1"
23+
metal:define-macro="test2">
24+
<p>This is content from a different macro</p>
25+
<p metal:fill-slot="first">
26+
This is slot content from macro 'test2'.
27+
The item name is <strong tal:content="item/Name | default">Empty</strong>.
28+
</p>
29+
<p>This is content from a different macro</p>
30+
</div>
31+
</div>
32+
</body>
33+
</html>

Tests/Test.CSF.Zpt.Integration/Test.CSF.Zpt.Integration.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@
264264
<None Include="Test data\LoadPluginTests\ExpectedOutputs\test04.html" />
265265
<None Include="Test data\ZptIntegrationTests\SourceDocuments\issue-221_form_test.html" />
266266
<None Include="Test data\ZptIntegrationTests\ExpectedOutputs\issue-221_form_test.html" />
267+
<None Include="Test data\LoadPluginTests\SourceDocuments\test05.html" />
268+
<None Include="Test data\LoadPluginTests\ExpectedOutputs\test05.html" />
267269
</ItemGroup>
268270
<ItemGroup>
269271
<ProjectReference Include="..\..\CSF.Zpt\CSF.Zpt.csproj">

version.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
semantic_version = 1.0.2
1+
semantic_version = 1.0.3
22
build_number = 1

0 commit comments

Comments
 (0)