https://github.com/i-e-b/t.g
A simple C# generator for HTML/XML
https://github.com/i-e-b/t.g
csharp html production-ready string-concatenation working xml
Last synced: 4 months ago
JSON representation
A simple C# generator for HTML/XML
- Host: GitHub
- URL: https://github.com/i-e-b/t.g
- Owner: i-e-b
- License: bsd-3-clause
- Created: 2017-11-10T15:56:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-20T12:54:57.000Z (over 6 years ago)
- Last Synced: 2025-05-26T14:21:43.225Z (5 months ago)
- Topics: csharp, html, production-ready, string-concatenation, working, xml
- Language: C#
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# T·g
A simple C# generator for HTML/XMLhttps://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
```csharp
var tag = T.g("div", "class","glass")[
T.g("a", "href", "#")["Fish"],
T.g("br/")
];Console.WriteLine(tag.ToString());
`
```
Outputs `### Writing to a stream
```csharp
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
```csharp
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;
}
```