BadScript 2
Loading...
Searching...
No Matches
BadDocsSystem.cs
Go to the documentation of this file.
1using System.Diagnostics;
2
3using BadHtml;
4
5using BadScript2.IO;
9
14
18public class BadDocsSystem : BadConsoleSystem<BadDocsSystemSettings>
19{
24 public BadDocsSystem(BadRuntime runtime) : base(runtime) { }
25
26
28 public override string Name => "docs";
29
30 private static string DocsPath
31 {
32 get
33 {
34 string? s = BadSettingsProvider.RootSettings.FindProperty<string>("Subsystems.Docs.RootDirectory");
35
36 if (s == null)
37 {
38 throw new BadRuntimeException("Subsystems.Docs.RootDirectory not set");
39 }
40
42
43 return s;
44 }
45 }
46
47 private static string TemplatePath => Path.Combine(DocsPath, "docs.bhtml");
48
50 protected override Task<int> Run(BadDocsSystemSettings settings)
51 {
52 BadRuntimeSettings.Instance.CatchRuntimeExceptions = false;
53 BadRuntimeSettings.Instance.WriteStackTraceInRuntimeErrors = true;
54 string outFile = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".html");
55 string htmlString = BadHtmlTemplate.Create(TemplatePath).Run(null, new BadHtmlTemplateOptions { Runtime = Runtime, SkipEmptyTextNodes = true });
56 File.WriteAllText(outFile, htmlString);
57 Process p = new Process();
58 p.StartInfo = new ProcessStartInfo(outFile)
59 {
60 UseShellExecute = true,
61 };
62 p.Start();
63
64 return Task.FromResult(0);
65 }
66}
Implements a Html Template.
static BadHtmlTemplate Create(string file, IFileSystem? fileSystem=null)
Creates a new Template.
string Run(object? model=null, BadHtmlTemplateOptions? options=null, BadScope? caller=null)
Runs the Template with the specified arguments.
Options for the Html Template Engine.
Exposes the BadScript Runtime Functionality to Consumers.
Definition BadRuntime.cs:28
Implements a Console System that uses a settings object of Type T.
BadDocsSystem(BadRuntime runtime)
Creates a new BadHtmlSystem instance.
override Task< int > Run(BadDocsSystemSettings settings)
Public interface for the filesystem abstraction of the BadScript Engine.
static IFileSystem Instance
File System implementation.
BadSettings? FindProperty(string propertyPath)
Finds a property based on the property path relative to this object.
Helper class that can be used to automatically load a settings object from a file.
static BadSettings RootSettings
Returns the Root Settings Object.
void CreateDirectory(string path, bool recursive=false)
Creates a new directory.
A Html Template Generator based on BadScript2.
Contains the 'html' console command implementation.
Contains IO Implementation for the BadScript2 Runtime.
Contains the Error Objects for the BadScript2 Language.
Contains Runtime Settings Objects.
Contains the Settings Implementation.