We could have something like<div><br></div><div>class DomId a where</div><div> toDomId :: a -> Text</div><div><br></div><div><div>class DomClass a where</div><div> toDomClass :: a -> Text</div></div><div><br></div>
<div>That hamlet calls on id and class insertions. Michael would no better if that is possible with the hamlet internals.</div><div><br></div><div><br><div class="gmail_quote">On Fri, Apr 8, 2011 at 7:03 AM, Max Cantor <span dir="ltr"><<a href="mailto:mxcantor@gmail.com">mxcantor@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">In an effort to get more type-checked goodness in hamlet, I started using string constants for all my dom IDs and classes. We're not using the newIdent function because I want control over what the IDs and classes will be named.<br>
<br>
I wrote up a little typeclass as such:<br>
<br>
class CustomIdentString a where jqVal :: a -> String; idVal :: a -> String<br>
<br>
newtype CustomIdentCls = MkCls String<br>
instance CustomIdentString CustomIdentCls where<br>
jqVal (MkCls s) = "." ++ s; idVal (MkCls s) = s;<br>
<br>
newtype CustomIdentId = MkId String<br>
instance CustomIdentString CustomIdentId where<br>
jqVal (MkId s) = "#" ++ s; idVal (MkId s) = s;<br>
<br>
This way, I can refer to divs in javascript using:<br>
$("#{jqVal myId}").foo..<br>
<br>
And create the elements in hamlet using<br>
<div ##{idVal myId}> ...<br>
<br>
I'm wondering is there a datatype for IDs and Classes that I can use to make the IDs and Classes directly so that:<br>
<div .#{foo myId}> and <div ##{foo myCls}><br>
would fail to typecheck?<br>
<br>
In general, are there any good, safe ways to do this instead of just unwrapping to strings?<br>
<br>
max<br>
_______________________________________________<br>
web-devel mailing list<br>
<a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
</blockquote></div><br></div>