From 1fbb94e9a2892a47b82aa693e727c0c6b4de4283 Mon Sep 17 00:00:00 2001 From: Booklordofthedings Date: Thu, 28 Nov 2024 12:24:54 +0100 Subject: [PATCH] changes --- BeefManaged.toml | 6 + Example_Website/src/Index.bf | 21 +- Example_Website/src/Program.bf | 9 +- src/.gitignore | 6 - src/Aven.bf | 88 +++- src/Builder.bf | 88 ---- src/HTML.bf | 917 +++++++++++++++++++++++++++++++++ src/HTML/HTML.bf | 914 -------------------------------- src/Internal/Builder.bf | 23 + src/Internal/Logger.bf | 41 ++ src/Internal/Page.bf | 73 +++ src/Log.bf | 59 --- src/Page.bf | 76 +-- 13 files changed, 1171 insertions(+), 1150 deletions(-) create mode 100644 BeefManaged.toml delete mode 100644 src/.gitignore delete mode 100644 src/Builder.bf create mode 100644 src/HTML.bf delete mode 100644 src/HTML/HTML.bf create mode 100644 src/Internal/Builder.bf create mode 100644 src/Internal/Logger.bf create mode 100644 src/Internal/Page.bf delete mode 100644 src/Log.bf diff --git a/BeefManaged.toml b/BeefManaged.toml new file mode 100644 index 0000000..548aaac --- /dev/null +++ b/BeefManaged.toml @@ -0,0 +1,6 @@ +FileVersion = 1 +Version = "" +GitURL = "https://code.booklordofthe.dev/Booklordofthedings/Aven" +GitTag = "" +GitHash = "c987948d019ca245b0ad1a65a31f8efc38701989" +Setup = true diff --git a/Example_Website/src/Index.bf b/Example_Website/src/Index.bf index dfdedb7..f7f9fa2 100644 --- a/Example_Website/src/Index.bf +++ b/Example_Website/src/Index.bf @@ -8,6 +8,17 @@ using Aven.HTML; class Index : Page { + public override void LoadPageContents() + { + this.AddElement( + Div("Content aisjdoasjiodashuihnsduijhnuisdhfsd", + 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;") + ); + } + public this() : base() { Title = scope $"Aven - {Aven.Version}"; @@ -18,14 +29,6 @@ class Index : Page } """); - 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 index d7bf1ff..85eeb9f 100644 --- a/Example_Website/src/Program.bf +++ b/Example_Website/src/Program.bf @@ -8,10 +8,9 @@ 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(); - + Aven aven = scope .(); + aven.Pages.Add(scope Example_Website.Index()); + aven.OutputDirectory = "../output/"; + aven.Build(); } } \ No newline at end of file diff --git a/src/.gitignore b/src/.gitignore deleted file mode 100644 index ef8fab8..0000000 --- a/src/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -# ---> Beef -output/ -build/ -recovery/ -BeefSpace_User.toml - diff --git a/src/Aven.bf b/src/Aven.bf index c75ee62..708fa77 100644 --- a/src/Aven.bf +++ b/src/Aven.bf @@ -1,8 +1,94 @@ namespace Aven; using System; +using System.IO; +using System.Collections; class Aven { - public static readonly String Version = "0.1.0"; + private static readonly Logger _defaultLogger = new .() ~ delete _; + private static readonly Builder _defaultBuilder = new .() ~ delete _; + + public static readonly String Version = "0.5.0"; + + private Dictionary _dirs = new .() ~ DeleteDictionaryAndKeysAndValues!(_); + private Dictionary _files = new .() ~ DeleteDictionaryAndKeysAndValues!(_); + + + public List Pages = new .(10) ~ delete _; + public Logger Log = _defaultLogger; + public Builder Builder = _defaultBuilder; + public String OutputDirectory = null; + + ///Copy a directory to the output directory + public Result IncludeDirInOutput(StringView dir, StringView outdir) + { + if(!Directory.Exists(dir)) + return .Err; + _dirs.Add(new .(dir), new .(outdir)); + return .Ok; + } + + ///Copy a file to the output directory + public Result IncludeFileInOutput(StringView dir, StringView outdir) + { + if(!File.Exists(dir)) + return .Err; + _files.Add(new .(dir), new .(outdir)); + return .Ok; + } + + ///Builds the website + public void Build() + { + Log.Info(scope $"Starting Aven {Version}"); + Log.Info("Start building"); + + if(!EnsureOutputExists()) + return; + + Builder.Build(this); + + Log.Info("Successfully build"); + } + + ///Writes a file to the location specified by output + private Result WriteToOutput(StringView file, StringView data) + { + String outdir = scope .(); + if (Path.GetDirectoryPath(scope $"{OutputDirectory}/{file}", outdir) case .Ok) + { + if (Directory.CreateDirectory(outdir) case .Ok) + { + if(File.WriteAllText(scope $"{OutputDirectory}/{file}", data) case .Ok) + { + Log.Info(scope $"Wrote file to {OutputDirectory}/{file}"); + } + } + } + Log.Error(scope $"Attempt to write to {OutputDirectory}/{file} failed"); + return .Err; + } + + private bool EnsureOutputExists() + { + if(OutputDirectory == null) + { + Log.Error("No output directory is has been set"); + return false; + } + + if(Directory.Exists(OutputDirectory)) + return true; + + if(Directory.CreateDirectory(OutputDirectory) case .Err) + { + Log.Error("Unable to create output directoy"); + return false; + } + + Log.Info("Output directory has been created"); + + return true; + } } \ No newline at end of file diff --git a/src/Builder.bf b/src/Builder.bf deleted file mode 100644 index 7cd25a2..0000000 --- a/src/Builder.bf +++ /dev/null @@ -1,88 +0,0 @@ -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) => _InputDirectories.Add(new .(folder)); - public void AddPage(StringView name, Page page) - { - if(!_Pages.ContainsKeyAlt(name)) - { - _Pages.Add(new .(name), page); - } - } - - /** - * 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"); - } - - Log.Debug("Copying over directories"); - for(var i in _InputDirectories) - Directory.Copy(i, _OutputDirectory).IgnoreError(); - } - 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.bf b/src/HTML.bf new file mode 100644 index 0000000..ec75c24 --- /dev/null +++ b/src/HTML.bf @@ -0,0 +1,917 @@ +namespace Aven.HTML; + +using System; +using System.Collections; + +class HTML +{ + static public implicit operator HTML (StringView v) => Raw(v); + + 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(params Span children) + { + 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}\""); + + if(_Classes.Count > 0) + { + buffer.Append("class=\""); + for(var i in _Classes) + buffer.Append(scope $"{i} "); + buffer.Append("\" "); + } + + for(var i in _Values) + { + buffer.Append(scope $"{i.key}=\"{i.value}\""); + } + } +} + +static +{ + public static HTML Raw(StringView body = "") + { + var toReturn = new HTML(); + toReturn.[Friend]_Body.Append(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, params Span children) + { + var toReturn = new HTML(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(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("adress"); + return toReturn; + } + + public static HTML Article(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("article"); + return toReturn; + } + + public static HTML Aside(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("aside"); + return toReturn; + } + + public static HTML Footer(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("footer"); + return toReturn; + } + + public static HTML Header(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("header"); + return toReturn; + } + + + public static HTML H1(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("h1"); + return toReturn; + } + + public static HTML H2(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("h2"); + return toReturn; + } + + public static HTML H3(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("h3"); + return toReturn; + } + + public static HTML H4(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("h4"); + return toReturn; + } + + public static HTML H5(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("h5"); + return toReturn; + } + + public static HTML H6(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("h6"); + return toReturn; + } + + public static HTML HGroup(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("hgroup"); + return toReturn; + } + + public static HTML Main(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("main"); + return toReturn; + } + + public static HTML Nav(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("nav"); + return toReturn; + } + + public static HTML Section(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("section"); + return toReturn; + } + + public static HTML Search(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("search"); + return toReturn; + } + + public static HTML BlockQuote(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("blockquote"); + return toReturn; + } + + public static HTML Dd(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("dd"); + return toReturn; + } + + public static HTML Div(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("div"); + return toReturn; + } + + public static HTML Dl(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("dl"); + return toReturn; + } + + public static HTML Dt(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("dt"); + return toReturn; + } + + public static HTML Figcaption(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("figcaption"); + return toReturn; + } + + public static HTML Figure(params Span children) + { + var toReturn = new HTML(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(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("li"); + return toReturn; + } + + public static HTML Menu(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("menu"); + return toReturn; + } + + public static HTML Ol(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("ol"); + return toReturn; + } + + public static HTML P(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("p"); + return toReturn; + } + + public static HTML Pre(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("pre"); + return toReturn; + } + + public static HTML Ul(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("ul"); + return toReturn; + } + + public static HTML A(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("a"); + return toReturn; + } + + public static HTML Abbr(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("abbr"); + return toReturn; + } + + public static HTML B(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("b"); + return toReturn; + } + + public static HTML Bdi(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("bdi"); + return toReturn; + } + + public static HTML Bdo(params Span children) + { + var toReturn = new HTML(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(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("cite"); + return toReturn; + } + + public static HTML Code(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("code"); + return toReturn; + } + + public static HTML Data(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("data"); + return toReturn; + } + + public static HTML Dfn(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("dfn"); + return toReturn; + } + + public static HTML Em(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("em"); + return toReturn; + } + + public static HTML I(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("i"); + return toReturn; + } + + public static HTML Kdb(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("kdb"); + return toReturn; + } + + public static HTML Mark(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("mark"); + return toReturn; + } + + public static HTML Q(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("q"); + return toReturn; + } + + public static HTML Rp(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("rp"); + return toReturn; + } + + public static HTML Rt(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("rt"); + return toReturn; + } + + public static HTML Ruby(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("ruby"); + return toReturn; + } + + public static HTML S(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("s"); + return toReturn; + } + + public static HTML Samp(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("samp"); + return toReturn; + } + + public static HTML Small(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("small"); + return toReturn; + } + + public static HTML Span(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("span"); + return toReturn; + } + + public static HTML Strong(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("strong"); + return toReturn; + } + + public static HTML Sub(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("sub"); + return toReturn; + } + + public static HTML Sup(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("sup"); + return toReturn; + } + + public static HTML Time(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("time"); + return toReturn; + } + + public static HTML U(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("u"); + return toReturn; + } + + public static HTML Var(params Span children) + { + var toReturn = new HTML(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(params Span children) + { + var toReturn = new HTML(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(params Span children) + { + var toReturn = new HTML(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(params Span children) + { + var toReturn = new HTML(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(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("fencedframe"); + return toReturn; + } + + public static HTML IFrame(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("iframe"); + return toReturn; + } + + public static HTML Object(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("object"); + return toReturn; + } + + public static HTML Picture(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("picture"); + return toReturn; + } + + public static HTML Portal(params Span children) + { + var toReturn = new HTML(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(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("svg"); + return toReturn; + } + + public static HTML Math(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("math"); + return toReturn; + } + + public static HTML Canvas(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("canvas"); + return toReturn; + } + + public static HTML NoScript(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("noscript"); + return toReturn; + } + + public static HTML Script(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("script"); + return toReturn; + } + + public static HTML Del(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("del"); + return toReturn; + } + + public static HTML Ins(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("ins"); + return toReturn; + } + + public static HTML Caption(params Span children) + { + var toReturn = new HTML(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(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("colgroup"); + return toReturn; + } + + public static HTML Table(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("table"); + return toReturn; + } + + public static HTML TBody(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("tbody"); + return toReturn; + } + + public static HTML Td(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("td"); + return toReturn; + } + + public static HTML TFoot(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("tfoot"); + return toReturn; + } + + public static HTML Th(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("th"); + return toReturn; + } + + public static HTML THead(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("thead"); + return toReturn; + } + + public static HTML Tr(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("tr"); + return toReturn; + } + + public static HTML Button(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("button"); + return toReturn; + } + + public static HTML Datalist(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("datalist"); + return toReturn; + } + + public static HTML Fieldset(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("fieldset"); + return toReturn; + } + + public static HTML Form(params Span children) + { + var toReturn = new HTML(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(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("label"); + return toReturn; + } + + public static HTML Legend(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("legend"); + return toReturn; + } + + public static HTML Meter(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("meter"); + return toReturn; + } + + public static HTML Optgroup(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("optgroup"); + return toReturn; + } + + public static HTML Option(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("option"); + return toReturn; + } + + public static HTML Output(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("output"); + return toReturn; + } + + public static HTML Progress(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("progress"); + return toReturn; + } + + public static HTML Select(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("select"); + return toReturn; + } + + public static HTML Textarea(params Span children) + { + var toReturn = new HTML( params children); + toReturn.Name = .("textarea"); + return toReturn; + } + + public static HTML Details(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("details"); + return toReturn; + } + + public static HTML Dialog(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("dialog"); + return toReturn; + } + + public static HTML Summary(params Span children) + { + var toReturn = new HTML( params children); + toReturn.Name = .("summary"); + return toReturn; + } + + public static HTML Slot(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("slot"); + return toReturn; + } + + public static HTML Template(params Span children) + { + var toReturn = new HTML(params children); + toReturn.Name = .("template"); + return toReturn; + } +} \ No newline at end of file diff --git a/src/HTML/HTML.bf b/src/HTML/HTML.bf deleted file mode 100644 index b50e6f3..0000000 --- a/src/HTML/HTML.bf +++ /dev/null @@ -1,914 +0,0 @@ -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}\""); - - if(_Classes.Count > 0) - { - buffer.Append("class=\""); - for(var i in _Classes) - buffer.Append(scope $"{i} "); - buffer.Append("\" "); - } - - 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/Internal/Builder.bf b/src/Internal/Builder.bf new file mode 100644 index 0000000..3002a0a --- /dev/null +++ b/src/Internal/Builder.bf @@ -0,0 +1,23 @@ +namespace Aven; + +using System; +using System.IO; +using System.Collections; + +class Builder +{ + public void Build(Aven aven) + { + aven.Log.Debug("Default Builder"); + + String output = new .(1000); + defer delete output; + + for(var page in aven.Pages) + { + page.Build(output); + if(aven.[Friend]WriteToOutput(page.GetPageFileOutput(), output) case .Err) + aven.Log.Warn("Page has not been written"); + } + } +} \ No newline at end of file diff --git a/src/Internal/Logger.bf b/src/Internal/Logger.bf new file mode 100644 index 0000000..d8c29dd --- /dev/null +++ b/src/Internal/Logger.bf @@ -0,0 +1,41 @@ +namespace Aven; + +using System; + +class Logger +{ + public enum LogLevel + { + Debug, + Info, + Warn, + Error + } + +#if DEBUG + public LogLevel CurrentLogLevel = .Debug; +#else + public LogLevel CurrentLogLevel = .Info; +#endif + + ///Log a message + public virtual void Log(LogLevel logLevel, StringView message) + { + switch(logLevel) + { + case .Debug: + Console.WriteLine(scope $"[Aven][Debug]: {message}"); + case .Info: + Console.WriteLine(scope $"[Aven][Info]: {message}"); + case .Warn: + Console.WriteLine(scope $"[Aven][Warn]: {message}"); + case .Error: + Console.WriteLine(scope $"[Aven][Error]: {message}"); + } + } + + public void Debug(StringView message) => Log(.Debug, message); + public void Info(StringView message) => Log(.Info, message); + public void Warn(StringView message) => Log(.Warn, message); + public void Error(StringView message) => Log(.Error, message); +} \ No newline at end of file diff --git a/src/Internal/Page.bf b/src/Internal/Page.bf new file mode 100644 index 0000000..0bff55f --- /dev/null +++ b/src/Internal/Page.bf @@ -0,0 +1,73 @@ +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 virtual StringView GetPageFileOutput() => "Index.html"; + + public void AddElement(params Span elmt) + { + for(var i in elmt) + _elements.Add(i); + } + + + + public void Build(String buffer) + { + LoadPageContents(); + buffer.Append(scope $""" + + + + + {Title} + {BuildStyles(.. scope .())} + {BuildScripts(.. 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 diff --git a/src/Log.bf b/src/Log.bf deleted file mode 100644 index 32a61e5..0000000 --- a/src/Log.bf +++ /dev/null @@ -1,59 +0,0 @@ -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 index 7fcd366..54fa75c 100644 --- a/src/Page.bf +++ b/src/Page.bf @@ -1,96 +1,36 @@ namespace Aven; -using Aven.HTML; using System; -using System.Collections; -/** - An instance of this class represents a single .html website -*/ -abstract class Page +extension 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; + get => _title; set { - _Title.Clear(); - _Title.Append(value); + _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)); + _scripts.Add(new .(i)); } public void AddStyles(params Span styles) { for(var i in styles) - _Styles.Add(new .(i)); + _styles.Add(new .(i)); } public void AddInlineStyle(StringView style) { - _InlineStyle.Add(new .(style)); + _inlineStyle.Add(new .(style)); } - public void Build(String buffer) - { - buffer.Append(scope $""" - - - - - {Title} - {BuildStyles(.. scope .())} - {BuildScripts(.. scope .())} - - - {BuildElements(.. scope .())} - - - """); - } + public abstract void LoadPageContents(); - 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