BadScript 2
Loading...
Searching...
No Matches
BadHtml.BadHtmlNodeTransformer Class Referenceabstract

Base class of all Node transformers. More...

Inheritance diagram for BadHtml.BadHtmlNodeTransformer:
BadHtml.Transformer.BadCopyNodeTransformer BadHtml.Transformer.BadCopyScriptNodeTransformer BadHtml.Transformer.BadCopyStyleNodeTransformer BadHtml.Transformer.BadExecuteScriptNodeTransformer BadHtml.Transformer.BadForEachNodeTransformer BadHtml.Transformer.BadFunctionNodeTransformer BadHtml.Transformer.BadIfNodeTransformer BadHtml.Transformer.BadImportFileNodeTransformer BadHtml.Transformer.BadImportTemplateNodeTransformer BadHtml.Transformer.BadInsertNodeTransformer BadHtml.Transformer.BadTextNodeTransformer BadHtml.Transformer.BadWhileNodeTransformer

Static Public Member Functions

static void Transform (BadHtmlContext context)
 Transforms the input node with one of the registered transformers.
 

Protected Member Functions

bool CanTransform (BadHtmlContext context)
 Returns true if the transformer can transform the specified node.
 
void TransformNode (BadHtmlContext context)
 Transforms the input node.
 

Static Protected Member Functions

static void TransformAttributes (BadHtmlContext context, HtmlNode outputNode)
 Transforms all attributes of the input node and writes it to the specified output node.
 

Static Private Attributes

static readonly List< BadHtmlNodeTransformers_Transformers
 List of all node transformers used in the engine.
 

Detailed Description

Base class of all Node transformers.

Definition at line 15 of file BadHtmlNodeTransformer.cs.

Member Function Documentation

◆ CanTransform()

bool BadHtml.BadHtmlNodeTransformer.CanTransform ( BadHtmlContext  context)
abstractprotected

Returns true if the transformer can transform the specified node.

Parameters
contextThe Html Context
Returns
True if can transform node

◆ Transform()

static void BadHtml.BadHtmlNodeTransformer.Transform ( BadHtmlContext  context)
static

Transforms the input node with one of the registered transformers.

Parameters
contextThe Html Context
Exceptions
InvalidOperationExceptionGets raised if the node can not be transformed

Definition at line 78 of file BadHtmlNodeTransformer.cs.

79 {
80 foreach (BadHtmlNodeTransformer transformer in s_Transformers)
81 {
82 if (!transformer.CanTransform(context))
83 {
84 continue;
85 }
86
87 transformer.TransformNode(context);
88
89 return;
90 }
91
92 throw new InvalidOperationException("No transformer found");
93 }
static readonly List< BadHtmlNodeTransformer > s_Transformers
List of all node transformers used in the engine.

◆ TransformAttributes()

static void BadHtml.BadHtmlNodeTransformer.TransformAttributes ( BadHtmlContext  context,
HtmlNode  outputNode 
)
staticprotected

Transforms all attributes of the input node and writes it to the specified output node.

Parameters
contextThe Html Context
outputNodeThe Output Node

Definition at line 54 of file BadHtmlNodeTransformer.cs.

55 {
56 foreach (HtmlAttribute attribute in context.InputNode.Attributes)
57 {
58 //Get Attribute Value
59 string value = attribute.Value;
60
61 //Replace all newlines with spaces
62 value = value.Replace("\n", " ").Replace("\r", " ");
63
64 //Evaluate Attribute Value with BadScript
65 BadObject result =
66 context.ParseAndExecute("$\"" + value + "\";", context.CreateAttributePosition(attribute));
67
68 //Set Attribute Value
69 outputNode.Attributes[attribute.Name].Value = result.ToString();
70 }
71 }
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
override string ToString()
Returns a String Representation of this Object.
Definition BadObject.cs:210

◆ TransformNode()

void BadHtml.BadHtmlNodeTransformer.TransformNode ( BadHtmlContext  context)
abstractprotected

Transforms the input node.

Parameters
contextThe Html Context

Member Data Documentation

◆ s_Transformers

readonly List<BadHtmlNodeTransformer> BadHtml.BadHtmlNodeTransformer.s_Transformers
staticprivate
Initial value:
= new List<BadHtmlNodeTransformer>
{
new BadInsertNodeTransformer(),
new BadImportTemplateNodeTransformer(),
new BadImportFileNodeTransformer(),
new BadExecuteScriptNodeTransformer(),
new BadForEachNodeTransformer(),
new BadWhileNodeTransformer(),
new BadFunctionNodeTransformer(),
new BadIfNodeTransformer(),
new BadCopyStyleNodeTransformer(),
new BadCopyScriptNodeTransformer(),
new BadTextNodeTransformer(),
new BadCopyNodeTransformer(),
}

List of all node transformers used in the engine.

Definition at line 20 of file BadHtmlNodeTransformer.cs.

21 {
34 };
Copies the current node to the output and transforms the attributes This is the default transformer.
Copies the current script node to the output if the lang attribute is not bs2.
Copies the current style node to the output.
Executes the current script block if the lang attribute is bs2.
Implements the 'bs:each' node transformer.
Implements a BadScript Function Node Transformer.
Implements the 'bs:if' node transformer.
Imports the file specified in the path attribute of the current bs:import node.
Imports the template specified in the path attribute of the current bs:template node.
Implements the bs:insert node transformer. That inserts the inner content of the node into the specif...
Implements a BadScript Text Node Transformer Copies the text nodes to the output and evaluates them w...
Implements the 'bs:while' node transformer.

The documentation for this class was generated from the following file: