Initial
This commit is contained in:
parent
ba7dcc6941
commit
017f656391
15 changed files with 1243 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
|||
# ---> Beef
|
||||
output/
|
||||
build/
|
||||
recovery/
|
||||
BeefSpace_User.toml
|
||||
|
|
6
BeefProj.toml
Normal file
6
BeefProj.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
FileVersion = 1
|
||||
|
||||
[Project]
|
||||
Name = "Aven"
|
||||
TargetType = "BeefLib"
|
||||
StartupObject = "Aven.Program"
|
5
BeefSpace.toml
Normal file
5
BeefSpace.toml
Normal file
|
@ -0,0 +1,5 @@
|
|||
FileVersion = 1
|
||||
Projects = {Aven = {Path = "."}, Example_Website = {Path = "Example_Website"}}
|
||||
|
||||
[Workspace]
|
||||
StartupProject = "Example_Website"
|
6
Example_Website/BeefProj.toml
Normal file
6
Example_Website/BeefProj.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
FileVersion = 1
|
||||
Dependencies = {corlib = "*", Aven = "*"}
|
||||
|
||||
[Project]
|
||||
Name = "Example_Website"
|
||||
StartupObject = "Example_Website.Program"
|
31
Example_Website/src/Index.bf
Normal file
31
Example_Website/src/Index.bf
Normal file
|
@ -0,0 +1,31 @@
|
|||
namespace Example_Website;
|
||||
|
||||
using System;
|
||||
|
||||
using Aven;
|
||||
using Aven.HTML;
|
||||
|
||||
class Index : Page
|
||||
{
|
||||
|
||||
public this() : base()
|
||||
{
|
||||
Title = scope $"Aven - {Aven.Version}";
|
||||
|
||||
this.AddInlineStyle("""
|
||||
body {
|
||||
margin:0px;
|
||||
}
|
||||
""");
|
||||
|
||||
this.AddElement(
|
||||
Div("",
|
||||
H1("Hello from Aven"),
|
||||
Raw("Aven is a website generation library, that can be used from"), A("Beef")..SetValue("href", "https://Beeflang.org"), Raw("to generate reuseable html."), Br(),
|
||||
Raw("By being integrated into a programming language you can freely write your own templating and generation logic"), Br()
|
||||
)..SetValue("style", "padding: 15px;")
|
||||
|
||||
|
||||
);
|
||||
}
|
||||
}
|
17
Example_Website/src/Program.bf
Normal file
17
Example_Website/src/Program.bf
Normal file
|
@ -0,0 +1,17 @@
|
|||
namespace Example_Website;
|
||||
|
||||
using System;
|
||||
|
||||
using Aven;
|
||||
|
||||
class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Builder b = scope .();
|
||||
b.OutputDirectory = "../output/";
|
||||
b.[Friend]_Pages.Add(new .("Index.html"),new Example_Website.Index());
|
||||
b.Build();
|
||||
|
||||
}
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
# Aven
|
||||
# Quil
|
||||
|
||||
Create HTML from Beef
|
||||
Write static websites dynamically
|
21
Rastergrafik.svg
Normal file
21
Rastergrafik.svg
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="210mm"
|
||||
height="297mm"
|
||||
viewBox="0 0 210 297"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<defs
|
||||
id="defs1" />
|
||||
<g
|
||||
id="layer1">
|
||||
<path
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
|
||||
d="M 118.65704,61.830325 C 68.476978,72.863108 46.783808,116.69898 27.519855,163.33213 93.392424,122.66883 109.32063,115.22131 171.19494,121.87364 187.26567,66.843752 172.66212,52.581957 118.65704,61.830325 Z"
|
||||
id="path1" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 746 B |
BIN
favicon.ico
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 264 KiB |
6
src/.gitignore
vendored
Normal file
6
src/.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
# ---> Beef
|
||||
output/
|
||||
build/
|
||||
recovery/
|
||||
BeefSpace_User.toml
|
||||
|
8
src/Aven.bf
Normal file
8
src/Aven.bf
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Aven;
|
||||
|
||||
using System;
|
||||
|
||||
class Aven
|
||||
{
|
||||
public static readonly String Version = "0.1.0";
|
||||
}
|
80
src/Builder.bf
Normal file
80
src/Builder.bf
Normal file
|
@ -0,0 +1,80 @@
|
|||
namespace Aven;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
|
||||
/**
|
||||
The builder is the core object for the page generation
|
||||
it houses most of the configuration object and it acts
|
||||
as a storage for all of the other pages.
|
||||
*/
|
||||
class Builder
|
||||
{
|
||||
private Dictionary<String, Page> _Pages = new .() ~ DeleteDictionaryAndKeysAndValues!(_);
|
||||
private List<String> _InputDirectories = new .() ~ DeleteContainerAndItems!(_);
|
||||
|
||||
private String _OutputDirectory = new .("") ~ delete _;
|
||||
public StringView OutputDirectory
|
||||
{
|
||||
get => _OutputDirectory;
|
||||
set
|
||||
{
|
||||
_OutputDirectory.Clear();
|
||||
_OutputDirectory.Append(value);
|
||||
}
|
||||
}
|
||||
|
||||
///Copies over a folder into the output directory
|
||||
public void AddFolder(StringView folder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates all of the website files and writes them to the output location
|
||||
*/
|
||||
public void Build()
|
||||
{
|
||||
|
||||
Log.Info("Starting build");
|
||||
|
||||
//First validate everything, so that we dont do a bunch of work for nothing
|
||||
if(_OutputDirectory == String.Empty)
|
||||
{
|
||||
Log.Error("No output directory specified. Cannot build");
|
||||
return;
|
||||
}
|
||||
|
||||
for(var entry in _Pages)
|
||||
{
|
||||
Log.Debug(scope $"Attempting to build: {_OutputDirectory}{entry.key}");
|
||||
var output = entry.value.Build(.. scope .());
|
||||
if(WriteFile(scope $"{_OutputDirectory}{entry.key}", output) case .Ok)
|
||||
Log.Info(scope $"Sucessfully build page: {entry.key}");
|
||||
else
|
||||
Log.Error("Unable to build page");
|
||||
}
|
||||
}
|
||||
private Result<void> WriteFile(StringView target, StringView toWrite)
|
||||
{
|
||||
|
||||
var targetDir = target.Substring(0, target.LastIndexOf('/'));
|
||||
if(!Directory.Exists(targetDir))
|
||||
{
|
||||
Log.Debug(scope $"Target directory does not exist, attempting to create: {targetDir}");
|
||||
if(Directory.CreateDirectory(targetDir) case .Err)
|
||||
{
|
||||
Log.Debug("Unable to create target directory");
|
||||
return .Err;
|
||||
}
|
||||
}
|
||||
|
||||
if(File.WriteAllText(target, toWrite) case .Err)
|
||||
{
|
||||
Log.Debug("Unable to write file");
|
||||
return .Err;
|
||||
}
|
||||
return .Ok;
|
||||
}
|
||||
}
|
905
src/HTML/HTML.bf
Normal file
905
src/HTML/HTML.bf
Normal file
|
@ -0,0 +1,905 @@
|
|||
namespace Aven.HTML;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
class HTML
|
||||
{
|
||||
private String _Name = new .("") ~ delete _;
|
||||
private String _Body = new .("") ~ delete _;
|
||||
private String _Id = new .("") ~ delete _;
|
||||
private HashSet<String> _Classes = new .() ~ DeleteContainerAndItems!(_);
|
||||
private List<HTML> _Children = new .() ~ DeleteContainerAndItems!(_);
|
||||
private bool _SelfClosing = false; //makes an object <name />
|
||||
private Dictionary<String, String> _Values = new .() ~ DeleteDictionaryAndKeysAndValues!(_); //Most of these values should come from fields
|
||||
//This is just used to allow arbitrary values for stuff ive missed
|
||||
|
||||
public StringView Name
|
||||
{
|
||||
get => _Name;
|
||||
set
|
||||
{
|
||||
_Name.Clear();
|
||||
_Name.Append(value);
|
||||
}
|
||||
}
|
||||
|
||||
public StringView Body
|
||||
{
|
||||
get => _Body;
|
||||
set
|
||||
{
|
||||
_Body.Clear();
|
||||
_Body.Append(value);
|
||||
}
|
||||
}
|
||||
|
||||
public StringView Id
|
||||
{
|
||||
get => _Id;
|
||||
set
|
||||
{
|
||||
_Id.Clear();
|
||||
_Id.Append(value);
|
||||
}
|
||||
}
|
||||
|
||||
public this(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
_Body.Append(body);
|
||||
for (var i in children)
|
||||
_Children.Add(i);
|
||||
}
|
||||
|
||||
public void SetValue(StringView key, StringView value)
|
||||
{
|
||||
if (_Values.ContainsKeyAlt<StringView>(key))
|
||||
_Values[scope .(key)]..Clear().Append(value);
|
||||
else
|
||||
_Values.Add(new .(key), new .(value));
|
||||
}
|
||||
|
||||
public void AddClass(StringView clas) => _Classes.Add(new .(clas));
|
||||
|
||||
public void RemoveClass(StringView clas) => _Classes.Remove(scope .(clas));
|
||||
|
||||
public void Build(String buffer)
|
||||
{
|
||||
if (_SelfClosing && _Name != "")
|
||||
{
|
||||
buffer.Append(scope $"<{Name} {CalculateValues(.. scope .())} />");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (Name != "")
|
||||
buffer.Append(scope $"<{Name} {CalculateValues(.. scope .())}>\n");
|
||||
|
||||
if (_Body != .Empty)
|
||||
buffer.Append(_Body);
|
||||
|
||||
for (var i in _Children)
|
||||
i.Build(buffer);
|
||||
|
||||
if (Name != "")
|
||||
buffer.Append(scope $"</{Name}>\n");
|
||||
}
|
||||
|
||||
private void CalculateValues(String buffer)
|
||||
{
|
||||
if(_Id != .Empty)
|
||||
buffer.Append(scope $"id=\"{_Id}\"");
|
||||
for(var i in _Values)
|
||||
{
|
||||
buffer.Append(scope $"{i.key}=\"{i.value}\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
public static HTML Raw(StringView body = "")
|
||||
{
|
||||
var toReturn = new HTML(body);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Empty(params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(children: params children);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Custom(StringView name, StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .(name);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
public static HTML Collapseable(HTML summary, params Span<HTML> details)
|
||||
{
|
||||
var toReturn = new HTML();
|
||||
toReturn.Name = .("details");
|
||||
|
||||
var sum = new HTML(children: summary);
|
||||
sum.Name = .("summary");
|
||||
toReturn.[Friend]_Children.Add(sum);
|
||||
for(var i in details)
|
||||
toReturn.[Friend]_Children.Add(i);
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Adress(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("adress");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Article(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("article");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Aside(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("aside");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Footer(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("footer");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Header(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("header");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
public static HTML H1(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("h1");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML H2(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("h2");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML H3(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("h3");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML H4(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("h4");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML H5(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("h5");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML H6(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("h6");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML HGroup(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("hgroup");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Main(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("main");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Nav(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("nav");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Section(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("section");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Search(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("search");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML BlockQuote(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("blockquote");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Dd(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("dd");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Div(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("div");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Dl(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("dl");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Dt(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("dt");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Figcaption(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("figcaption");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Figure(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("figure");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Hr()
|
||||
{
|
||||
var toReturn = new HTML();
|
||||
toReturn.[Friend]_SelfClosing = true;
|
||||
toReturn.Name = .("hr");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Li(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("li");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Menu(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("menu");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Ol(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("ol");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML P(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("p");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Pre(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("pre");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Ul(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("ul");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML A(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("a");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Abbr(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("abbr");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML B(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("b");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Bdi(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("bdi");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Bdo(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("bdo");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Br()
|
||||
{
|
||||
var toReturn = new HTML();
|
||||
toReturn.[Friend]_SelfClosing = true;
|
||||
toReturn.Name = .("br");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Cite(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("cite");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Code(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("code");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Data(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("data");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Dfn(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("dfn");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Em(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("em");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML I(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("i");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Kdb(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("kdb");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Mark(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("mark");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Q(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("q");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Rp(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("rp");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Rt(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("rt");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Ruby(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("ruby");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML S(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("s");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Samp(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("samp");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Small(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("small");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Span(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("span");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Strong(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("strong");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Sub(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("sub");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Sup(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("sup");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Time(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("time");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML U(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("u");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Var(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("var");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Wbr()
|
||||
{
|
||||
var toReturn = new HTML();
|
||||
toReturn.[Friend]_SelfClosing = true;
|
||||
toReturn.Name = .("wbr");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Area()
|
||||
{
|
||||
var toReturn = new HTML();
|
||||
toReturn.[Friend]_SelfClosing = true;
|
||||
toReturn.Name = .("area");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Audio(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("audio");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Img(StringView src = "", int64 width = -1, int64 height = -1, StringView alt = "")
|
||||
{
|
||||
var toReturn = new HTML();
|
||||
toReturn.[Friend]_SelfClosing = true;
|
||||
if(src != "") toReturn.SetValue("src", src);
|
||||
if(alt != "") toReturn.SetValue("alt", alt);
|
||||
if(width > 0) toReturn.SetValue("width", width.ToString(.. scope .()));
|
||||
if(height > 0) toReturn.SetValue("height", height.ToString(.. scope .()));
|
||||
toReturn.Name = .("img");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Map(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("map");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Track()
|
||||
{
|
||||
var toReturn = new HTML();
|
||||
toReturn.[Friend]_SelfClosing = true;
|
||||
toReturn.Name = .("track");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Video(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("video");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Embed()
|
||||
{
|
||||
var toReturn = new HTML();
|
||||
toReturn.[Friend]_SelfClosing = true;
|
||||
toReturn.Name = .("embed");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Fencedframe(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("fencedframe");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML IFrame(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("iframe");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Object(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("object");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Picture(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("picture");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Portal(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("portal");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Source()
|
||||
{
|
||||
var toReturn = new HTML();
|
||||
toReturn.[Friend]_SelfClosing = true;
|
||||
toReturn.Name = .("source");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Svg(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("svg");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Math(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("math");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Canvas(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("canvas");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML NoScript(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("noscript");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Script(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("script");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Del(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("del");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Ins(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("ins");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Caption(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("caption");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Col()
|
||||
{
|
||||
var toReturn = new HTML();
|
||||
toReturn.[Friend]_SelfClosing = true;
|
||||
toReturn.Name = .("col");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Colgroup(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("colgroup");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Table(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("table");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML TBody(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("tbody");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Td(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("td");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML TFoot(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("tfoot");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Th(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("th");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML THead(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("thead");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Tr(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("tr");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Button(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("button");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Datalist(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("datalist");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Fieldset(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("fieldset");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Form(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("form");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Input()
|
||||
{
|
||||
var toReturn = new HTML();
|
||||
toReturn.[Friend]_SelfClosing = true;
|
||||
toReturn.Name = .("input");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Label(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("label");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Legend(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("legend");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Meter(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("meter");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Optgroup(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("optgroup");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Option(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("option");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Output(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("output");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Progress(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("progress");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Select(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("select");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Textarea(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("textarea");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Details(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("details");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Dialog(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("dialog");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Summary(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("summary");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Slot(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("slot");
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static HTML Template(StringView body = "", params Span<HTML> children)
|
||||
{
|
||||
var toReturn = new HTML(body, params children);
|
||||
toReturn.Name = .("template");
|
||||
return toReturn;
|
||||
}
|
||||
}
|
59
src/Log.bf
Normal file
59
src/Log.bf
Normal file
|
@ -0,0 +1,59 @@
|
|||
namespace Aven;
|
||||
|
||||
using System;
|
||||
|
||||
/*
|
||||
A very basic logging implementation, future implementations can use this interface but be better
|
||||
*/
|
||||
class Log
|
||||
{
|
||||
public enum LogLevel
|
||||
{
|
||||
Trace,
|
||||
Debug,
|
||||
Info,
|
||||
Warn,
|
||||
Error
|
||||
}
|
||||
|
||||
public static LogLevel LogLevel
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = .Debug;
|
||||
|
||||
public static void Trace(StringView message)
|
||||
{
|
||||
Console.ForegroundColor = .Cyan;
|
||||
Console.WriteLine(scope $"[Trace]:{message}");
|
||||
Console.ForegroundColor = .White;
|
||||
}
|
||||
|
||||
public static void Debug(StringView message)
|
||||
{
|
||||
Console.ForegroundColor = .Yellow;
|
||||
Console.WriteLine(scope $"[Debug]:{message}");
|
||||
Console.ForegroundColor = .White;
|
||||
}
|
||||
|
||||
public static void Info(StringView message)
|
||||
{
|
||||
Console.ForegroundColor = .Green;
|
||||
Console.WriteLine(scope $"[Info]:{message}");
|
||||
Console.ForegroundColor = .White;
|
||||
}
|
||||
|
||||
public static void Error(StringView message)
|
||||
{
|
||||
Console.ForegroundColor = .DarkYellow;
|
||||
Console.WriteLine(scope $"[Error]:{message}");
|
||||
Console.ForegroundColor = .White;
|
||||
}
|
||||
|
||||
public static void Fatal(StringView message)
|
||||
{
|
||||
Console.ForegroundColor = .Red;
|
||||
Console.WriteLine(scope $"[Fatal]:{message}");
|
||||
Console.ForegroundColor = .White;
|
||||
}
|
||||
}
|
96
src/Page.bf
Normal file
96
src/Page.bf
Normal file
|
@ -0,0 +1,96 @@
|
|||
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");
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue