Re: d_to_html.d
On 2017-08-05 19:07:50 +, 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
Re: d_to_html.d
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 == "baz123"); } -- Biotronic
Re: d_to_html.d
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.
Re: d_to_html.d
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!
Re: d_to_html.d
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!
Re: d_to_html.d
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. :)
Re: d_to_html.d
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
Re: d_to_html.d
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.
Re: d_to_html.d
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.
d_to_html.d
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