Skip to content

Commit

Permalink
Prepare for release 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat committed Apr 13, 2019
1 parent 483dfe8 commit 47561c9
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 19 deletions.
6 changes: 3 additions & 3 deletions API/GenHTTP.API/GenHTTP.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<LangVersion>8.0</LangVersion>
<NullableContextOptions>enable</NullableContextOptions>

<AssemblyVersion>2.1.0.0</AssemblyVersion>
<FileVersion>2.1.0.0</FileVersion>
<Version>2.1.0</Version>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
<FileVersion>2.2.0.0</FileVersion>
<Version>2.2.0</Version>

<Authors>Andreas Nägeli</Authors>
<Company />
Expand Down
10 changes: 10 additions & 0 deletions API/GenHTTP.API/Modules/IResourceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ namespace GenHTTP.Api.Modules
public interface IResourceProvider
{

/// <summary>
/// Specifies, whether a consumer of this resource is allowed to
/// cache content derived from the resource.
/// </summary>
/// <remarks>
/// For content which may change externally (e.g. files), this property
/// should return <code>false</code>.
/// </remarks>
bool AllowCache { get; }

/// <summary>
/// Returns the read-only stream of the resource to be accessed.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions Core/GenHTTP.Core/GenHTTP.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<LangVersion>8.0</LangVersion>
<NullableContextOptions>enable</NullableContextOptions>

<AssemblyVersion>2.1.0.0</AssemblyVersion>
<FileVersion>2.1.0.0</FileVersion>
<Version>2.1.0</Version>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
<FileVersion>2.2.0.0</FileVersion>
<Version>2.2.0</Version>

<Authors>Andreas Nägeli</Authors>
<Company />
Expand Down
6 changes: 3 additions & 3 deletions Modules/GenHTTP.Modules.Core/GenHTTP.Modules.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<LangVersion>8.0</LangVersion>
<NullableContextOptions>enable</NullableContextOptions>

<AssemblyVersion>2.1.0.0</AssemblyVersion>
<FileVersion>2.1.0.0</FileVersion>
<Version>2.1.0</Version>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
<FileVersion>2.2.0.0</FileVersion>
<Version>2.2.0</Version>

<Authors>Andreas Nägeli</Authors>
<Company />
Expand Down
2 changes: 2 additions & 0 deletions Modules/GenHTTP.Modules.Core/Resource/FileDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class FileDataProvider : IResourceProvider

public FileInfo File { get; }

public bool AllowCache => false;

#endregion

#region Initialization
Expand Down
2 changes: 2 additions & 0 deletions Modules/GenHTTP.Modules.Core/Resource/ResourceDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class ResourceDataProvider : IResourceProvider

public string QualifiedName { get; }

public bool AllowCache => true;

#endregion

#region Initialization
Expand Down
2 changes: 2 additions & 0 deletions Modules/GenHTTP.Modules.Core/Resource/StringDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class StringDataProvider : IResourceProvider

public string Content { get; }

public bool AllowCache => true;

#endregion

#region Initialization
Expand Down
19 changes: 18 additions & 1 deletion Modules/GenHTTP.Modules.Core/Templating/PlaceholderRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class PlaceholderRender<T> : IRenderer<T> where T : IBaseModel
{
private readonly static Regex PLACEHOLDER = new Regex(@"\[([a-zA-Z0-9]+)\]");

private string? _Template;

#region Get-/Setters

public IResourceProvider TemplateProvider { get; }
Expand All @@ -33,7 +35,7 @@ public PlaceholderRender(IResourceProvider templateProvider)

public string Render(T model)
{
var template = TemplateProvider.GetResourceAsString();
var template = GetTemplate();

var flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase;

Expand All @@ -52,6 +54,21 @@ public string Render(T model)
});
}

private string GetTemplate()
{
if (TemplateProvider.AllowCache)
{
return _Template ?? (_Template = LoadTemplate());
}

return LoadTemplate();
}

private string LoadTemplate()
{
return TemplateProvider.GetResourceAsString();
}

#endregion

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<LangVersion>8.0</LangVersion>
<NullableContextOptions>enable</NullableContextOptions>

<AssemblyVersion>2.1.0.0</AssemblyVersion>
<FileVersion>2.1.0.0</FileVersion>
<Version>2.1.0</Version>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
<FileVersion>2.2.0.0</FileVersion>
<Version>2.2.0</Version>

<Authors>Andreas Nägeli</Authors>
<Company />
Expand Down
8 changes: 5 additions & 3 deletions Modules/GenHTTP.Modules.Scriban/ScribanPageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class ScribanPageProvider<T> : IContentProvider where T : PageModel

public ModelProvider<T> ModelProvider { get; }

public ScribanRenderer<T> Renderer { get; }

public string? Title { get; }

#endregion
Expand All @@ -33,6 +35,8 @@ public ScribanPageProvider(IResourceProvider templateProvider, ModelProvider<T>
TemplateProvider = templateProvider;
ModelProvider = modelProvider;
Title = title;

Renderer = new ScribanRenderer<T>(TemplateProvider);
}

#endregion
Expand All @@ -43,11 +47,9 @@ public IResponseBuilder Handle(IRequest request)
{
if (request.HasType(RequestMethod.HEAD, RequestMethod.GET, RequestMethod.POST))
{
var renderer = new ScribanRenderer<T>(TemplateProvider);

var model = ModelProvider(request);

var content = renderer.Render(model);
var content = Renderer.Render(model);

var templateModel = new TemplateModel(request, model.Title ?? Title ?? "Untitled Page", content);

Expand Down
20 changes: 17 additions & 3 deletions Modules/GenHTTP.Modules.Scriban/ScribanRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace GenHTTP.Modules.Scriban

public class ScribanRenderer<T> : IRenderer<T> where T : IBaseModel
{
private Template? _Template;

#region Get-/Setters

Expand All @@ -34,9 +35,7 @@ public ScribanRenderer(IResourceProvider templateProvider)

public string Render(T model)
{
var content = TemplateProvider.GetResourceAsString();

var template = Template.Parse(content);
var template = GetTemplate();

var obj = new ScriptObject();

Expand All @@ -46,6 +45,21 @@ public string Render(T model)
return template.Render(obj);
}

private Template GetTemplate()
{
if (TemplateProvider.AllowCache)
{
return _Template ?? (_Template = LoadTemplate());
}

return LoadTemplate();
}

private Template LoadTemplate()
{
return Template.Parse(TemplateProvider.GetResourceAsString());
}

#endregion

}
Expand Down

0 comments on commit 47561c9

Please sign in to comment.