-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5af1f91
commit 935f7ab
Showing
12 changed files
with
229 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Threading.Tasks; | ||
using GenHTTP.Api.Content; | ||
using GenHTTP.Api.Content.IO; | ||
|
||
namespace GenHTTP.Modules.AutoLayout | ||
{ | ||
|
||
public interface IResourceHandlerProvider | ||
{ | ||
|
||
public bool Supports(IResource resource); | ||
|
||
ValueTask<IHandlerBuilder> GetHandlerAsync(IResource resource); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Threading.Tasks; | ||
using GenHTTP.Api.Content; | ||
using GenHTTP.Api.Content.IO; | ||
using GenHTTP.Modules.IO; | ||
|
||
namespace GenHTTP.Modules.AutoLayout.Provider | ||
{ | ||
|
||
public class DownloadProvider : IResourceHandlerProvider | ||
{ | ||
|
||
public bool Supports(IResource resource) => true; | ||
|
||
public ValueTask<IHandlerBuilder> GetHandlerAsync(IResource resource) => new(Content.From(resource)); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using GenHTTP.Api.Content; | ||
using GenHTTP.Api.Content.IO; | ||
using GenHTTP.Api.Protocol; | ||
using GenHTTP.Modules.Basics; | ||
using GenHTTP.Modules.Markdown; | ||
|
||
namespace GenHTTP.Modules.AutoLayout.Provider | ||
{ | ||
|
||
public class MarkdownProvider : IResourceHandlerProvider | ||
{ | ||
|
||
public bool Supports(IResource resource) => (resource.ContentType?.KnownType ?? resource.Name?.GuessContentType()) == ContentType.TextMarkdown; | ||
|
||
public ValueTask<IHandlerBuilder> GetHandlerAsync(IResource resource) | ||
{ | ||
return new(ModMarkdown.Page(resource)); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Threading.Tasks; | ||
|
||
using GenHTTP.Api.Content; | ||
using GenHTTP.Api.Content.IO; | ||
using GenHTTP.Api.Protocol; | ||
|
||
using GenHTTP.Modules.Basics; | ||
using GenHTTP.Modules.Scriban; | ||
|
||
namespace GenHTTP.Modules.AutoLayout.Provider | ||
{ | ||
|
||
public class ScribanProvider : IResourceHandlerProvider | ||
{ | ||
|
||
public bool Supports(IResource resource) => (resource.ContentType?.KnownType ?? resource.Name?.GuessContentType()) == ContentType.TextScriban; | ||
|
||
public ValueTask<IHandlerBuilder> GetHandlerAsync(IResource resource) | ||
{ | ||
return new(ModScriban.Page(resource)); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using GenHTTP.Modules.AutoLayout.Provider; | ||
using GenHTTP.Modules.AutoLayout.Scanning; | ||
|
||
namespace GenHTTP.Modules.AutoLayout | ||
{ | ||
|
||
public static class Resolvers | ||
{ | ||
|
||
public static HandlerRegistryBuilder Default() | ||
{ | ||
return new HandlerRegistryBuilder().Fallback(new DownloadProvider()) | ||
.Add(new MarkdownProvider()) | ||
.Add(new ScribanProvider()); | ||
} | ||
|
||
public static HandlerRegistryBuilder Empty() => new(); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
using GenHTTP.Api.Content; | ||
using GenHTTP.Api.Content.IO; | ||
|
||
namespace GenHTTP.Modules.AutoLayout.Scanning | ||
{ | ||
|
||
public class HandlerRegistry | ||
{ | ||
|
||
#region Get-/Setters | ||
|
||
public List<IResourceHandlerProvider> Providers { get; } | ||
|
||
public IResourceHandlerProvider Fallback { get; } | ||
|
||
#endregion | ||
|
||
#region Initialization | ||
|
||
public HandlerRegistry(List<IResourceHandlerProvider> providers, IResourceHandlerProvider fallback) | ||
{ | ||
Providers = providers; | ||
Fallback = fallback; | ||
} | ||
|
||
#endregion | ||
|
||
#region Functionality | ||
|
||
public async ValueTask<IHandlerBuilder> ResolveAsync(IResource resource) | ||
{ | ||
foreach (var provider in Providers) | ||
{ | ||
if (provider.Supports(resource)) | ||
{ | ||
return await provider.GetHandlerAsync(resource); | ||
} | ||
} | ||
|
||
if (!Fallback.Supports(resource)) | ||
{ | ||
throw new InvalidOperationException($"Fallback cannot handle resource '{resource.Name}'"); | ||
} | ||
|
||
return await Fallback.GetHandlerAsync(resource); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.Generic; | ||
|
||
using GenHTTP.Api.Infrastructure; | ||
|
||
namespace GenHTTP.Modules.AutoLayout.Scanning | ||
{ | ||
|
||
public class HandlerRegistryBuilder : IBuilder<HandlerRegistry> | ||
{ | ||
private readonly List<IResourceHandlerProvider> _Providers = new(); | ||
|
||
private IResourceHandlerProvider? _Fallback; | ||
|
||
#region Functionality | ||
|
||
public HandlerRegistryBuilder Add(IResourceHandlerProvider provider) | ||
{ | ||
_Providers.Add(provider); | ||
return this; | ||
} | ||
|
||
public HandlerRegistryBuilder Fallback(IResourceHandlerProvider provider) | ||
{ | ||
_Fallback = provider; | ||
return this; | ||
} | ||
|
||
public HandlerRegistry Build() | ||
{ | ||
return new HandlerRegistry(_Providers, _Fallback ?? throw new BuilderMissingPropertyException("fallback")); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters