Using the C preprocessor as an HTML templating engine
1–10 of 34 posts
Re: Using the C preprocessor as an HTML templating engine
#2Re: Using the C preprocessor as an HTML templating engine
#3Why not use SSI[1]? It's inspired by the CPP's syntax, but is supported directly by most HTTP servers (and is more powerful, to boot).
Re: Using the C preprocessor as an HTML templating engine
#4I ended up using a Perl preprocessor, but it seems like cpp would work ok-ish for certain use cases that don’t require, say, strict tabs like Python among a few other things mentioned on the cpp manual.
Re: Using the C preprocessor as an HTML templating engine
#5Re: Using the C preprocessor as an HTML templating engine
#6Re: Using the C preprocessor as an HTML templating engine
#7Seems like a bad idea, given that the CPP and HTML have a fair number of overlapping tokens (e.g. `#` for both URL fragments and macro beginnings). Why not use SSI[1]? It's inspired by the CPP's syntax, but is supported directly by most HTTP servers (and is more powerful, to boot). [1]: https://en.wikipedia.org/wiki/Server_Side_Includes
Re: Using the C preprocessor as an HTML templating engine
#8I was considering doing something like this just the other day. It had a gnuplot script and it seemed to me that it would be so much more versatile if I could use #ifdefine and #include in it. I ended up using a Perl preprocessor, but it seems like cpp would work ok-ish for certain use cases that don’t require, say, strict tabs like Python among a few other things mentioned on the cpp manual.
I've used it in the past for wrangling the definitions of a multitude of SQL triggers I was using to generate a real-time materialized view. The fact that you can modify its syntax is very helpful for making it work with non-C syntaxes (like SQL or even LaTeX).
It even has an HTML mode built-in, which you can customize to your needs, but looks like:
which works better for certain WYSIWYG editors. You could modify the syntax to be
Re: Using the C preprocessor as an HTML templating engine
#9Seems like a bad idea, given that the CPP and HTML have a fair number of overlapping tokens (e.g. `#` for both URL fragments and macro beginnings). Why not use SSI[1]? It's inspired by the CPP's syntax, but is supported directly by most HTTP servers (and is more powerful, to boot). [1]: https://en.wikipedia.org/wiki/Server_Side_Includes
# is only processed by cpp when it's the first non-whitespace character in a line so that shouldn't be an issue in the real world. But, yeah, SSI.