mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-08-02 18:17:30 +08:00
Add initial docs
This commit is contained in:

committed by
Patrik Svensson

parent
decb887b0a
commit
f1912b1d44
34
docs/src/Shortcodes/ChildrenShortcode.cs
Normal file
34
docs/src/Shortcodes/ChildrenShortcode.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using Statiq.Common;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Docs.Shortcodes
|
||||
{
|
||||
public class ChildrenShortcode : SyncShortcode
|
||||
{
|
||||
public override ShortcodeResult Execute(KeyValuePair<string, string>[] args, string content, IDocument document, IExecutionContext context)
|
||||
{
|
||||
var ul = new XElement("ul", new XAttribute("class", "list-group"));
|
||||
|
||||
foreach (var child in document.GetChildren().OnlyVisible())
|
||||
{
|
||||
var li = new XElement("li", new XAttribute("class", "list-group-item"));
|
||||
|
||||
var link = new XElement("a", new XAttribute("href", child.GetLink()));
|
||||
link.Add(child.GetTitle());
|
||||
li.Add(link);
|
||||
|
||||
var description = child.GetDescription();
|
||||
if (description.IsNotEmpty())
|
||||
{
|
||||
li.Add(new XElement("br"));
|
||||
li.Add(new XElement("i", description));
|
||||
}
|
||||
|
||||
ul.Add(li);
|
||||
}
|
||||
|
||||
return ul.ToString();
|
||||
}
|
||||
}
|
||||
}
|
59
docs/src/Shortcodes/ColorTableShortcode.cs
Normal file
59
docs/src/Shortcodes/ColorTableShortcode.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NJsonSchema;
|
||||
using Statiq.Common;
|
||||
using System.Xml.Linq;
|
||||
using Docs.Pipelines;
|
||||
using Docs.Models;
|
||||
|
||||
namespace Docs.Shortcodes
|
||||
{
|
||||
public class ColorTableShortcode : SyncShortcode
|
||||
{
|
||||
private const string ColorStyle = "display: inline-block;width: 60px; height: 15px;";
|
||||
|
||||
public override ShortcodeResult Execute(KeyValuePair<string, string>[] args, string content, IDocument document, IExecutionContext context)
|
||||
{
|
||||
// Get the definition.
|
||||
var colors = context.Outputs
|
||||
.FromPipeline(nameof(ColorsPipeline))
|
||||
.First()
|
||||
.GetChildren(Constants.Colors.Root)
|
||||
.OfType<ObjectDocument<List<Color>>>()
|
||||
.First().Object;
|
||||
|
||||
var table = new XElement("table", new XAttribute("class", "table"));
|
||||
var header = new XElement("tr", new XAttribute("class", "color-row"));
|
||||
header.Add(new XElement("th", ""));
|
||||
header.Add(new XElement("th", "Name"));
|
||||
header.Add(new XElement("th", "RGB"));
|
||||
header.Add(new XElement("th", "Hex"));
|
||||
header.Add(new XElement("th", "System.ConsoleColor"));
|
||||
table.Add(header);
|
||||
|
||||
foreach (var color in colors)
|
||||
{
|
||||
var rep = new XElement("td",
|
||||
new XElement("span",
|
||||
new XAttribute("class", "color-representation"),
|
||||
new XAttribute("style", $"background-color:{color.Hex};")));
|
||||
var name = new XElement("td", new XElement("code", color.Name.ToLower()));
|
||||
var rgb = new XElement("td", new XElement("code", $"{color.R},{color.G},{color.B}"));
|
||||
var hex = new XElement("td", new XElement("code", color.Hex));
|
||||
var clr = new XElement("td", new XElement("code", color.ClrName));
|
||||
|
||||
// Create row
|
||||
var row = new XElement("tr");
|
||||
row.Add(rep);
|
||||
row.Add(name);
|
||||
row.Add(rgb);
|
||||
row.Add(hex);
|
||||
row.Add(clr);
|
||||
table.Add(row);
|
||||
}
|
||||
|
||||
return table.ToString();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user