96 lines
No EOL
1.8 KiB
Beef
96 lines
No EOL
1.8 KiB
Beef
namespace Aven;
|
|
using Aven.HTML;
|
|
|
|
using System;
|
|
using System.Collections;
|
|
|
|
/**
|
|
An instance of this class represents a single .html website
|
|
*/
|
|
abstract class Page
|
|
{
|
|
private String _Title = new .("") ~ delete _;
|
|
private List<HTML> _Elements = new .() ~ DeleteContainerAndItems!(_);
|
|
private List<String> _Scripts = new .() ~ DeleteContainerAndItems!(_);
|
|
private List<String> _InlineStyle = new .() ~ DeleteContainerAndItems!(_);
|
|
private List<String> _Styles = new .() ~ DeleteContainerAndItems!(_);
|
|
|
|
|
|
public StringView Title
|
|
{
|
|
get => _Title;
|
|
set
|
|
{
|
|
_Title.Clear();
|
|
_Title.Append(value);
|
|
}
|
|
}
|
|
|
|
public void AddElement(params Span<HTML> elmt)
|
|
{
|
|
for(var i in elmt)
|
|
_Elements.Add(i);
|
|
}
|
|
|
|
public void AddScripts(params Span<StringView> scripts)
|
|
{
|
|
for(var i in scripts)
|
|
_Scripts.Add(new .(i));
|
|
}
|
|
|
|
public void AddStyles(params Span<StringView> styles)
|
|
{
|
|
for(var i in styles)
|
|
_Styles.Add(new .(i));
|
|
}
|
|
|
|
public void AddInlineStyle(StringView style)
|
|
{
|
|
_InlineStyle.Add(new .(style));
|
|
}
|
|
|
|
public void Build(String buffer)
|
|
{
|
|
buffer.Append(scope $"""
|
|
<!Doctype HTML>
|
|
<!-- Made with Quill version 0.1 -->
|
|
<html>
|
|
<head>
|
|
<title>{Title}</title>
|
|
{BuildStyles(.. scope .())}
|
|
|
|
</head>
|
|
<body>
|
|
{BuildElements(.. scope .())}
|
|
</body>
|
|
</html>
|
|
""");
|
|
}
|
|
|
|
private void BuildElements(String buffer)
|
|
{
|
|
for(var i in _Elements)
|
|
{
|
|
i.Build(buffer);
|
|
buffer.Append("\n");
|
|
}
|
|
}
|
|
|
|
private void BuildStyles(String buffer)
|
|
{
|
|
for(var i in _Styles)
|
|
buffer.Append(scope $"<link rel=\"stylesheet\" href=\"{i}\" />\n");
|
|
for(var i in _InlineStyle)
|
|
buffer.Append(scope $"""
|
|
<style>
|
|
{i}
|
|
</style>
|
|
""");
|
|
}
|
|
|
|
private void BuildScripts(String buffer)
|
|
{
|
|
for(var i in _Scripts)
|
|
buffer.Append(scope $"<script src=\"{i}\"></script>\n");
|
|
}
|
|
} |