News for hackers. Stuff that matters.
Re:Aramid: Create Strongly-Typed HTML Components in C# by hyperlinq on Monday November 14, 2016 @12:53PM (#12951707)
You may want to check out Hyperlinq, a C# library for statically typed HTML generation. It also statically types the HTML attributes. Example code:

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.

Re:Aramid: Create Strongly-Typed HTML Components in C# by ZenoArrow on Sunday November 13, 2016 @06:37PM (#12946457)
Re:Aramid: Create Strongly-Typed HTML Components in C# by haimez on Sunday November 13, 2016 @06:00PM (#12946258)
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.

Re:Aramid: Create Strongly-Typed HTML Components in C# by wtetzner on Sunday November 13, 2016 @07:09PM (#12946582)
> 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/

Re:Aramid: Create Strongly-Typed HTML Components in C# by jeremy_wiebe on Monday November 14, 2016 @12:45AM (#12947784)
Looks a lot like the HtmlTags project that grew out of FubuMvc.

https://github.com/HtmlTags/htmltags

Re:Aramid: Create Strongly-Typed HTML Components in C# by SBArbeit on Sunday November 13, 2016 @09:13PM (#12947054)
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.
Re:Aramid: Create Strongly-Typed HTML Components in C# by simooooo on Monday November 14, 2016 @03:44AM (#12948392)
I'd much rather use razor than write all my markup in c#. This code looks way too bloated
Re:Aramid: Create Strongly-Typed HTML Components in C# by zihotki on Monday November 14, 2016 @05:37AM (#12948825)
Agree, I can't even think of an use case which can not be implemented using TagHelpers, partials & co in newer version of Razor.
Re:Aramid: Create Strongly-Typed HTML Components in C# by 3dGrabber on Monday November 14, 2016 @08:38AM (#12949722)
While the tags are strongly typed, their attributes are apparently not (anonymous types). Why?
Re:Aramid: Create Strongly-Typed HTML Components in C# by throwaway98237 on Sunday November 13, 2016 @07:50PM (#12946717)
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.
Re:Aramid: Create Strongly-Typed HTML Components in C# by isuckatcoding on Sunday November 13, 2016 @10:06PM (#12947239)
Is this only for server side rendering?
Re:Aramid: Create Strongly-Typed HTML Components in C# by partycoder on Monday November 14, 2016 @03:28AM (#12948343)
Why not F#?
Re:Aramid: Create Strongly-Typed HTML Components in C# by junkyarddog on Monday November 14, 2016 @06:01AM (#12948947)
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.