shakespeare-2.0.5: A toolkit for making compile-time interpolated templates

Safe HaskellNone
LanguageHaskell98

Text.Coffee

Contents

Description

A Shakespearean module for CoffeeScript, introducing type-safe, compile-time variable and url interpolation. It is exactly the same as Text.Julius, except that the template is first compiled to Javascript with the system tool coffee.

To use this module, coffee must be installed on your system.

#{...} is the Shakespearean standard for variable interpolation, but CoffeeScript already uses that sequence for string interpolation. Therefore, Shakespearean interpolation is introduced with %{...}.

If you interpolate variables, the template is first wrapped with a function containing javascript variables representing shakespeare variables, then compiled with coffee, and then the value of the variables are applied to the function. This means that in production the template can be compiled once at compile time and there will be no dependency in your production system on coffee.

Your code:

  b = 1
  console.log(#{a} + b)

Function wrapper added to your coffeescript code:

((shakespeare_var_a) =>
  b = 1
  console.log(shakespeare_var_a + b)
)

This is then compiled down to javascript, and the variables are applied:

;(function(shakespeare_var_a){
  var b = 1;
  console.log(shakespeare_var_a + b);
})(#{a});

Further reading:

  1. Shakespearean templates: http://www.yesodweb.com/book/templates
  2. CoffeeScript: http://coffeescript.org/

Synopsis

Functions

Template-Reading Functions

These QuasiQuoter and Template Haskell methods return values of type JavascriptUrl url. See the Yesod book for details.

coffee :: QuasiQuoter Source

Read inline, quasiquoted CoffeeScript.

coffeeFile :: FilePath -> Q Exp Source

Read in a CoffeeScript template file. This function reads the file once, at compile time.

coffeeFileReload :: FilePath -> Q Exp Source

Read in a CoffeeScript template file. This impure function uses unsafePerformIO to re-read the file on every call, allowing for rapid iteration.

coffeeFileDebug :: FilePath -> Q Exp Source

Deprecated: Please use coffeeFileReload instead.

Deprecated synonym for coffeeFileReload