Tag 1.0.2

A simple C# generator for HTML/XML

There is a newer version of this package available.
See the version list below for details.
Install-Package Tag -Version 1.0.2
dotnet add package Tag --version 1.0.2
<PackageReference Include="Tag" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tag --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tag, 1.0.2"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Tag as a Cake Addin
#addin nuget:?package=Tag&version=1.0.2

// Install Tag as a Cake Tool
#tool nuget:?package=Tag&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

T·g

A simple C# generator for HTML/XML

https://www.nuget.org/packages/Tag

Why?

Sometimes you have a project where a lot of code is needed to output a little markup. For those projects, markup templating engines make things more difficult, and a lot of the time you end up doing string concatenation. T·g is a step up from string concatenation.

Usage

See the TagTests.cs file for examples of every feature. Here are some overviews to get you started.

Basic usage

var tag = T.g("div", "class","glass")[
             T.g("a", "href", "#")["Fish"],
             T.g("br/")
          ];

Console.WriteLine(tag.ToString());

Outputs <div class="glass"><a href="#">Fish</a><br/></div>

Writing to a stream

var tag = T.g( . . . );
tag.StreamTo(myWritableStream, Encoding.UTF8);

if StreamTo is called multiple times, it will write another copy of the tag tree.

Templating and injection pattern

var doc = HtmlDoc("Hello World", out var head, out var body);

body.Add(T.g("h1")["Hello, world"]);
body.Add(T.g("p")["This is a simple HTML page example"]);

return doc.ToString();

.
.
.

TagContent HtmlDoc(string title, out TagContent head, out TagContent body)
{
    var html = T.g("html");

    head = T.g("head")[
                    T.g("title")[title],
                    T.g("style").LoadFile("Styles/PageStyle.css")
                ]
            ];
    
    body = T.g("body")[T.g("script").LoadFile("Scripts/PageScript.js")];

    html.Add(head);
    html.Add(body);

    return html;
}

T·g

A simple C# generator for HTML/XML

https://www.nuget.org/packages/Tag

Why?

Sometimes you have a project where a lot of code is needed to output a little markup. For those projects, markup templating engines make things more difficult, and a lot of the time you end up doing string concatenation. T·g is a step up from string concatenation.

Usage

See the TagTests.cs file for examples of every feature. Here are some overviews to get you started.

Basic usage

var tag = T.g("div", "class","glass")[
             T.g("a", "href", "#")["Fish"],
             T.g("br/")
          ];

Console.WriteLine(tag.ToString());

Outputs <div class="glass"><a href="#">Fish</a><br/></div>

Writing to a stream

var tag = T.g( . . . );
tag.StreamTo(myWritableStream, Encoding.UTF8);

if StreamTo is called multiple times, it will write another copy of the tag tree.

Templating and injection pattern

var doc = HtmlDoc("Hello World", out var head, out var body);

body.Add(T.g("h1")["Hello, world"]);
body.Add(T.g("p")["This is a simple HTML page example"]);

return doc.ToString();

.
.
.

TagContent HtmlDoc(string title, out TagContent head, out TagContent body)
{
    var html = T.g("html");

    head = T.g("head")[
                    T.g("title")[title],
                    T.g("style").LoadFile("Styles/PageStyle.css")
                ]
            ];
    
    body = T.g("body")[T.g("script").LoadFile("Scripts/PageScript.js")];

    html.Add(head);
    html.Add(body);

    return html;
}

Release Notes

Adding plain text filter

Dependencies

This package has no dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Tag:

Package Downloads
Gasconade
A log message management system and exploration UI, in a similar vein to Swagger. Contains an expressive templating system.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.3.1 2,637 3/20/2019
1.3.0 825 7/9/2018
1.2.0 533 5/24/2018
1.1.0 798 4/17/2018
1.0.4 596 4/16/2018
1.0.3 558 4/16/2018
1.0.2 706 4/13/2018
1.0.1 582 12/8/2017
1.0.0 871 11/14/2017
Show less