Thread overview
d_to_html.d
Aug 05, 2017
WebFreak001
Aug 06, 2017
David Gileadi
Aug 06, 2017
crimaniak
Aug 06, 2017
Meta
Aug 06, 2017
Jacob Carlborg
Aug 08, 2017
Biotronic
Aug 07, 2017
solidstate1991
Aug 07, 2017
TheGag96
Aug 07, 2017
jmh530
Aug 09, 2017
Robert M. Münch
August 05, 2017
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
August 05, 2017
On 8/5/17 12:07 PM, 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. 

[snip]

That is amazing! I can't decide whether it's the best thing I've ever seen or a horrible hack, but it's a great showcase for what you can do with D.
August 06, 2017
On Saturday, 5 August 2017 at 19:07:50 UTC, 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

Just because you *can* do something, it doesn't mean you *should*. ;-)

Very creative, I don't think reading source code has ever made me chuckle before.
August 06, 2017
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
August 06, 2017
On Sunday, 6 August 2017 at 00:22:32 UTC, David Gileadi wrote:
> On 8/5/17 12:07 PM, 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.
>
> [snip]
>
> That is amazing! I can't decide whether it's the best thing I've ever seen or a horrible hack,
The best thing for Olympic programming, horrible hack for production code. :)

August 07, 2017
On Saturday, 5 August 2017 at 19:07:50 UTC, 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.

Finally! I can have a footing in frontend development!
August 07, 2017
On Saturday, 5 August 2017 at 19:07:50 UTC, WebFreak001 wrote:
>snip

Man, this is absolutely nuts. Overriding opBinary to catch hyphens, aliasing opAssign to opCall... Just evil, haha! Amazing job!
August 07, 2017
On Monday, 7 August 2017 at 02:32:56 UTC, TheGag96 wrote:
>
> Man, this is absolutely nuts. Overriding opBinary to catch hyphens, aliasing opAssign to opCall... Just evil, haha! Amazing job!

I don't think I had noticed either of those things when I skimmed it the first time. Thanks for highlighting.
August 08, 2017
On Sunday, 6 August 2017 at 15:18:29 UTC, Jacob Carlborg wrote:
[snip]
> 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.

That's easily amendable:

struct ElementBuilder {
    auto opDispatch(string name, Args...)(Args args) const {
        return Element(name)(args);
    }
}

enum xml = ElementBuilder();

unittest {
    enum a = xml.foo(xml.bar("baz"), xml.qux(123));
    assert(a.toString == "<foo><bar>baz</bar><qux>123</qux></foo>");
}

--
  Biotronic
August 09, 2017
On 2017-08-05 19:07:50 +0000, WebFreak001 said:

> 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(
> ...

That's pretty cool and comes very close to a domain specific language. This would make it possible to get declarative GUI layout etc. in with a much nicer syntax. Cool idea.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster