On 09/07/2015 10:39 AM, Dan Gravell wrote:
> I think I've missed something here. I've always hated having to generate:
>
> <img src="/images/an-image.png"/>
There is SHtml.link() but it returns an <a> element, it doesn't expose
an API to get only the href URL. I have this workaround
def linkSrc(to: String, func: () => Any): String = {
// WORKAROUND generate link URL, get it from an "a" tag because
there is no
// exposed API
SHtml.link(to, func, NodeSeq.Empty).attribute("href").get.text
}
I serve audio using it, for example:
val func = { () =>
val r = fileResponse(f.openStream(), f.length, "audio/ogg;
codecs=opus", None)
throw shortcutResponse(r)
}
<audio src={ SHtml.linkSrc("/download/audio", func) }/>
fileResponse just build a StreamingResponse
>
> Then have either serve that URL from the static web resources or have a
> well-known URL pass to a DispatchPF.
>
> Is there a way of doing this inline in code? I think that would be more
> elegant and potentially more performant at the expense of a bit of
> memory. I'm thinking of something to associate a function with the
> generated img src attribute which then returns the bytes for the image.
>
> Dan
>
> <mailto:
liftweb+u...@googlegroups.com>.