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

Safe HaskellNone
LanguageHaskell98

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

Documentation

type TextUrl url = RenderUrl url -> Builder Source #

class ToText a where Source #

Methods

toText :: a -> Builder Source #

Instances
ToText Int Source # 
Instance details

Defined in Text.Shakespeare.Text

Methods

toText :: Int -> Builder Source #

ToText Int32 Source # 
Instance details

Defined in Text.Shakespeare.Text

Methods

toText :: Int32 -> Builder Source #

ToText Int64 Source # 
Instance details

Defined in Text.Shakespeare.Text

Methods

toText :: Int64 -> Builder Source #

ToText Builder Source # 
Instance details

Defined in Text.Shakespeare.Text

ToText Text Source # 
Instance details

Defined in Text.Shakespeare.Text

Methods

toText :: Text -> Builder Source #

ToText Text Source # 
Instance details

Defined in Text.Shakespeare.Text

Methods

toText :: Text -> Builder Source #

ToText [Char] Source # 
Instance details

Defined in Text.Shakespeare.Text

Methods

toText :: [Char] -> Builder Source #

stext :: QuasiQuoter Source #

"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 Source #

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

Since: 2.0.22

textFileDebug :: FilePath -> Q Exp Source #

Deprecated: Please use textFileReload instead

strict text

lazy text, same as stext :)

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

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

codegen :: QuasiQuoter Source #

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 Source #

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