On 2017-08-05 21:07, WebFreak001 wrote:
Hi, I made a D to HTML generator which is basically diet, but fully
using the D compiler as generator and not some complicated parser, etc.
Here an example what you pass in:

string page = html(
     head(
         title("wtf is this"),
         style(
             html(
                 font-family = "Roboto",
                 background = 0xEFEFEF
             ),
             div.content(
                 max-width = 800.px,
                 margin = auto_,
                 margin-top = 32.px,
                 box-shadow = "0 2px 5px rgba(0, 0, 0, 0.3)",
                 background = white,
                 padding = 32.px
             ),
             div.footer(
                 text-"align" = center
             )
         )
     ),
     body(
         div.content(
             h1("The most crappy HTML generator ever"),
             div.teaser(
                 p("Super fast")
             ),
             hr,
             p("Reasons why you should use d_to_html:"),
             ul(
                 li("TODO: no reason yet") * 5
             )
         ),
         div.footer(
             p(raw!"© 2017 webfreak.org")
         )
     )
).toString;

Which generates: https://i.webfreak.org/fStzn0.html

Full source:
https://gist.github.com/WebFreak001/6a1916779e48898c7ababc47a3113829

Though some things (like min and max for example) won't work correctly,
so you need to manually write `attr!"min" = 4` if you wanted to add that
to an input element.

btw this is just a joke project, it's totally abusing operator
overloading just to show what is possible with it. The idea came up in
Wild's discord server, you can join us too, we have a programming and a
dplug channel: https://discordapp.com/invite/bMZk9Q4

Wow, that's pretty cool :). One downside I see is that all tags are currently hard coded. This won't work for XML or if using new/custom tags that the library doesn't know about yet.

--
/Jacob Carlborg

Reply via email to