Text.Shakespeare

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

Safe Haskell | None
Language | Haskell98

Text.Shakespeare

Contents

- low-level
- Internal

Description

NOTE: This module should be considered internal, and will be hidden in 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 #

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 # |
Methods lift :: ShakespeareSettings -> Q Exp #

data PreConvert #

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

Lift PreConvert # |
Methods lift :: PreConvert -> Q Exp #

data WrapInsertion #

Constructors

WrapInsertion |
Fields wrapInsertionIndent :: Maybe String wrapInsertionStartBegin :: String wrapInsertionSeparator :: String wrapInsertionStartClose :: String wrapInsertionEnd :: String wrapInsertionAddParens :: Bool

Instances

Lift WrapInsertion # |
Methods lift :: WrapInsertion -> Q Exp #

data PreConversion #

Constructors

ReadProcess String [String] |
Id |

Instances

Lift PreConversion # |
Methods lift :: PreConversion -> Q Exp #

defaultShakespeareSettings :: ShakespeareSettings #

shakespeare :: ShakespeareSettings -> QuasiQuoter #

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

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

# low-level

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

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

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

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

data VarType #

Constructors

VTPlain |
VTUrl |
VTUrlParam |
VTMixin |

Instances

Bounded VarType # |
Methods minBound :: VarType # maxBound :: VarType #
Enum VarType # |
Methods succ :: VarType -> VarType # pred :: VarType -> VarType # toEnum :: Int -> VarType # fromEnum :: VarType -> Int # enumFrom :: VarType -> [VarType] # enumFromThen :: VarType -> VarType -> [VarType] # enumFromTo :: VarType -> VarType -> [VarType] # enumFromThenTo :: VarType -> VarType -> VarType -> [VarType] #
Eq VarType # |
Methods (==) :: VarType -> VarType -> Bool # (/=) :: VarType -> VarType -> Bool #
Data VarType # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> VarType -> c VarType # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c VarType # toConstr :: VarType -> Constr # dataTypeOf :: VarType -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c VarType) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c VarType) # gmapT :: (forall b. Data b => b -> b) -> VarType -> VarType # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> VarType -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> VarType -> r # gmapQ :: (forall d. Data d => d -> u) -> VarType -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> VarType -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> VarType -> m VarType # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> VarType -> m VarType # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> VarType -> m VarType #
Ord VarType # |
Methods compare :: VarType -> VarType -> Ordering # (<) :: VarType -> VarType -> Bool # (<=) :: VarType -> VarType -> Bool # (>) :: VarType -> VarType -> Bool # (>=) :: VarType -> VarType -> Bool # max :: VarType -> VarType -> VarType # min :: VarType -> VarType -> VarType #
Show VarType # |
Methods showsPrec :: Int -> VarType -> ShowS # show :: VarType -> String # showList :: [VarType] -> ShowS #
Generic VarType # |
Associated Types type Rep VarType :: * -> * # Methods from :: VarType -> Rep VarType x # to :: Rep VarType x -> VarType #
type Rep VarType # |
type Rep VarType = D1 (MetaData "VarType" "Text.Shakespeare" "shakespeare-2.0.11.1-3SyyZoWFAdPC9dHlPUb5aq" False) ((:+:) ((:+:) (C1 (MetaCons "VTPlain" PrefixI False) U1) (C1 (MetaCons "VTUrl" PrefixI False) U1)) ((:+:) (C1 (MetaCons "VTUrlParam" PrefixI False) U1) (C1 (MetaCons "VTMixin" PrefixI False) U1)))

data Deref #

Instances

Eq Deref # |
Methods (==) :: Deref -> Deref -> Bool # (/=) :: Deref -> Deref -> Bool #
Data Deref # |
Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Deref -> c Deref # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Deref # toConstr :: Deref -> Constr # dataTypeOf :: Deref -> DataType # dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Deref) # dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Deref) # gmapT :: (forall b. Data b => b -> b) -> Deref -> Deref # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Deref -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Deref -> r # gmapQ :: (forall d. Data d => d -> u) -> Deref -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Deref -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Deref -> m Deref # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Deref -> m Deref # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Deref -> m Deref #
Ord Deref # |
Methods compare :: Deref -> Deref -> Ordering # (<) :: Deref -> Deref -> Bool # (<=) :: Deref -> Deref -> Bool # (>) :: Deref -> Deref -> Bool # (>=) :: Deref -> Deref -> Bool # max :: Deref -> Deref -> Deref # min :: Deref -> Deref -> Deref #
Read Deref # |
Methods readsPrec :: Int -> ReadS Deref # readList :: ReadS [Deref] # readPrec :: ReadPrec Deref # readListPrec :: ReadPrec [Deref] #
Show Deref # |
Methods showsPrec :: Int -> Deref -> ShowS # show :: Deref -> String # showList :: [Deref] -> ShowS #
Lift Deref # |
Methods lift :: Deref -> Q Exp #

type Parser = Parsec String [String] #

A parser with a user state of [String]

preFilter #

Arguments

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

# Internal

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

pack' :: String -> Text #