yesodweb/hamlet — pull request #36 by gregwebs (2012-01-28 02:27:49+00:00)
Title: perform coffeescript conversion at compile time

-- | The Coffeescript language compiles down to Javascript.
-- Previously we waited until the very end, at the rendering stage to perform this compilation.
-- Lets call is a post-conversion
-- This had the advantage that all Haskell values were inserted first:
-- for example a value could be inserted that Coffeescript would compile into Javascript.
-- While that is perhaps a safer approach, the advantage is not used in practice:
-- it was that way mainly for ease of implementation.
-- The down-side is the template must be compiled down to Javascript during every request.
-- If instead we do a pre-conversion to compile down to Javascript,
-- we only need to perform the compilation once.
-- During the pre-conversion we first modify all Haskell insertions
-- so that they will be ignored by the Coffeescript compiler (backticks).
-- So %{var} is change to `%{var}` using the preVar function.

The tests fail because I have a shim for the lift instance corresponding to my additions to the Shakespeare settings. The PreConvert settings are apropriately abstract now, but if need be they can be changed so there are no String -> String functions and instead just String settings. However, we still need a PreConvert function. We could just hard-code that into Shakespeare.js: let me know what approach is needed.