[web-devel] [Hamlet] CSS size wrapper

Dmitry Kurochkin dmitry.kurochkin at gmail.com
Tue Feb 15 21:55:59 CET 2011


Hi Yesod developers.

Attached are two modules to implement CSS size wrappers for Hamlet. It
implements several types for different CSS units:

  * em - EmSize
  * ex - ExSize
  * px - PixelSize
  * % - PercentageSize
  * cm, in, mm, pc, pt - AbsoluteSize

You can create them using an mkSize Template Haskell function, e.g.

  let size = $(mkSize "100%")

All types are instances of Show, Eq, Ord, Num, Fractional and ToCss.
This allows you to do math and interpolate it to Hamlet.

Ideally, I wanted to have only one type and make an implicit conversion
from string literals. But I do not know how to forbid mixing of
incompatible units in math (e.g. 10px + 10cm) with a single type. And I
do not know how to make implicit conversion from string literals with
multiple types.

I would appreciate any comments. Including on naming style, type design,
API and overall usefulness. Keep in mind that this is the first time I
use Template Haskell, so the code may be not optimal and plain ugly
(e.g. can we use quasi quotes instead of directly messing with TH?)

BTW Michael, one more thing I miss in Hamlet is defining variables in
templates. I would prefer to put simple CSS-related constants directly
in Cassius instead of a dedicated module. Is it possible to implement?

Regards,
  Dmitry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MkSizeType.hs
Type: text/x-haskell
Size: 2745 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110215/cee1c4f4/attachment.hs>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Size.hs
Type: text/x-haskell
Size: 4247 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110215/cee1c4f4/attachment-0001.hs>


More information about the web-devel mailing list