DEV Community

Render static site from Scala code

Sakib Hadžiavdić on August 17, 2017

Have you ever thought: If I just had a variable in my ugly HTML... So I wouldn't have to repeat all those Bootstrap classes and could change them...
Collapse
 
scheidig profile image
Albrecht Scheidig

Good stuff. We have implemented something like that in Groovy (using a DSL). But we used it to create dynamic content.
I don't see why you would limit your idea to create a static site, it works the same to create dynamic content, does it?

Collapse
 
sake_92 profile image
Sakib Hadžiavdić

Thanks! :) Well, I was referring to server-side dynamics. Here you run sbt hepek, change a few files and they get rendered to files. You copy them to your server and serve them statically...

Of course you can have your Javascript do whatever you want to. You could even try to use Play, ScalaJS and ScalaCSS and build everything from Scala... :D

Or did I miss the point?

Collapse
 
scheidig profile image
Albrecht Scheidig

Not sure :-)
What we implemented was server-side, too. Groovy is a JVM language like Scala is, and it also supports traits etc. And you can implement your own DSLs, supporting syntax similar to yours:

div(class: "xyz") {
  span("Text goes here")
}

But we used it inside our web application server to create dynamic content, thus accessing context.

And I guess your approach would also be capable to support dynamic content.

Thread Thread
 
sake_92 profile image
Sakib Hadžiavdić

Oh, I see now. I forgot to mention here that I'm using Scalatags library (not mine)... Similar stuff to yours. Keep hacking! :D