@@ -1,96 +0,0 @@
1−{-# LANGUAGE TemplateHaskell #-}
2−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3−{-# LANGUAGE FlexibleInstances #-}
5−{-# OPTIONS_GHC -fno-warn-missing-fields #-}
7−-- | This module contains Shakespearean (see "Text.Shakespeare") templates
8−-- for Elm. It introduces type-safe compile-time variable and URL
9−-- interpolation. A typeclass @'ToElm'@ is provided for interpolated
12−-- Further reading on Shakespearean templates:
13−-- <http://www.yesodweb.com/book/templates>
15−-- Further reading on Elm: <http://elm-lang.org>
16−module Language.Elm.Quasi
18− -- ** Template-Reading Functions
19− -- |These QuasiQuoters return functions of the type @(t -> 'Elm')@
20− -- where @t@ is the URL rendering function if type-safe URLs are used.
22− -- A usage example for both type-safe (Yesod) and standard path segment
23− -- (Happstack) URLs is provided in the Examples folder in the Git
32− -- * Typeclass for interpolated variables
35− -- ** Rendering Functions
40−import Language.Haskell.TH.Quote (QuasiQuoter (..))
41−import Language.Haskell.TH.Syntax
42−import Data.Text.Lazy.Builder (Builder, fromText, toLazyText, fromLazyText)
44−import qualified Data.Text as TS
45−import qualified Data.Text.Lazy as TL
46−import Text.Shakespeare
48−-- | Render Elm to lazy Text.
49−renderElm :: Elm -> TL.Text
50−renderElm (Elm b) = toLazyText b
52−-- | Newtype wrapper of 'Builder'.
53−newtype Elm = Elm { unElm :: Builder }
56−-- | A typeclass for types that can be interpolated in Elm templates.
58− toElm :: a -> Builder
59−instance ToElm [Char] where toElm = fromLazyText . TL.pack
60−instance ToElm TS.Text where toElm = fromText
61−instance ToElm TL.Text where toElm = fromLazyText
63−elmSettings :: Q ShakespeareSettings
67− unWrapExp <- [|unElm|]
68− return $ defaultShakespeareSettings { toBuilder = toJExp
73−-- |QuasiQuoter for embedding Elm code inside of Haskell code.
76−-- @[elm|main = plaintext \"Some elm code\"|]@
78−elm = QuasiQuoter { quoteExp = \s -> do
80− quoteExp (shakespeare rs) s
83−-- |A Template Haskell function for embedding Elm code from external
87−-- @$(elmFile \"elm_source/index.elm\")@
88−elmFile :: FilePath -> Q Exp
91− shakespeareFile rs fp
93−elmFileReload :: FilePath -> Q Exp
96− shakespeareFileReload rs fp