Skip to content

Commit

Permalink
Templater v5.0.0
Browse files Browse the repository at this point in the history
Add navigation plugin example on various places (Limits and WordTables)
Remove usage of .NET 3.5 as it is no longer supported

Show example of sorting plugin in DepartmentReport
Usage of content control and removal in Paragraphs
  • Loading branch information
zapov committed Oct 22, 2020
1 parent 287d87d commit e413300
Show file tree
Hide file tree
Showing 177 changed files with 764 additions and 455 deletions.
2 changes: 1 addition & 1 deletion Advanced/CsvStreaming/CsvStreaming.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<Private>True</Private>
</Reference>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.6.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.5.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/CsvStreaming/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip" version="1.13.0" targetFramework="net40-Client" />
<package id="Templater" version="4.6.0" targetFramework="net40-Client" />
<package id="Templater" version="5.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/CsvStreaming/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>csv-streaming-example</artifactId>
<packaging>jar</packaging>
<version>4.6.0</version>
<version>5.0.0</version>
<name>CSV streaming</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
2 changes: 1 addition & 1 deletion Advanced/DepartmentReport/DepartmentReport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.6.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.5.0.0\lib\Net40\NGS.Templater.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
16 changes: 15 additions & 1 deletion Advanced/DepartmentReport/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,18 @@ If data sheet was hidden and Summary was the first sheet report would be even ea
### Anonymous classes

Templater can work with IEnumerable or Collection data sources in which case it will extract the signature from the provided data.
This way anonymous objects can be used for easier development via C# LINQ or Java Streams
This way anonymous objects can be used for easier development via C# LINQ or Java Streams


### Navigation plugin

This template has alias defined for `department.team.project:sort(name)` as `project`
Since v5 there is a natural way to deal with data manipulation during navigation via navigation plugin.
Navigation plugin can provide alternative object for further processing.
This can be used for various purposes:

* returning same collection somewhat changed (limiting, sorting, filtering, ...)
* returning totally different object/collection
* calling methods with arguments (unlike only being able to use zero method navigation)
* various other complex logic

2 changes: 1 addition & 1 deletion Advanced/DepartmentReport/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="4.6.0" targetFramework="net40-Client" />
<package id="Templater" version="5.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/DepartmentReport/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>department-report-example</artifactId>
<packaging>jar</packaging>
<version>4.6.0</version>
<version>5.0.0</version>
<name>DepartmentReportExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
Binary file modified Advanced/DepartmentReport/result.xlsx
Binary file not shown.
16 changes: 15 additions & 1 deletion Advanced/DepartmentReport/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,26 @@ public static void Main(string[] args)
{
using (var fis = File.OpenRead("template/departments.xlsx"))
using (var fos = File.OpenWrite("departments.xlsx"))
using (var doc = Configuration.Factory.Open(fis, fos, "xlsx"))
using (var doc = Configuration
.Builder
.NavigateSeparator(':')
.Include(SortExpression)
.Build()
.Open(fis, fos, "xlsx"))
doc.Process(GetCompany());

Process.Start(new ProcessStartInfo("departments.xlsx") { UseShellExecute = true });
}

static object SortExpression(object parent, object value, string member, string metadata)
{
var col = value as ICollection;
if (!metadata.StartsWith("sort(") || col == null || col.Count < 2) return value;
var property = metadata.Substring(5, metadata.Length - 6);
var f = col.OfType<object>().First().GetType().GetField(property);
return col.OfType<object>().OrderBy(it => f.GetValue(it)).ToList();
}

private static Company GetCompany()
{
var company = new Company
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package hr.ngs.templater.example;

import hr.ngs.templater.Configuration;
import hr.ngs.templater.IDocumentFactoryBuilder;
import hr.ngs.templater.ITemplateDocument;

import java.awt.Desktop;
import java.io.*;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -89,13 +91,50 @@ public static void main(final String[] args) throws Exception {
File tmp = File.createTempFile("department", ".xlsx");

FileOutputStream fos = new FileOutputStream(tmp);
ITemplateDocument tpl = Configuration.factory().open(templateStream, "xlsx", fos);
ITemplateDocument tpl = Configuration
.builder()
.navigateSeparator(':')
.include(new SortExpression())
.build()
.open(templateStream, "xlsx", fos);
tpl.process(getCompany());
tpl.flush();
fos.close();
Desktop.getDesktop().open(tmp);
}

//this is just a simplistic implementation
//a better implementation would take care of methods, dictionaries and various other types
static class SortExpression implements IDocumentFactoryBuilder.INavigate {
@Override
public Object navigate(Object parent, Object value, String member, String metadata) {
if (!metadata.startsWith("sort(") || value instanceof Object[] == false) return value;
Object[] elements = (Object[])value;
if (elements.length < 2 || elements[0] == null) return value;
String property = metadata.substring(5, metadata.length() - 1);
Field f;
try {
f = elements[0].getClass().getField(property);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
}
//just a simplistic implementation
//it doesn't check for primitives and non Comparable objects
Comparator propertyComparator = (left, right) -> {
try {
Comparable lv = (Comparable)f.get(left);
Comparable rv = (Comparable)f.get(right);
return lv.compareTo(rv);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
};
Arrays.sort(elements, propertyComparator);

return value;
}
}

private static Company getCompany() {
Company company = new Company();
company.name = "Sweat shop ltd.";
Expand Down
Binary file modified Advanced/DepartmentReport/template/departments.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion Advanced/DoubleProcessing/DoubleProcessing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.6.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.5.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/DoubleProcessing/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="4.6.0" targetFramework="net40-Client" />
<package id="Templater" version="5.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/DoubleProcessing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>double-processing-example</artifactId>
<packaging>jar</packaging>
<version>4.6.0</version>
<version>5.0.0</version>
<name>DoubleProcessingExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
2 changes: 1 addition & 1 deletion Advanced/PowerQuery/PowerQuery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.6.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.5.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/PowerQuery/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="4.6.0" targetFramework="net40-Client" />
<package id="Templater" version="5.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/PowerQuery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>power-query-example</artifactId>
<packaging>jar</packaging>
<version>4.6.0</version>
<version>5.0.0</version>
<name>PowerQueryExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
2 changes: 1 addition & 1 deletion Advanced/SalesOrderMVP (.NET)/SalesOrderMVP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<Private>True</Private>
</Reference>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.6.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.5.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/SalesOrderMVP (.NET)/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Fluent.Ribbon" version="3.6.1.236" targetFramework="net40-Client" />
<package id="Templater" version="4.6.0" targetFramework="net40-Client" />
<package id="Templater" version="5.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/SheetReport/SheetReport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<Private>True</Private>
</Reference>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.6.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.5.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/SheetReport/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SharpZipLib" version="0.86.0" targetFramework="net40-Client" />
<package id="Templater" version="4.6.0" targetFramework="net40-Client" />
<package id="Templater" version="5.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/SheetReport/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>sheet-report-example</artifactId>
<packaging>jar</packaging>
<version>4.6.0</version>
<version>5.0.0</version>
<name>SheetReportExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
2 changes: 1 addition & 1 deletion Advanced/TemplaterServer/TemplaterServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Templater" Version="4.6.0" />
<PackageReference Include="Templater" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Advanced/TemplaterServer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>templater-server</artifactId>
<packaging>jar</packaging>
<version>4.6.0</version>
<version>5.0.0</version>
<name>TemplaterServer</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
2 changes: 1 addition & 1 deletion Advanced/XmlBinding/XmlBinding.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.6.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.5.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Advanced/XmlBinding/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="4.6.0" targetFramework="net40-Client" />
<package id="Templater" version="5.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Advanced/XmlBinding/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>xml-binding-example</artifactId>
<packaging>jar</packaging>
<version>4.6.0</version>
<version>5.0.0</version>
<name>XmlBindingExample</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
2 changes: 1 addition & 1 deletion Beginner/AndroidExample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'hr.ngs.templater:templater:4.3.0'
implementation 'hr.ngs.templater:templater:5.0.0'
implementation 'xalan:xalan:2.7.2'
implementation 'xerces:xercesImpl:2.12.0'
testImplementation 'junit:junit:4.12'
Expand Down
2 changes: 1 addition & 1 deletion Beginner/BeerList (Scala)/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ version := "1.0.0-SNAPSHOT"
organization := "hr.ngs.templater.example"
scalaVersion := "2.11.12"

libraryDependencies += "hr.ngs.templater" %% "templater" % "4.6.0"
libraryDependencies += "hr.ngs.templater" %% "templater" % "5.0.0"
2 changes: 1 addition & 1 deletion Beginner/CsvExample/CsvExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.6.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.5.0.0\lib\Net40\NGS.Templater.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion Beginner/CsvExample/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="4.6.0" targetFramework="net40-Client" />
<package id="Templater" version="5.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Beginner/CsvExample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>csv-example</artifactId>
<packaging>jar</packaging>
<version>4.6.0</version>
<version>5.0.0</version>
<name>CSV</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
2 changes: 1 addition & 1 deletion Beginner/DataSet (.NET)/DataSetExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.6.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.5.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Beginner/DataSet (.NET)/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="4.6.0" targetFramework="net40-Client" />
<package id="Templater" version="5.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Beginner/DynamicResize/DynamicResize.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NGS.Templater">
<HintPath>..\..\packages\Templater.4.6.0\lib\Net40\NGS.Templater.dll</HintPath>
<HintPath>..\..\packages\Templater.5.0.0\lib\Net40\NGS.Templater.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
2 changes: 1 addition & 1 deletion Beginner/DynamicResize/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Templater" version="4.6.0" targetFramework="net40-Client" />
<package id="Templater" version="5.0.0" targetFramework="net40-Client" />
</packages>
2 changes: 1 addition & 1 deletion Beginner/DynamicResize/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>hr.ngs.templater.example</groupId>
<artifactId>dynamic-resize</artifactId>
<packaging>jar</packaging>
<version>4.6.0</version>
<version>5.0.0</version>
<name>DynamicResize</name>
<url>https://github.com/ngs-doo/TemplaterExamples</url>

Expand Down
Loading

0 comments on commit e413300

Please sign in to comment.