Aramid: Create Strongly-Typed HTML Components in C#(github.com)
github.com
Aramid: Create Strongly-Typed HTML Components in C#
https://github.com/edamtoft/Aramid
9 comments
While the tags are strongly typed, their attributes are apparently not (anonymous types).
Why?
I like the idea, but I think this kind of thing feels obtuse in languages like C# and Java where the "templates" are 100% written with the hosted language.
Some languages can work around this by having flexible type definitions and syntax to make the DSL much closer to the target template (for an example, see: http://www.lihaoyi.com/scalatags/). This works pretty well to avoid all those field declaration and "new" keywords.
Some languages can work around this by having flexible type definitions and syntax to make the DSL much closer to the target template (for an example, see: http://www.lihaoyi.com/scalatags/). This works pretty well to avoid all those field declaration and "new" keywords.
> I like the idea, but I think this kind of thing feels obtuse in languages like C# and Java where the "templates" are 100% written with the hosted language.
I agree, but it's not that bad. I do think j2html [1] has a cleaner look than Aramid.
[1] http://j2html.com/
I agree, but it's not that bad. I do think j2html [1] has a cleaner look than Aramid.
[1] http://j2html.com/
WebSharper templates are worth considering as an alternative:
https://github.com/intellifactory/websharper.ui.next/blob/ma...
https://kimsereyblog.blogspot.co.uk/2016/08/create-html-comp...
https://github.com/intellifactory/websharper.ui.next/blob/ma...
https://kimsereyblog.blogspot.co.uk/2016/08/create-html-comp...
I feel the name should be "Kevlar" to reflect use of trademarks by Microsoft and DuPont. Perhaps if the language used was C++ then Aramid might be appropriate.
In .NET Core, there are new TagHelpers that probably do some of the same stuff... not sure exactly of the overlap, but I've used them and they're really nice.
Is this only for server side rendering?
Looks a lot like the HtmlTags project that grew out of FubuMvc.
https://github.com/HtmlTags/htmltags
https://github.com/HtmlTags/htmltags
Why not F#?
Using F# would have been a great choice. By using algebraic data types plus active patterns the size of the code base would have been dramatically reduced and much more comprehensible. And of course it would have been even more type safe.
[deleted]
H.head ( H.title ("Hello world"), H.link (a => a.href ("/favicon.ico").rel ("shortcut icon").type ("image/x-icon")) )
Having used it on a website that I've had to maintain for years I can say that the simplicity of writing reusable components and ease of refactoring is really nice. It entirely negates the need to use a view mechanism at all - you just write your views in C# code.
The links for github and nuget are:
https://github.com/hyperlinq/hyperlinq https://www.nuget.org/packages/Hyperlinq
I should mention that I use Hyperlinq in conjunction with MarkdownDeep. Markdown is great for defining HTML fragments that are very document-oriented, as opposed to data-oriented. So for instance I'd use markdown to define an FAQ, but would use Hyperlinq to define HTML for a customer record. Markdown fragments can be inserted into a Hyperlinq DOM as literal nodes (the underlying mechanism for Hyperlinq is Linq to XML), so the two approaches mesh together nicely.
I wrote the library ages ago but put very little effort into promoting it as I'm too busy.