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

Safe Haskell | None
Language | Haskell2010

Text.Shakespeare.Text

Description

A Shakespearean module for general text processing, introducing type-safe, compile-time variable interpolation.

Text templates use the same parser as for other shakespearean templates which enables variable interpolation using `#{..}`. The parser also recognize the @`{..}` and `^{..}` syntax.

If it is necessary that your template produces the output containing one of the interpolation syntax you can escape the sequence using a backslash:

    λ> :set -XQuasiQuotes
    λ> let bar = 23 :: Int in [st|#{bar}|] :: Text

produces "23", but

    λ> let bar = 23 :: Int in [st|#\{bar}|] :: Text

returns "#{bar}". The escaping backslash is removed from the output.

Further reading: Shakespearean templates: https://www.yesodweb.com/book/shakespearean-templates

Synopsis

- type TextUrl url = RenderUrl url -> Builder
- class ToText a where
  - toText :: a -> Builder
- renderTextUrl :: RenderUrl url -> TextUrl url -> Text
- stext :: QuasiQuoter
- stextFile :: FilePath -> Q Exp
- text :: QuasiQuoter
- textFile :: FilePath -> Q Exp
- textFileDebug :: FilePath -> Q Exp
- textFileReload :: FilePath -> Q Exp
- st :: QuasiQuoter
- lt :: QuasiQuoter
- sbt :: QuasiQuoter
- lbt :: QuasiQuoter
- codegen :: QuasiQuoter
- codegenSt :: QuasiQuoter
- codegenFile :: FilePath -> Q Exp
- codegenFileReload :: FilePath -> Q Exp

# Documentation

type TextUrl url = RenderUrl url -> Builder #

class ToText a where #

Methods

toText :: a -> Builder #

#### Instances

Instances details

ToText Int32 # |
Instance details Defined in Text.Shakespeare.Text Methods toText :: Int32 -> Builder #
ToText Int64 # |
Instance details Defined in Text.Shakespeare.Text Methods toText :: Int64 -> Builder #
ToText Text # |
Instance details Defined in Text.Shakespeare.Text Methods toText :: Text -> Builder #
ToText Builder # |
Instance details Defined in Text.Shakespeare.Text Methods toText :: Builder -> Builder #
ToText Text # |
Instance details Defined in Text.Shakespeare.Text Methods toText :: Text -> Builder #
ToText Int # |
Instance details Defined in Text.Shakespeare.Text Methods toText :: Int -> Builder #
ToText [Char] # |
Instance details Defined in Text.Shakespeare.Text Methods toText :: [Char] -> Builder #

renderTextUrl :: RenderUrl url -> TextUrl url -> Text #

stext :: QuasiQuoter #

"Simple text" quasi-quoter. May only be used to generate expressions.

Generated expressions have type `Text`.

    >>> do let x = "world"
           putStrLn [stext|Hello, #{x}!|]
    Hello, world!

stextFile :: FilePath -> Q Exp #

Like `stext`, but reads an external file at compile-time.

Since: 2.0.22

text :: QuasiQuoter #

textFile :: FilePath -> Q Exp #

textFileDebug :: FilePath -> Q Exp #

Deprecated: Please use textFileReload instead

textFileReload :: FilePath -> Q Exp #

st :: QuasiQuoter #

strict text

lt :: QuasiQuoter #

lazy text, same as stext :)

sbt :: QuasiQuoter #

strict text whose left edge is aligned with bar ('|')

lbt :: QuasiQuoter #

lazy text, whose left edge is aligned with bar ('|') * Yesod code generation

codegen :: QuasiQuoter #

codegen is designed for generating Yesod code, including templates So it uses different interpolation characters that won't clash with templates. You can use the normal text quasiquoters to generate code

codegenSt :: QuasiQuoter #

Generates strict Text codegen is designed for generating Yesod code, including templates So it uses different interpolation characters that won't clash with templates.

codegenFile :: FilePath -> Q Exp #

codegenFileReload :: FilePath -> Q Exp #