Use Shakespeare-text and external file

713 views Asked by At

How can I convert the below example to use an external file instead of the embedded lazy text quasi quotes?

{-# LANGUAGE QuasiQuotes, OverloadedStrings #-}
import Text.Shakespeare.Text
import qualified Data.Text.Lazy.IO as TLIO
import Data.Text (Text)
import Control.Monad (forM_)

data Item = Item
    { itemName :: Text
    , itemQty :: Int
    }

items :: [Item]
items =
    [ Item "apples" 5
    , Item "bananas" 10
    ]

main :: IO ()
main = forM_ items $ \item -> TLIO.putStrLn
    [lt|You have #{show $ itemQty item} #{itemName item}.|]

This is from the yesod online book.

1

There are 1 answers

4
Michael Snoyman On

You can use the textFile function, along the lines of $(textFile "some-file").