Add FileSystemTemplateSource(.., bool throws)
ln.build build job pending

master
Harald Wolff 2020-12-01 12:45:50 +01:00
parent 29f17af90c
commit b3ca0d3bb9
2 changed files with 12 additions and 3 deletions

View File

@ -8,9 +8,15 @@ namespace ln.templates.html
public class FileSystemTemplateSource : ITemplateSource
{
public String BasePath { get; }
public bool Throws { get; }
Dictionary<string, TemplateDocument> templateDocuments = new Dictionary<string, TemplateDocument>();
public FileSystemTemplateSource(String path,bool throws)
:this(path)
{
Throws = throws;
}
public FileSystemTemplateSource(String path)
{
if (!Directory.Exists(path))
@ -18,7 +24,8 @@ namespace ln.templates.html
BasePath = path;
}
public TemplateDocument GetTemplateByPath(string path)
public TemplateDocument GetTemplateByPath(string path) => GetTemplateByPath(path, Throws);
public TemplateDocument GetTemplateByPath(string path,bool _throw)
{
string templatePath = Path.Combine(BasePath, path);
if (!File.Exists(templatePath))
@ -26,7 +33,9 @@ namespace ln.templates.html
if (templateDocuments.ContainsKey(path))
templateDocuments.Remove(path);
throw new FileNotFoundException();
if (_throw)
throw new FileNotFoundException();
return null;
}
if (!templateDocuments.TryGetValue(path,out TemplateDocument templateDocument))

View File

@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<Version>0.1.0</Version>
<Version>0.1.1</Version>
<Authors>Harald Wolff-Thobaben</Authors>
<Company>l--n.de</Company>
<Description>A simple templating system</Description>