Skip to content

Twinvision/Twinvision.Flow

Repository files navigation

Twinvision.Flow Build Status

An HTML builder library to create html using a fluent C# builder pattern with no external package dependencies. See below for some code examples.

Hello world example

Code

var builder = new HTMLBuilder();
builder.Document().Body(content: "Hello world!");
System.Diagnostics.Debug.WriteLine(builder.ToString());

Output

<!DOCTYPE html>
<html>
    <body>Hello world!</body>
</html>

Create div with comments

Code

var builder = new HTMLBuilder();
builder.Document("en").Body()
       .Comment("A comment for" + Environment.NewLine + "a div element")
       .Div(content: "HTML comments test");
System.Diagnostics.Debug.WriteLine(builder.ToString());

Output

<!DOCTYPE html>
<html lang="en">
    <body>
        <!--
            A comment for
            a div element
        -->
        <div>HTML comments test</div>
    </body>
</html>

Create component block

Code

var builder = new HTMLBuilder();
builder.Document().Body()
       .H(1, "Component example")
       .BeginComponent("My Component")
            .Div("Main component element")
                .Child()
                    .AddElement("span", "Extra component content")
                .Parent()
       .EndComponent();
System.Diagnostics.Debug.WriteLine(builder.ToString());

Result

<!DOCTYPE html>
<html>
    <body>
        <h1>Component example</h1>
        <!-- Begin My Component -->
        <div class="Main component element">
            <span>Extra component content</span>
        </div>
        <!-- End My Component -->
    </body>
</html>