From 017f6563918c00a0967e10a9023ceda69072b686 Mon Sep 17 00:00:00 2001 From: Booklordofthedings Date: Wed, 30 Oct 2024 14:03:57 +0100 Subject: [PATCH] Initial --- .gitignore | 1 + BeefProj.toml | 6 + BeefSpace.toml | 5 + Example_Website/BeefProj.toml | 6 + Example_Website/src/Index.bf | 31 ++ Example_Website/src/Program.bf | 17 + README.md | 4 +- Rastergrafik.svg | 21 + favicon.ico | Bin 0 -> 270398 bytes src/.gitignore | 6 + src/Aven.bf | 8 + src/Builder.bf | 80 +++ src/HTML/HTML.bf | 905 +++++++++++++++++++++++++++++++++ src/Log.bf | 59 +++ src/Page.bf | 96 ++++ 15 files changed, 1243 insertions(+), 2 deletions(-) create mode 100644 BeefProj.toml create mode 100644 BeefSpace.toml create mode 100644 Example_Website/BeefProj.toml create mode 100644 Example_Website/src/Index.bf create mode 100644 Example_Website/src/Program.bf create mode 100644 Rastergrafik.svg create mode 100644 favicon.ico create mode 100644 src/.gitignore create mode 100644 src/Aven.bf create mode 100644 src/Builder.bf create mode 100644 src/HTML/HTML.bf create mode 100644 src/Log.bf create mode 100644 src/Page.bf diff --git a/.gitignore b/.gitignore index b4edfd0..ef8fab8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # ---> Beef +output/ build/ recovery/ BeefSpace_User.toml diff --git a/BeefProj.toml b/BeefProj.toml new file mode 100644 index 0000000..f85b838 --- /dev/null +++ b/BeefProj.toml @@ -0,0 +1,6 @@ +FileVersion = 1 + +[Project] +Name = "Aven" +TargetType = "BeefLib" +StartupObject = "Aven.Program" diff --git a/BeefSpace.toml b/BeefSpace.toml new file mode 100644 index 0000000..75221cf --- /dev/null +++ b/BeefSpace.toml @@ -0,0 +1,5 @@ +FileVersion = 1 +Projects = {Aven = {Path = "."}, Example_Website = {Path = "Example_Website"}} + +[Workspace] +StartupProject = "Example_Website" diff --git a/Example_Website/BeefProj.toml b/Example_Website/BeefProj.toml new file mode 100644 index 0000000..2536c45 --- /dev/null +++ b/Example_Website/BeefProj.toml @@ -0,0 +1,6 @@ +FileVersion = 1 +Dependencies = {corlib = "*", Aven = "*"} + +[Project] +Name = "Example_Website" +StartupObject = "Example_Website.Program" diff --git a/Example_Website/src/Index.bf b/Example_Website/src/Index.bf new file mode 100644 index 0000000..dfdedb7 --- /dev/null +++ b/Example_Website/src/Index.bf @@ -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;") + + + ); + } +} \ No newline at end of file diff --git a/Example_Website/src/Program.bf b/Example_Website/src/Program.bf new file mode 100644 index 0000000..d7bf1ff --- /dev/null +++ b/Example_Website/src/Program.bf @@ -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(); + + } +} \ No newline at end of file diff --git a/README.md b/README.md index 7882c20..0eca537 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# Aven +# Quil -Create HTML from Beef \ No newline at end of file +Write static websites dynamically \ No newline at end of file diff --git a/Rastergrafik.svg b/Rastergrafik.svg new file mode 100644 index 0000000..0fef9f1 --- /dev/null +++ b/Rastergrafik.svg @@ -0,0 +1,21 @@ + + + + + + + + + diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..7757aefcf23458c4ecf5662d840a3a38b4849d66 GIT binary patch literal 270398 zcmeI533yb+nuf!^FDeQM5<~=1!4+my1W`nUxeBN#xZ#F)0UuPnE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ON)xKW)W!5xlzcZB+XPIQDgH1P@Mw{+2WtzsD9yC2{QaK`}T00Izz00bZafxRHmy_9>> zOYyH&ivRtk_-B^lpVdA71zG8(_?HsE>?-l^&rXZ)pPSY_?ghDN>81F`58&>!_yOFV z7C(RmY4HPS{*B@V(3h4LH-P3JH-P4!mJ#m@%)fgn{&54CnU+>9-u>numr$1ZXT*7c z{L|z3XPbXKLh_GCNdEBxm@EJ8B?rLoABT`-khp~W{&50e8N^)40Vwh>IRMH4@d8lf zA146*`{M+l$iL(OWcn{CIgb?immGjB|NSKgAmCqO9>^}bzr-&H`j>>*pTPEvlD;75 zUs5J3N??0HdhAS8>|X++q6AhXGGad9FaOvf3?#4~5DY;<_s}QFC*U&tpYINb9rVuLLT7K)L)w5-|9Hu=|xD5iUF{MR?ku;r^LX7liv~?W2Eo)cxVM5}g3$^N&uT z@cUyVKxqDSrTNE5fUx^xBtW=-W)y((`Dc}Ke|D6AM%Wib0}l6(23S7-Xn^7OM*|G^ zj|LdwpBWj!2>+~7{Ig5(j{+3&{3t*X{!suT{G$Lw_(uVV^v{flK%{?GDgN1|_(uYW ze10T=NdHIxk^YeYBK;$OM56p7BIqJrLd^%Y0_o@ literal 0 HcmV?d00001 diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..ef8fab8 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,6 @@ +# ---> Beef +output/ +build/ +recovery/ +BeefSpace_User.toml + diff --git a/src/Aven.bf b/src/Aven.bf new file mode 100644 index 0000000..c75ee62 --- /dev/null +++ b/src/Aven.bf @@ -0,0 +1,8 @@ +namespace Aven; + +using System; + +class Aven +{ + public static readonly String Version = "0.1.0"; +} \ No newline at end of file diff --git a/src/Builder.bf b/src/Builder.bf new file mode 100644 index 0000000..74c8391 --- /dev/null +++ b/src/Builder.bf @@ -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 _Pages = new .() ~ DeleteDictionaryAndKeysAndValues!(_); + private List _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 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; + } +} \ No newline at end of file diff --git a/src/HTML/HTML.bf b/src/HTML/HTML.bf new file mode 100644 index 0000000..6217e8b --- /dev/null +++ b/src/HTML/HTML.bf @@ -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 _Classes = new .() ~ DeleteContainerAndItems!(_); + private List _Children = new .() ~ DeleteContainerAndItems!(_); + private bool _SelfClosing = false; //makes an object + private Dictionary _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 children) + { + _Body.Append(body); + for (var i in children) + _Children.Add(i); + } + + public void SetValue(StringView key, StringView value) + { + if (_Values.ContainsKeyAlt(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 $"\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 children) + { + var toReturn = new HTML(children: params children); + return toReturn; + } + + public static HTML Custom(StringView name, StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .(name); + return toReturn; + } + + + public static HTML Collapseable(HTML summary, params Span 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 children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("adress"); + return toReturn; + } + + public static HTML Article(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("article"); + return toReturn; + } + + public static HTML Aside(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("aside"); + return toReturn; + } + + public static HTML Footer(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("footer"); + return toReturn; + } + + public static HTML Header(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("header"); + return toReturn; + } + + + public static HTML H1(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("h1"); + return toReturn; + } + + public static HTML H2(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("h2"); + return toReturn; + } + + public static HTML H3(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("h3"); + return toReturn; + } + + public static HTML H4(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("h4"); + return toReturn; + } + + public static HTML H5(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("h5"); + return toReturn; + } + + public static HTML H6(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("h6"); + return toReturn; + } + + public static HTML HGroup(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("hgroup"); + return toReturn; + } + + public static HTML Main(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("main"); + return toReturn; + } + + public static HTML Nav(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("nav"); + return toReturn; + } + + public static HTML Section(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("section"); + return toReturn; + } + + public static HTML Search(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("search"); + return toReturn; + } + + public static HTML BlockQuote(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("blockquote"); + return toReturn; + } + + public static HTML Dd(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("dd"); + return toReturn; + } + + public static HTML Div(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("div"); + return toReturn; + } + + public static HTML Dl(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("dl"); + return toReturn; + } + + public static HTML Dt(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("dt"); + return toReturn; + } + + public static HTML Figcaption(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("figcaption"); + return toReturn; + } + + public static HTML Figure(StringView body = "", params Span 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 children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("li"); + return toReturn; + } + + public static HTML Menu(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("menu"); + return toReturn; + } + + public static HTML Ol(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("ol"); + return toReturn; + } + + public static HTML P(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("p"); + return toReturn; + } + + public static HTML Pre(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("pre"); + return toReturn; + } + + public static HTML Ul(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("ul"); + return toReturn; + } + + public static HTML A(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("a"); + return toReturn; + } + + public static HTML Abbr(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("abbr"); + return toReturn; + } + + public static HTML B(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("b"); + return toReturn; + } + + public static HTML Bdi(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("bdi"); + return toReturn; + } + + public static HTML Bdo(StringView body = "", params Span 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 children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("cite"); + return toReturn; + } + + public static HTML Code(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("code"); + return toReturn; + } + + public static HTML Data(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("data"); + return toReturn; + } + + public static HTML Dfn(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("dfn"); + return toReturn; + } + + public static HTML Em(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("em"); + return toReturn; + } + + public static HTML I(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("i"); + return toReturn; + } + + public static HTML Kdb(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("kdb"); + return toReturn; + } + + public static HTML Mark(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("mark"); + return toReturn; + } + + public static HTML Q(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("q"); + return toReturn; + } + + public static HTML Rp(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("rp"); + return toReturn; + } + + public static HTML Rt(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("rt"); + return toReturn; + } + + public static HTML Ruby(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("ruby"); + return toReturn; + } + + public static HTML S(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("s"); + return toReturn; + } + + public static HTML Samp(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("samp"); + return toReturn; + } + + public static HTML Small(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("small"); + return toReturn; + } + + public static HTML Span(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("span"); + return toReturn; + } + + public static HTML Strong(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("strong"); + return toReturn; + } + + public static HTML Sub(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("sub"); + return toReturn; + } + + public static HTML Sup(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("sup"); + return toReturn; + } + + public static HTML Time(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("time"); + return toReturn; + } + + public static HTML U(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("u"); + return toReturn; + } + + public static HTML Var(StringView body = "", params Span 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 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 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 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 children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("fencedframe"); + return toReturn; + } + + public static HTML IFrame(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("iframe"); + return toReturn; + } + + public static HTML Object(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("object"); + return toReturn; + } + + public static HTML Picture(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("picture"); + return toReturn; + } + + public static HTML Portal(StringView body = "", params Span 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 children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("svg"); + return toReturn; + } + + public static HTML Math(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("math"); + return toReturn; + } + + public static HTML Canvas(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("canvas"); + return toReturn; + } + + public static HTML NoScript(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("noscript"); + return toReturn; + } + + public static HTML Script(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("script"); + return toReturn; + } + + public static HTML Del(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("del"); + return toReturn; + } + + public static HTML Ins(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("ins"); + return toReturn; + } + + public static HTML Caption(StringView body = "", params Span 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 children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("colgroup"); + return toReturn; + } + + public static HTML Table(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("table"); + return toReturn; + } + + public static HTML TBody(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("tbody"); + return toReturn; + } + + public static HTML Td(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("td"); + return toReturn; + } + + public static HTML TFoot(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("tfoot"); + return toReturn; + } + + public static HTML Th(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("th"); + return toReturn; + } + + public static HTML THead(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("thead"); + return toReturn; + } + + public static HTML Tr(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("tr"); + return toReturn; + } + + public static HTML Button(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("button"); + return toReturn; + } + + public static HTML Datalist(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("datalist"); + return toReturn; + } + + public static HTML Fieldset(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("fieldset"); + return toReturn; + } + + public static HTML Form(StringView body = "", params Span 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 children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("label"); + return toReturn; + } + + public static HTML Legend(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("legend"); + return toReturn; + } + + public static HTML Meter(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("meter"); + return toReturn; + } + + public static HTML Optgroup(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("optgroup"); + return toReturn; + } + + public static HTML Option(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("option"); + return toReturn; + } + + public static HTML Output(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("output"); + return toReturn; + } + + public static HTML Progress(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("progress"); + return toReturn; + } + + public static HTML Select(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("select"); + return toReturn; + } + + public static HTML Textarea(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("textarea"); + return toReturn; + } + + public static HTML Details(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("details"); + return toReturn; + } + + public static HTML Dialog(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("dialog"); + return toReturn; + } + + public static HTML Summary(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("summary"); + return toReturn; + } + + public static HTML Slot(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("slot"); + return toReturn; + } + + public static HTML Template(StringView body = "", params Span children) + { + var toReturn = new HTML(body, params children); + toReturn.Name = .("template"); + return toReturn; + } +} \ No newline at end of file diff --git a/src/Log.bf b/src/Log.bf new file mode 100644 index 0000000..32a61e5 --- /dev/null +++ b/src/Log.bf @@ -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; + } +} \ No newline at end of file diff --git a/src/Page.bf b/src/Page.bf new file mode 100644 index 0000000..508ec73 --- /dev/null +++ b/src/Page.bf @@ -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 _Elements = new .() ~ DeleteContainerAndItems!(_); + private List _Scripts = new .() ~ DeleteContainerAndItems!(_); + private List _InlineStyle = new .() ~ DeleteContainerAndItems!(_); + private List _Styles = new .() ~ DeleteContainerAndItems!(_); + + + public StringView Title + { + get => _Title; + set + { + _Title.Clear(); + _Title.Append(value); + } + } + + public void AddElement(params Span elmt) + { + for(var i in elmt) + _Elements.Add(i); + } + + public void AddScripts(params Span scripts) + { + for(var i in scripts) + _Scripts.Add(new .(i)); + } + + public void AddStyles(params Span 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 $""" + + + + + {Title} + {BuildStyles(.. scope .())} + + + + {BuildElements(.. scope .())} + + + """); + } + + 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 $"\n"); + for(var i in _InlineStyle) + buffer.Append(scope $""" + + """); + } + + private void BuildScripts(String buffer) + { + for(var i in _Scripts) + buffer.Append(scope $"\n"); + } +} \ No newline at end of file