BadScript 2
Loading...
Searching...
No Matches
BadImportFileNodeTransformer.cs
Go to the documentation of this file.
1using BadScript2.IO;
3
4using HtmlAgilityPack;
5
6namespace BadHtml.Transformer;
7
12{
14 protected override bool CanTransform(BadHtmlContext context)
15 {
16 return context.InputNode.Name == "bs:import";
17 }
18
20 protected override void TransformNode(BadHtmlContext context)
21 {
22 HtmlAttribute? pathAttribute = context.InputNode.Attributes["path"];
23
24 if (pathAttribute == null)
25 {
27 context.ExecutionContext.Scope,
28 "Missing 'path' attribute in 'bs:import' node",
29 context.CreateOuterPosition()
30 );
31 }
32
33
34 string? path = pathAttribute.Value;
35
36 if (string.IsNullOrEmpty(path))
37 {
39 context.ExecutionContext.Scope,
40 "Empty 'path' attribute in 'bs:import' node",
41 context.CreateAttributePosition(pathAttribute)
42 );
43 }
44
45 string data = BadFileSystem.ReadAllText(path);
46
47 context.OutputNode.AppendChild(context.OutputDocument.CreateTextNode(data));
48 }
49}
Implements the Html Context for the Transformation Process.
BadSourcePosition CreateAttributePosition(HtmlAttribute attribute)
Creates the Source Position of the specified Attribute.
BadSourcePosition CreateOuterPosition()
Creates the Source Position of the current Input Nodes Outer Content.
HtmlDocument OutputDocument
The Output Document.
readonly HtmlNode InputNode
The Current Input Node.
readonly BadExecutionContext ExecutionContext
The Execution Context that is used to evaluate badscript code.
readonly HtmlNode OutputNode
The Current Output Node.
Base class of all Node transformers.
Imports the file specified in the path attribute of the current bs:import node.
Public interface for the filesystem abstraction of the BadScript Engine.
static string ReadAllText(this IFileSystem fileSystem, string path)
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
Implementations of Html Node Transformers that are used in the Transformation Process.
Contains IO Implementation for the BadScript2 Runtime.
Contains the Error Objects for the BadScript2 Language.