Skip to content

Commit

Permalink
Merge pull request #13 from Amberg/workitems/ReadmeFix
Browse files Browse the repository at this point in the history
fix in documentation
  • Loading branch information
Amberg authored May 21, 2024
2 parents 4347270 + 8b25a8d commit 0a69175
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 36 deletions.
2 changes: 1 addition & 1 deletion DocxTemplater.Images/DocxTemplater.Images.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DocxTemplater\DocxTemplater.csproj" />
Expand Down
32 changes: 16 additions & 16 deletions DocxTemplater.Test/DocxTemplateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void ImplicitIterator()
docTemplate.BindModel("ds", model);
var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
// check result text
var document = WordprocessingDocument.Open(result, false);
var body = document.MainDocumentPart.Document.Body;
Expand All @@ -183,7 +183,7 @@ public string DateTimeFormatterTest(string format)

var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
// check result text
var document = WordprocessingDocument.Open(result, false);
var body = document.MainDocumentPart.Document.Body;
Expand All @@ -208,14 +208,14 @@ public void HtmlIsAlwaysEnclosedWithHtmlTags(string html, string expexted)

var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
result.SaveAsFileAndOpenInWord();
result.Position = 0;
var document = WordprocessingDocument.Open(result, false);
// check word contains altChunk
var body = document.MainDocumentPart.Document.Body;
var altChunk = body.Descendants<AltChunk>().FirstOrDefault();
Assert.IsNotNull(altChunk);
Assert.That(result, Is.Not.Null);
// extract html part
var htmlPart = document.MainDocumentPart.GetPartById(altChunk.Id);
var stream = htmlPart.GetStream();
Expand All @@ -238,7 +238,7 @@ public void InsertHtmlInLoop()
docTemplate.BindModel("Items", new[] { "<h1>Test1</h1>", "<h1>Test2</h1>" });
var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
result.SaveAsFileAndOpenInWord();
// check document contains 2 altChunks
var document = WordprocessingDocument.Open(result, false);
Expand All @@ -262,7 +262,7 @@ public void InsertTextWithNewline()
docTemplate.BindModel("ds", "FirstLine\r\nSecondLine\nThirdLine");
var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
// check document contains newline
var document = WordprocessingDocument.Open(result, false);
var body = document.MainDocumentPart.Document.Body;
Expand Down Expand Up @@ -292,7 +292,7 @@ public void ConditionalBlockInLoop()
});
var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
// validate content
var document = WordprocessingDocument.Open(result, false);
var body = document.MainDocumentPart.Document.Body;
Expand All @@ -313,7 +313,7 @@ public void NullValueHandlingForNesteObjects()
docTemplate.BindModel("ds", new { Model = new { Outer = (LessonReportModel)null } });
var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
var document = WordprocessingDocument.Open(result, false);
var body = document.MainDocumentPart.Document.Body;
//check values have been replaced
Expand Down Expand Up @@ -358,7 +358,7 @@ public void LoopStartAndEndTagsAreRemoved()
docTemplate.BindModel("ds", new { Items = new[] { new { Name = "Item1", Price = 5 }, new { Name = "Item2", Price = 7 } } });
var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
result.Position = 0;
result.SaveAsFileAndOpenInWord();
result.Position = 0;
Expand All @@ -382,7 +382,7 @@ public void CollectionSeparatorTest()
docTemplate.BindModel("ds", new[] { "Item1", "Item2", "Item3" });
var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
// check result text
var document = WordprocessingDocument.Open(result, false);
var body = document.MainDocumentPart.Document.Body;
Expand Down Expand Up @@ -413,7 +413,7 @@ public void ConditionsWithAndWithoutPrefix()
docTemplate.BindModel("ds4", new { MyBool = false });
var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
result.Position = 0;
result.SaveAsFileAndOpenInWord();
result.Position = 0;
Expand Down Expand Up @@ -456,7 +456,7 @@ public void BindToMultipleModels()

var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
result.Position = 0;

var document = WordprocessingDocument.Open(result, false);
Expand All @@ -482,7 +482,7 @@ public void ReplaceTextBoldIsPreserved()
docTemplate.BindModel("Property1", "Replaced");
var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
result.Position = 0;

var document = WordprocessingDocument.Open((Stream)result, false);
Expand Down Expand Up @@ -511,7 +511,7 @@ public string CultureIsAppliedTest(string formatter, CultureInfo culture, object
docTemplate.BindModel("var", value);
var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
result.Position = 0;

var document = WordprocessingDocument.Open(result, false);
Expand Down Expand Up @@ -585,7 +585,7 @@ public void BindCollection()
docTemplate.BindModel("company", new { Name = "X" });
var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
result.Position = 0;

var document = WordprocessingDocument.Open(result, false);
Expand Down Expand Up @@ -655,7 +655,7 @@ public void BindCollectionToTable()
});
var result = docTemplate.Process();
docTemplate.Validate();
Assert.IsNotNull(result);
Assert.That(result, Is.Not.Null);
result.Position = 0;
// result.SaveAsFileAndOpenInWord();
var document = WordprocessingDocument.Open(result, false);
Expand Down
16 changes: 11 additions & 5 deletions DocxTemplater.Test/DocxTemplater.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoBogus" Version="2.13.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DocxTemplater.Images\DocxTemplater.Images.csproj" />
Expand Down
20 changes: 10 additions & 10 deletions DocxTemplater.Test/OpenXmlHelperTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void SplitAfterElementSameRunAtParagraphLevel()
var splitedParts = paragraph.SplitAfterElement(element);

Assert.That(splitedParts.Count, Is.EqualTo(2));
Assert.True(splitedParts.All(x => x is Paragraph));
Assert.That(splitedParts.All(x => x is Paragraph));
Assert.That(splitedParts.ElementAt(0).Descendants<Text>().Count(), Is.EqualTo(2));
Assert.That(splitedParts.ElementAt(1).Descendants<Text>().Count(), Is.EqualTo(3));
Assert.That(body.InnerText, Is.EqualTo(innerTextBefore));
Expand All @@ -41,7 +41,7 @@ public void SplitAfterElementDifferentRunAtParagraphLevel()
var splitedParts = paragraph.SplitAfterElement(element);

Assert.That(splitedParts.Count, Is.EqualTo(2));
Assert.True(splitedParts.All(x => x is Paragraph));
Assert.That(splitedParts.All(x => x is Paragraph));
Assert.That(splitedParts.ElementAt(0).Descendants<Text>().Count(), Is.EqualTo(2));
Assert.That(splitedParts.ElementAt(1).Descendants<Text>().Count(), Is.EqualTo(3));
Assert.That(body.InnerText, Is.EqualTo(innerTextBefore));
Expand All @@ -62,7 +62,7 @@ public void SplitAfterElemntSameRunAtRunLevel()

var splitedParts = run.SplitAfterElement(element);
Assert.That(splitedParts.Count, Is.EqualTo(2));
Assert.True(splitedParts.All(x => x is Run));
Assert.That(splitedParts.All(x => x is Run));
Assert.That(splitedParts.ElementAt(0).Descendants<Text>().Count(), Is.EqualTo(2));
Assert.That(splitedParts.ElementAt(1).Descendants<Text>().Count(), Is.EqualTo(3));
Assert.That(body.InnerText, Is.EqualTo(innerTextBefore));
Expand All @@ -82,7 +82,7 @@ public void SplitBeforeElementSameRunAtParagraphLevel()
var splitedParts = paragraph.SplitBeforeElement(element);

Assert.That(splitedParts.Count, Is.EqualTo(2));
Assert.True(splitedParts.All(x => x is Paragraph));
Assert.That(splitedParts.All(x => x is Paragraph));
Assert.That(splitedParts.ElementAt(0).Descendants<Text>().Count(), Is.EqualTo(1));
Assert.That(splitedParts.ElementAt(1).Descendants<Text>().Count(), Is.EqualTo(4));
Assert.That(body.InnerText, Is.EqualTo(innerTextBefore));
Expand All @@ -103,7 +103,7 @@ public void SplitBeforeElementSameRunAtRunLevel()
var splitedParts = run.SplitBeforeElement(element);

Assert.That(splitedParts.Count, Is.EqualTo(2));
Assert.True(splitedParts.All(x => x is Run));
Assert.That(splitedParts.All(x => x is Run));
Assert.That(splitedParts.ElementAt(0).Descendants<Text>().Count(), Is.EqualTo(1));
Assert.That(splitedParts.ElementAt(1).Descendants<Text>().Count(), Is.EqualTo(4));
Assert.That(body.InnerText, Is.EqualTo(innerTextBefore));
Expand All @@ -125,7 +125,7 @@ public void SplitAfterElementAtEndOfParent()
var splitedParts = run.SplitAfterElement(element);

Assert.That(splitedParts.Count, Is.EqualTo(1));
Assert.True(splitedParts.All(x => x is Run));
Assert.That(splitedParts.All(x => x is Run));
Assert.That(splitedParts.ElementAt(0).Descendants<Text>().Count(), Is.EqualTo(5));
Assert.That(body.InnerText, Is.EqualTo(innerTextBefore));
}
Expand All @@ -146,7 +146,7 @@ public void SplitBeforeElementAtStartOfParent()
var splitedParts = run.SplitBeforeElement(element);

Assert.That(splitedParts.Count, Is.EqualTo(1));
Assert.True(splitedParts.All(x => x is Run));
Assert.That(splitedParts.All(x => x is Run));
Assert.That(splitedParts.ElementAt(0).Descendants<Text>().Count(), Is.EqualTo(5));
Assert.That(body.InnerText, Is.EqualTo(innerTextBefore));
}
Expand All @@ -165,7 +165,7 @@ public void SplitRun()
var paragraph = new Paragraph(xml);
var parts = paragraph.ChildElements.First<Run>().SplitAfterElement(paragraph.Descendants<Text>().First());
Assert.That(parts.Count, Is.EqualTo(2));
CollectionAssert.AreEqual(parts.Select(x => x.InnerText), new[] { "Text1", "Text2" });
Assert.That(parts.Select(x => x.InnerText), Is.EqualTo(new[] { "Text1", "Text2" }));

var runs = paragraph.Descendants<Run>().ToList();
Assert.That(runs.Count, Is.EqualTo(2));
Expand All @@ -186,7 +186,7 @@ public void SplitRunOnlyOneTextInRun()
var paragraph = new Paragraph(xml);
var parts = paragraph.ChildElements.First<Run>().SplitAfterElement(paragraph.Descendants<Text>().First());
Assert.That(parts.Count, Is.EqualTo(1));
CollectionAssert.AreEqual(parts.Select(x => x.InnerText), new[] { "Text1" });
Assert.That(parts.Select(x => x.InnerText), Is.EqualTo(new[] { "Text1" }));

var runs = paragraph.Descendants<Run>().ToList();
Assert.That(runs.Count, Is.EqualTo(1));
Expand Down Expand Up @@ -259,7 +259,7 @@ public void MergeTextMiddle()
var paragraph = new Paragraph(xml);
var firstText = paragraph.Descendants<Text>().Single(x => x.Text == "LeadingMiddleEnd");
firstText.MergeText(7, firstText, 6);
CollectionAssert.AreEqual(new[] { "Leading", "Middle", "End" }, paragraph.Descendants<Text>().Select(x => x.Text));
Assert.That(paragraph.Descendants<Text>().Select(x => x.Text), Is.EqualTo(new[] { "Leading", "Middle", "End" }));
}
}
}
3 changes: 3 additions & 0 deletions DocxTemplater.Test/PatternMatcherTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static IEnumerable TestPatternMatch_Cases()
yield return new TestCaseData("{{ds.foo.var}:F(d)}").Returns(new[] { PatternType.Variable }).SetName("Variable with dot");
yield return new TestCaseData("{{ds.foo_blubb.var}:F(d)}").Returns(new[] { PatternType.Variable }).SetName("Variable with underscore");
yield return new TestCaseData("{{var}:toupper}").Returns(new[] { PatternType.Variable });
yield return new TestCaseData("{{var}:f(MM/dd/yyy)}").Returns(new[] { PatternType.Variable }).SetName("Slash in pattern");
yield return new TestCaseData("{{else}}").Returns(new[] { PatternType.ConditionElse });
yield return new TestCaseData("{{ else }}").Returns(new[] { PatternType.ConditionElse });
yield return new TestCaseData("{{ : }}").Returns(new[] { PatternType.ConditionElse });
Expand Down Expand Up @@ -78,6 +79,8 @@ static IEnumerable PatternMatcherArgumentParsingTest_Cases()
yield return new TestCaseData("{{Foo}}").Returns(Array.Empty<string>());
yield return new TestCaseData("{{Foo}:format}").Returns(Array.Empty<string>());
yield return new TestCaseData("{{Foo}:format()}").Returns(Array.Empty<string>());
yield return new TestCaseData("{{Foo}:format('MM/dd/yyyy')}").Returns(new[] { "MM/dd/yyyy" });
yield return new TestCaseData("{{Foo}:format(MM/dd/yyyy)}").Returns(new[] { "MM/dd/yyyy" });
yield return new TestCaseData("{{Foo}:format('')}").Returns(new[] { string.Empty });
yield return new TestCaseData("{{Foo}:format(a)}").Returns(new[] { "a" });
yield return new TestCaseData("{{Foo}:format(param)}").Returns(new[] { "param" });
Expand Down
2 changes: 1 addition & 1 deletion DocxTemplater/DocxTemplater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
<PackageReference Include="DynamicExpresso.Core" Version="2.16.1" />
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion DocxTemplater/PatterMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal static class PatternMatcher
(?:\(
(?:
(?:
'(?<arg>(?:(?:\\')|[\w\s-\\/:,""])*?)' # quoted string can contain , or whitespace or can be empty
'(?<arg>(?:(?:\\('))|[\w\s-\\/:,""])*?)' # quoted string can contain , or whitespace or can be empty
|
(?<arg>[\w\s-\\/:'""]+) # unquoted string
)(?:\s*,\s*)? # starting and leading whitespaces are ignored
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ The syntax is case insensitive
| {{/Items}}...{{.}:toUpper} ... {{/Items}} | A list of string all upper case - dot notation
| {{/Items}}{{.}}{{:s:}},{{/Items}} | A list of strings comma separated - dot notation
| {{SomeString}:ToUpper()} | Variable with formatter to upper
| {{SomeDate}:Format("MM/dd/yyyy")} | Date variable with formatting
| {{SomeDate}:F("MM/dd/yyyy")} | Date variable with formatting - short syntax
| {{SomeDate}:Format('MM/dd/yyyy')} | Date variable with formatting
| {{SomeDate}:F('MM/dd/yyyy')} | Date variable with formatting - short syntax
| {{SomeBytes}:img()} | Image Formatter for image data
| {{SomeHtmlString}:html()} | Inserts html string into word document
### Collections
Expand Down

0 comments on commit 0a69175

Please sign in to comment.