implicit function producing an attribute

瀏覽次數:29 次
跳到第一則未讀訊息

Byron Weber Becker

未讀,
2015年8月12日 下午3:35:532015/8/12
收件者:Scalatags
I'd like to create an implicit definition to convert from an object I don't have control over to a scalatags attribute.  

The use case is:

(a href := /* do some funky things to myObj to get a URL as a string */)(...)

This works, but what I'd like to write is simply

(a href := myObj)(...)

and have an implicit to the funky stuff for me.

What I want to write generates the following error message:

[error] Test.scala:47: No AttrValue defined for type MyObj; scalatags does not know how to use MyObj as an attribute

[error]           href := myObj)(...)

[error]                ^

[error] one error found


From this I gather that my implicit should have the following signature:

implicit def MyObjToAttrValue(o : MyObj):AttrValue[String] = ???

So...  Once I coax o to give me a URL as string, how do I turn that URL into an AttrValue?

Thanks,
Byron
回覆所有人
回覆作者
轉寄
0 則新訊息