[web-devel] [Yesod] Bookmarklet web app development.

Michael Snoyman michael at snoyman.com
Mon Feb 21 06:56:57 CET 2011

When writing a Julius template, you can embed type-safe URL values
inside using @{...} interpolation. At the end of the day, however,
Julius needs to be able to send a String version of that URL to the
user. Julius itself knows nothing of how to convert your RootR (or
whatever) value into a String, so it needs some help. Therefore, the
type sig of a Julius template is:

    type Julius url = Render url -> Javascript
    type Render url = url -> QueryString -> String
    type QueryString = [(String, String)]

The idea is that the render function will be able to take any route
and a list of query string parameters and create a string version of
your route. A simple example might be:

    data MyRoute = RootR | PersonR String
    myRender RootR [] = "http://www.example.com/"
    myRender (PersonR "michael") [("age", "26")] =

And so on and so forth. Once you have this function, you can
automatically convert a Julius to a Javascript value, eg:

    [$julius|alert("Go to @{PersonR "michael"}")|] myRender :: Javascript

You can then use renderJavascript to convert a Javascript value into a
bytestring. As a convenience, we also have renderJulius, which simply

    renderJulius :: Render url -> Julius url -> ByteString
    renderJulius r j = renderJavascript $ r j

Hope that helps,

On Sun, Feb 20, 2011 at 10:25 PM, Ian Duncan <iand675 at gmail.com> wrote:
> renderJulius is indeed what you want.
> renderJulius takes a route rendering function for the first argument and
> then a quasiquoted Julius expression. Unfortunately there's not an
> explanation exactly how renderJulius's first argument works, but it's
> definitely related to how it renders routes.
> Perhaps Michael can give us an intuition on that.
> #{} interpolated stuff works without any special effort.
> Once it's clear how to use the first argument, you should be able to just
> write out the data either to a temporary file and give that to your user or
> just embed the rendered javascript in a link on a page and have the user
> drag it to their toolbar.
> --
> Ian Duncan
> On Sunday, February 20, 2011 at 6:08 AM, William Pearson wrote:
> On 20 February 2011 05:22, Ian Duncan <iand675 at gmail.com> wrote:
> William,
> It sounds like you should be able to do what you want to do. You can render
> type-safe urls with Julius using @{type-safe-url} escapes and other stuff
> using #{whatever} escapes. No need to sacrifice there. Is that what you were
> asking? I'm not quite clear on what your dilemma is.
> The problem is creating a function of type a -> Handler (Content,
> ContentType) where Content is not a static javascript file, but
> created from a Julius or Cassius template.
> addJulius is not what I want because it returns a GWidget which I need
> to add to a defaultLayout or something. Which even if I had a blank
> default layout as a subsite would put it in script tags, I think.
> renderJulius looks like what I want but I haven't found examples of it's
> use.
> Does that make things clearer?
> Will
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel

More information about the web-devel mailing list