I’m writing a moderately complex script for Greasemonkey. Part of it is generating a big blob of HTML and CSS and cramming it into the page. I’d like to keep these HTML and CSS blobs as separate files in my source tree, since:
- Javascript has no multiline strings, so either I get a huge line, or lots of concatenation, or line continuations. Ugly.
- The files evolve at different rates, so having them as separate files in Git is notionally better
- My text editor can set the mode properly when it’s not one document embedded in another
Among many other things.
Unfortunately, Greasemonkey scripts are only ever a single script, not a bundle, so I have to inline the HTML and CSS at some point. I’m trying to find a good build system for this workflow. Building for distribution would involve copying from the HTML and CSS into the user script.
My first instinct was to use make the C preprocessor and #include, but this only works on lines, so doing something like:
var panel = document.createElement('div');
panel.innerHTML = '#include "panel.html"';
Doesn’t work.
What I’m looking for is something exactly like http://js-preprocessor.com/ , but that doesn’t throw a “wrong number of arguments” error when I run it. 😛
I ended rolling my own in Python. It’s not exactly trivial (~50 LOC), thg435, but it does the job. Brock Adams’ CDATA multiline string makes it easier.