[Ur] PATCH: add inlineScript directive
Adam Chlipala
adamc at impredicative.com
Sat Sep 24 10:18:24 EDT 2011
austin seipp wrote:
> The two main things people want here are JavaScript and CSS
> I'd suppose. The boilerplate can roughly be put down to something like
> this (Zachary Tatlock put this trick on the list earlier):
>
> val inlineStuff = "..."
>
> fun retStuff () = retBlob (textBlob inlineStuff) (blessMime "text/css")
> ...
> <link type="text/css" href={url (retStuff ())}/>
>
> I notice there is no 'script' tag in basis. This makes it not possible
> to use this trick for JavaScript, hence why I went the route of
> modifying the compiler. Although I assume it could be added quite
> easily, so kinda moot point.
>
It sounds very scary to me to allow <script> in Ur/Web programs. I
don't want to allow any automatic interpretation of strings as programs
in any language.
> Perhaps there should be another top-level declaration for 'static'
> files, which declare values of a new 'static' type or somesuch?
> Something like:
>
> static cssCode
> static jsCode
> ...
> <script type="text/javascript" href={staticUrl cssCode}/>
> <link type="text/css" href={staticUrl jsCode}/>
>
Adding a new declaration form seems like overkill to me. What I've been
thinking about is closer to just the second stage that you propose:
> with accompanying .urp declarations like:
>
> staticFile Module.cssCode=static/style.css text/css
> staticFile Module.jsCode=static/extra.js text/javascript
>
I'd do this with directives instead taking filename to grab data from,
URL to "mount" it at, and MIME type. I would also allow omitting the
MIME type, in which case it is reverse-engineered from the file
extension using /etc/mime.types. I would also automatically whitelist
each URL given in this manner, for injection into the [url] type.
More information about the Ur
mailing list