OzieWest / net-web-helper

Html builder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple class for render html struct

HOW TO

create simple tag
var result = String.Empty;
using (var _create = new SimpleTagBuilder()) 
{
	_create.Tag("div");
	result = _create.Render();
}

// output: <div></div>
create self-contained tag
var _result = String.Empty;
using (var _create = new SimpleTagBuilder())
{
	_create.Tag("br", selfClose: true);
	_result = _create.Render();
}
// output: <br/>
create tag with attributes
var _result = String.Empty;
using (var _create = new SimpleTagBuilder())
{
	_create.Tag("div", withAttributes: new { id = "testId", @class = "testClass" });
	_result = _create.Render();
}
// output: <div id='testId' class='testClass'></div>
create tag with nested tags
var _result = String.Empty;
using (var _create = new SimpleTagBuilder())
{
	_create.Tag("div", withAttributes: new { id = "testId", @class = "testClass" }, withChildren: () => 
	{
		_create.Tag("span", withChildren: () =>
		{
			_create.Text("hello world");
		});
	});
	_result = _create.Render();
}
// output: <div id='testId' class='testClass'><span>hello world</span></div>
create tag with attribute without value
var _result = String.Empty;
using (var _create = new SimpleTagBuilder())
{
	_create.Tag("div", withAttributes: new { ngApp = "" });

	_result = _create.Render();
}
// output: <div ng-app></div>
add script
var _result = String.Empty;
using (var _create = new SimpleTagBuilder())
{
	_create.Tag("div", withChildren: () =>
	{
		_create.Script("alert(123);", useStrict: true);
	});

	_result = _create.Render();
}
// output: <div><script>'use strict';alert(123);</script></div>

Some conventions

  • name myBigAttr transform to my-big-attr
  • don`t start attribute name with UpperCase

About

Html builder


Languages

Language:C# 100.0%