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

Safe Haskell | None

Text.Shakespeare

Contents

- low-level

Description

For lack of a better name... a parameterized version of Julius.

Synopsis

- data ShakespeareSettings = ShakespeareSettings {
  - varChar :: Char
  - urlChar :: Char
  - intChar :: Char
  - toBuilder :: Exp
  - wrap :: Exp
  - unwrap :: Exp
  - justVarInterpolation :: Bool
  - preConversion :: Maybe PreConvert
  - modifyFinalValue :: Maybe Exp
  }
- data PreConvert = PreConvert {
  - preConvert :: PreConversion
  - preEscapeBegin :: String
  - preEscapeEnd :: String
  - preEscapeIgnoreBalanced :: [Char]
  - preEscapeIgnoreLine :: [Char]
  }
- data PreConversion
  - = ReadProcess String [String]
  - | Id
- defaultShakespeareSettings :: ShakespeareSettings
- shakespeare :: ShakespeareSettings -> QuasiQuoter
- shakespeareFile :: ShakespeareSettings -> FilePath -> Q Exp
- shakespeareFileReload :: ShakespeareSettings -> FilePath -> Q Exp
- shakespeareFromString :: ShakespeareSettings -> String -> Q Exp
- shakespeareUsedIdentifiers :: ShakespeareSettings -> String -> [(Deref, VarType)]
- type RenderUrl url = url -> QueryParameters -> Text
- data VarType
- data Deref

# Documentation

data ShakespeareSettings Source

Constructors

ShakespeareSettings |

Fields

varChar :: Char
urlChar :: Char
intChar :: Char
toBuilder :: Exp
wrap :: Exp
unwrap :: Exp
justVarInterpolation :: Bool
preConversion :: Maybe PreConvert
modifyFinalValue :: Maybe Exp

  A transformation applied to the final expression. Most often, this would be used to force the type of the expression to help make more meaningful error messages.

Instances

Lift ShakespeareSettings |

data PreConvert Source

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 preEscapeBegin and preEscapeEnd. preEscapeIgnoreBalanced is used to not insert backtacks for variable already inside strings or backticks. coffeescript will happily ignore the interpolations, and backticks would not be treated as escaping in that context. preEscapeIgnoreLine was added to ignore comments (which in Coffeescript begin with a '#')

Constructors

PreConvert |

Fields

preConvert :: PreConversion
preEscapeBegin :: String
preEscapeEnd :: String
preEscapeIgnoreBalanced :: [Char]
preEscapeIgnoreLine :: [Char]

Instances

Lift PreConvert |

data PreConversion Source

Constructors

ReadProcess String [String] |
Id |

Instances

Lift PreConversion |

defaultShakespeareSettings :: ShakespeareSettings Source

shakespeare :: ShakespeareSettings -> QuasiQuoter Source

shakespeareFile :: ShakespeareSettings -> FilePath -> Q Exp Source

shakespeareFileReload :: ShakespeareSettings -> FilePath -> Q Exp Source

# low-level

shakespeareFromString :: ShakespeareSettings -> String -> Q Exp Source

shakespeareUsedIdentifiers :: ShakespeareSettings -> String -> [(Deref, VarType)]Source

Determine which identifiers are used by the given template, useful for creating systems like yesod devel.

type RenderUrl url = url -> QueryParameters -> Text Source

data VarType Source

data Deref Source

Instances

Eq Deref |
Data Deref |
Ord Deref |
Read Deref |
Show Deref |
Typeable Deref |
Lift Deref |