[Ur] New support for CSS code in Ur/Web source

Adam Chlipala adamc at impredicative.com
Sun May 6 16:16:24 EDT 2012


Based on the earlier discussion on this list, I've pushed some new 
support for embedded CSS style code, to the public Mercurial repo:
     http://hg.impredicative.com/urweb

There is some new documentation in the manual and in the types of new 
basis.urs functions, but here's the quick summary:

You should now be able to write 'class' and 'style' attribute values 
just as in standard HTML; that is, as string literals with normal HTML 
syntax.  Class names will need to resolve to Ur/Web identifiers, and I 
haven't put in support for all CSS syntax yet.  Rather, I chose what 
seems like a reasonable, safe subset (e.g., no support for quoted 
strings or character escaping), and I will consider adding more upon 
request.

The old 'dynClass' HTML pseudo-attribute remains, for specifying a 
[signal] value that lets the class of a tag vary reactively.  There is 
now also 'dynStyle', whose meaning you can probably guess!

To get the compiler to desugar standard CSS syntax for you, you can also 
pass string literals to the pseudo-functions [CLASS] and [STYLE].  (It 
is intentional that these aren't _real_ functions that you could call at 
runtime; that could allow scary injection attacks.)

In preparation for building a library to interface with Twitter's 
Bootstrap CSS library, I also added the option to use .urp directives like:
     rewrite style Bootstrap/* [-]
to render all CSS class names with hyphens instead of underscores.


This was the last feature I wanted to add before the next Ur/Web 
release, which I hope to make in the next few days.  So, bug reports 
will be appreciated!



More information about the Ur mailing list