www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - d_to_html.d

reply WebFreak001 <d.forum webfreak.org> writes:
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!"&copy; 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
Aug 05 2017
next sibling parent reply David Gileadi <gileadisNOSPM gmail.com> writes:
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.
Aug 05 2017
parent crimaniak <crimaniak gmail.com> writes:
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. :)
Aug 06 2017
prev sibling next sibling parent Meta <jared771 gmail.com> writes:
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!"&copy; 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.
Aug 05 2017
prev sibling next sibling parent reply Jacob Carlborg <doob me.com> writes:
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!"&copy; 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
Aug 06 2017
parent Biotronic <simen.kjaras gmail.com> writes:
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
Aug 08 2017
prev sibling next sibling parent solidstate1991 <laszloszeremi outlook.com> writes:
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!
Aug 06 2017
prev sibling next sibling parent reply TheGag96 <thegag96 gmail.com> writes:
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!
Aug 06 2017
parent jmh530 <john.michael.hall gmail.com> writes:
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.
Aug 07 2017
prev sibling parent =?iso-8859-1?Q?Robert_M._M=FCnch?= <robert.muench saphirion.com> writes:
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
Aug 09 2017