mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-08-03 10:27:58 +08:00
Update emoji support
* Add constants for emojis * Move emoji shortcode rendering to Markup * Add documentation * Add example * Add tests
This commit is contained in:

committed by
Patrik Svensson

parent
090b30f731
commit
eeb3f967b6
41
docs/src/Modules/ReadEmbedded.cs
Normal file
41
docs/src/Modules/ReadEmbedded.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Statiq.Common;
|
||||
|
||||
namespace Docs.Modules
|
||||
{
|
||||
public sealed class ReadEmbedded : Module
|
||||
{
|
||||
private readonly System.Reflection.Assembly _assembly;
|
||||
private readonly string _resource;
|
||||
|
||||
public ReadEmbedded(System.Reflection.Assembly assembly, string resource)
|
||||
{
|
||||
_assembly = assembly ?? throw new ArgumentNullException(nameof(assembly));
|
||||
_resource = resource ?? throw new ArgumentNullException(nameof(resource));
|
||||
}
|
||||
|
||||
protected override Task<IEnumerable<IDocument>> ExecuteContextAsync(IExecutionContext context)
|
||||
{
|
||||
return Task.FromResult((IEnumerable<IDocument>)new[]
|
||||
{
|
||||
context.CreateDocument(ReadResource()),
|
||||
});
|
||||
}
|
||||
|
||||
private Stream ReadResource()
|
||||
{
|
||||
var resourceName = _resource.Replace("/", ".");
|
||||
|
||||
var stream = _assembly.GetManifestResourceStream(resourceName);
|
||||
if (stream == null)
|
||||
{
|
||||
throw new InvalidOperationException("Could not load manifest resource stream.");
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user