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

Safe Haskell | Safe-Inferred
Language | Haskell2010

Text.Shakespeare

Contents

- low-level
- Internal

Description

future releases.

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
  - preEscapeIgnoreBalanced :: [Char]
  - preEscapeIgnoreLine :: [Char]
  - wrapInsertion :: Maybe WrapInsertion
  }
- data WrapInsertion = WrapInsertion {
  - wrapInsertionIndent :: Maybe String
  - wrapInsertionStartBegin :: String
  - wrapInsertionSeparator :: String
  - wrapInsertionStartClose :: String
  - wrapInsertionEnd :: String
  - wrapInsertionAddParens :: Bool
  }
- 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
  - = VTPlain
  - | VTUrl
  - | VTUrlParam
  - | VTMixin
- data Deref
- type Parser = Parsec String [String]
- preFilter :: Maybe FilePath -> ShakespeareSettings -> String -> IO String
- shakespeareRuntime :: ShakespeareSettings -> FilePath -> [(Deref, VarExp url)] -> Shakespeare url
- pack' :: String -> Text

# 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

Instances details

Lift ShakespeareSettings Source # |
Instance details Defined in Text.Shakespeare Methods lift :: Quote m => ShakespeareSettings -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => ShakespeareSettings -> Code m ShakespeareSettings Source #

data PreConvert Source #

Coffeescript, TypeScript, and other languages 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.

The problem then is the insertion of Haskell values: we need a hole for them. This can be done with variables known to the language. During the pre-conversion we first modify all Haskell insertions So #{a} is change to shakespeare_var_a Then we can place the Haskell values in a function wrapper that exposes those variables: (function(shakespeare_var_a){ ... shakespeare_var_a ...}) TypeScript can compile that, and then we tack an application of the Haskell values onto the result: (#{a})

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
- preEscapeIgnoreBalanced :: [Char]
- preEscapeIgnoreLine :: [Char]
- wrapInsertion :: Maybe WrapInsertion

#### Instances

Instances details

Lift PreConvert Source # |
Instance details Defined in Text.Shakespeare Methods lift :: Quote m => PreConvert -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => PreConvert -> Code m PreConvert Source #

data WrapInsertion Source #

Constructors

WrapInsertion |

Fields

- wrapInsertionIndent :: Maybe String
- wrapInsertionStartBegin :: String
- wrapInsertionSeparator :: String
- wrapInsertionStartClose :: String
- wrapInsertionEnd :: String
- wrapInsertionAddParens :: Bool

#### Instances

Instances details

Lift WrapInsertion Source # |
Instance details Defined in Text.Shakespeare Methods lift :: Quote m => WrapInsertion -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => WrapInsertion -> Code m WrapInsertion Source #

data PreConversion Source #

Constructors

ReadProcess String [String] |
Id |

#### Instances

Instances details

Lift PreConversion Source # |
Instance details Defined in Text.Shakespeare Methods lift :: Quote m => PreConversion -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => PreConversion -> Code m PreConversion Source #

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 #

Constructors

VTPlain |
VTUrl |
VTUrlParam |
VTMixin |

#### Instances

Instances details

Data VarType Source # |

Instance details

Defined in Text.Shakespeare

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> VarType -> c VarType Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c VarType Source #

toConstr :: VarType -> Constr Source #

dataTypeOf :: VarType -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c VarType) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c VarType) Source #

gmapT :: (forall b. Data b => b -> b) -> VarType -> VarType Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> VarType -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> VarType -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> VarType -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> VarType -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> VarType -> m VarType Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> VarType -> m VarType Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> VarType -> m VarType Source #

Bounded VarType Source # |
Instance details Defined in Text.Shakespeare Methods minBound :: VarType Source # maxBound :: VarType Source #
Enum VarType Source # |

Instance details

Defined in Text.Shakespeare

Methods

succ :: VarType -> VarType Source #

pred :: VarType -> VarType Source #

toEnum :: Int -> VarType Source #

fromEnum :: VarType -> Int Source #

enumFrom :: VarType -> [VarType] Source #

enumFromThen :: VarType -> VarType -> [VarType] Source #

enumFromTo :: VarType -> VarType -> [VarType] Source #

enumFromThenTo :: VarType -> VarType -> VarType -> [VarType] Source #

Generic VarType Source # |
Instance details Defined in Text.Shakespeare Associated Types type Rep VarType :: Type -> Type Source # Methods from :: VarType -> Rep VarType x Source # to :: Rep VarType x -> VarType Source #
Show VarType Source # |
Instance details Defined in Text.Shakespeare Methods showsPrec :: Int -> VarType -> ShowS Source # show :: VarType -> String Source # showList :: [VarType] -> ShowS Source #
Eq VarType Source # |
Instance details Defined in Text.Shakespeare Methods (==) :: VarType -> VarType -> Bool Source # (/=) :: VarType -> VarType -> Bool Source #
Ord VarType Source # |
Instance details Defined in Text.Shakespeare Methods compare :: VarType -> VarType -> Ordering Source # (<) :: VarType -> VarType -> Bool Source # (<=) :: VarType -> VarType -> Bool Source # (>) :: VarType -> VarType -> Bool Source # (>=) :: VarType -> VarType -> Bool Source # max :: VarType -> VarType -> VarType Source # min :: VarType -> VarType -> VarType Source #
type Rep VarType Source # |

Instance details

Defined in Text.Shakespeare

type Rep VarType = D1 ('MetaData "VarType" "Text.Shakespeare" "shakespeare-2.1.0.1-CE72GqjBrzE23L77Nv4ubm" 'False) ((C1 ('MetaCons "VTPlain" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "VTUrl" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "VTUrlParam" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "VTMixin" 'PrefixI 'False) (U1 :: Type -> Type)))

data Deref Source #

#### Instances

Instances details

Data Deref Source # |

Instance details

Defined in Text.Shakespeare.Base

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Deref -> c Deref Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Deref Source #

toConstr :: Deref -> Constr Source #

dataTypeOf :: Deref -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Deref) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Deref) Source #

gmapT :: (forall b. Data b => b -> b) -> Deref -> Deref Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Deref -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Deref -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Deref -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Deref -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Deref -> m Deref Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Deref -> m Deref Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Deref -> m Deref Source #

Read Deref Source # |
Instance details Defined in Text.Shakespeare.Base Methods readsPrec :: Int -> ReadS Deref Source # readList :: ReadS [Deref] Source # readPrec :: ReadPrec Deref Source # readListPrec :: ReadPrec [Deref] Source #
Show Deref Source # |
Instance details Defined in Text.Shakespeare.Base Methods showsPrec :: Int -> Deref -> ShowS Source # show :: Deref -> String Source # showList :: [Deref] -> ShowS Source #
Eq Deref Source # |
Instance details Defined in Text.Shakespeare.Base Methods (==) :: Deref -> Deref -> Bool Source # (/=) :: Deref -> Deref -> Bool Source #
Ord Deref Source # |
Instance details Defined in Text.Shakespeare.Base Methods compare :: Deref -> Deref -> Ordering Source # (<) :: Deref -> Deref -> Bool Source # (<=) :: Deref -> Deref -> Bool Source # (>) :: Deref -> Deref -> Bool Source # (>=) :: Deref -> Deref -> Bool Source # max :: Deref -> Deref -> Deref Source # min :: Deref -> Deref -> Deref Source #
Lift Deref Source # |
Instance details Defined in Text.Shakespeare.Base Methods lift :: Quote m => Deref -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => Deref -> Code m Deref Source #

type Parser = Parsec String [String] Source #

A parser with a user state of [String]

preFilter Source #

Arguments

:: Maybe FilePath | for error reporting
-> ShakespeareSettings |
-> String |
-> IO String |

# Internal

shakespeareRuntime :: ShakespeareSettings -> FilePath -> [(Deref, VarExp url)] -> Shakespeare url Source #

pack' :: String -> Text Source #