4 ms·
Aramid: Create Strongly-Typed HTML Components in C#
- haimez 10y agoI 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/ http://www.lihaoyi.com/scalatags/). This works pretty well to avoid all those field declaration and "new" keywords.
- wtetzner 10y ago> 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/ http://j2html.com/
- ZenoArrow 10y agoWebSharper templates are worth considering as an alternative: https://github.com/intellifactory/websharper.ui.next/blob/master/docs/Templates.md https://github.com/intellifactory/websharper.ui.next/blob/ma... https://kimsereyblog.blogspot.co.uk/2016/08/create-html-componants-for-your.html https://kimsereyblog.blogspot.co.uk/2016/08/create-html-comp...
- throwaway98237 10y agoI 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.
- SBArbeit 10y agoIn .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.
- isuckatcoding 10y agoIs this only for server side rendering?
- jeremy_wiebe 10y agoLooks a lot like the HtmlTags project that grew out of FubuMvc. https://github.com/HtmlTags/htmltags https://github.com/HtmlTags/htmltags
- partycoder 10y agoWhy not F#?
- deleted 10y ago[deleted]
- junkyarddog 10y agoUsing 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.
- 3dGrabber 10y agoWhile the tags are strongly typed, their attributes are apparently not (anonymous types). Why?
- hyperlinq 10y agoYou 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://github.com/hyperlinq/hyperlinq https://www.nuget.org/packages/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.