JeyDotC.JustCs
1.1.0
See the version list below for details.
dotnet add package JeyDotC.JustCs --version 1.1.0
NuGet\Install-Package JeyDotC.JustCs -Version 1.1.0
<PackageReference Include="JeyDotC.JustCs" Version="1.1.0" />
paket add JeyDotC.JustCs --version 1.1.0
#r "nuget: JeyDotC.JustCs, 1.1.0"
// Install JeyDotC.JustCs as a Cake Addin #addin nuget:?package=JeyDotC.JustCs&version=1.1.0 // Install JeyDotC.JustCs as a Cake Tool #tool nuget:?package=JeyDotC.JustCs&version=1.1.0
JustCs
Forget about templating, use just C#!
Create your page:
public class MyPage : ComponentElement
{
protected override Element Render(IElementAttributes props) =>
_<Html>(
_<Head>(
_<Title>("Hello World")
),
_<Body>(
_<H1>("Hello from JustCs!")
)
);
}
Serve your page:
[ApiController]
[Route("[controller]")]
public class MyPageController : ControllerBase
{
[HttpGet]
public IView Index() => new View<MyPage>();
}
Installation
dotnet add package JeyDotC.JustCs --version 1.1.0
dotnet add package JeyDotC.JustCs.Mvc --version 1.0.0
Setup
At your Startup.cs file, add this to your controller options:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers(options =>
{
options.WithJustCs(); //<-- This allows API controllers to render JustCs HTML views.
});
}
Basic Usage
Create a component
Just create a class that extends ComponentElement
(or ComponentElement<>
) and implement the Render
method.
public class MyPage : ComponentElement
{
protected override Element Render(IElementAttributes props) =>
_<Html>(
_<Head>(
_<Title>("Hello World")
),
_<Body>(
_<H1>("Hello from JustCs!")
_<Form>(new Attrs { Method = "POST", Action = "/login" },
_<Label>(new Attrs { For = "username" }, "Username"),
_<Input>(new Attrs { Id = "username", Name = "username", Type = "text", Placeholder = "User Name" }),
_<Label>(new Attrs { For = "password" }, "Password"),
_<Input>(new Attrs { Id = "username", Name = "username", Type = "password" }),
_<Button>(new Attrs { Type = "submit" }, "Login"),
)
)
);
}
Return the view as a response
At your controller, just create a View<>
instance which will serve as the HTTP response.
[ApiController]
[Route("[controller]")]
public class MyPageController : ControllerBase
{
[HttpGet]
public IView Index() => new View<MyPage>();
}
The View class, since it serves as the response, which means you can set the status code and headers too.
[ApiController]
[Route("[controller]")]
public class MyPageController : ControllerBase
{
[HttpGet]
public IView Index() => new View<MyPage>();
[HttpGet]
public IView Error() => new View<MyErrorPage>(null, HttpStatusCode.ServerError)
.WithHeader("X-Some-Header", "some-value");
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on JeyDotC.JustCs:
Package | Downloads |
---|---|
JeyDotC.JustCs.Mvc
Library to render HTML using just C#. |
|
JeyDotC.JustCs.Testing
A small set of unit test helpers. |
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.1.0 Names are now just lowercased by default.
Added the Attr attribute that allows to override name transform behavior.
Added name transform tuple machinsm to override name transform on dynamic properties e.g. (_).
HtmlRenderer won't allow repeated attributes.
Tag names are now validated in order to avoid scripting injection.
Attrs properties are now arranged alphabetically.
V1.0.3 Added the lodash (_) property to Attrs so user can add extra attributes without inheriting the record.
Added conditional rendering via ValueTuple<boolean, Element> implicit conversion.
V1.0.2 Switched Attrs and AriaAttrs from class to record.
V1.0.1 Added support for WAI ARIA attributes.