Maybe instead of adding classes to FieldSettings, we should have just added arbitrary attributes, which would solve this and a number of other problems. The downside is that, with current Hamlet syntax, it would be very difficult to add arbitrary attributes. Maybe we should also add a new construct (syntax up for debate):
let attrs = [("foo", "bar"), ("baz", "bin")]
html = [shamlet|<tag @attrs>|]
print html -- <tag foo="bar" baz="bin"></tag>
Any thoughts?
Michael
I like both ideas, but I'd like to bikeshed on the syntax. I think
that @ is bad choice since we may already have something like <a
href=@{RouteR}>. Greg's idea of using # is something I don't like as
well for the same reason. I propose using ^, such as <tag ^{attrs}>.
It's unambigous since ^ can't appear inside tags right now, and
semantically it is close to including a Widget, but on a smaller
scale.
Cheers! =)
--
Felipe.
<tag #{key}=value>
But in theory, we might want to add it. Now imagine that key ==
"checked". It would be perfectly reasonable for somebody to want to
write:
<input type=checkbox #{key}>
and expected the result to be "<input type='checkbox' checked>".
The reason I used @ is that XPath uses @ for attributes, but I don't
think it's really good since we use @ for URLs.
Michael
attr (k,v) = T.concat [k,"=",v])
instance ToHtml [(Text, Text)] where
toHtml = toHtml . T.intercalate " " . map attr
or
instance ToHtml Attrs where
toHtml (Attrs pairs) = toHtml . T.intercalate " " $ map attr pairs
I'm not too familiar with ToHtml, but with this works, then I don't
have any problems with it =).
Cheers,
--
Felipe.
If we want correctness, it may still make sense to re-use #{} but
expand it as toAttribute. I would much prefer that over using @ or ^,
although using an entirely different symbol could be better.
I looked at the source, and realized that for Hamlet we do not have a
ToHtml typeclass right now. I think creating a ToHtml typeclass would
have its own merits - it would give hamlet some of the same
extensibility as the rest of shakespeare.
Another possibility would be to use ^{} as suggested, but with a
ToWidget typeclass that will automatically convert our attributes.
I want to be convinced that we have exhausted the possibilities of our
existing syntax before making it context-sensitive.
I like *{} the best also. I think it is important to stick with our
bracketed interpolation for consistency. I think it is easy to explain
#{} as ToHtml in Hamlet, ToJavascript is Julius, etc, and ^{} as
widget interpolation in all three. Explaining *{} as attribute
interpolation (we will probably end up with a ToAttribute typeclass)
is easy, and we can allow #{} and ^{} in the attributes in the future
if needed.
What about OP's problem with yesod-form, then?
--
Felipe.