-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A toolkit for making compile-time interpolated templates -- -- Shakespeare is a family of type-safe, efficient template languages. -- Shakespeare templates are expanded at compile-time, ensuring that all -- interpolated variables are in scope. Variables are interpolated -- according to their type through a typeclass. -- -- Shakespeare templates can be used inline with a quasi-quoter or in an -- external file. -- -- Note there is no dependency on haskell-src-extras. Instead Shakespeare -- believes logic should stay out of templates and has its own minimal -- Haskell parser. -- -- Packages that use this: xml-hamlet -- -- Please see the documentation at -- http://www.yesodweb.com/book/shakespearean-templates for more -- details. @package shakespeare @version 2.0.13 -- | General parsers, functions and datatypes for all Shakespeare -- languages. module Text.Shakespeare.Base data Deref DerefModulesIdent :: [String] -> Ident -> Deref DerefIdent :: Ident -> Deref DerefIntegral :: Integer -> Deref DerefRational :: Rational -> Deref DerefString :: String -> Deref DerefBranch :: Deref -> Deref -> Deref DerefList :: [Deref] -> Deref DerefTuple :: [Deref] -> Deref newtype Ident Ident :: String -> Ident type Scope = [(Ident, Exp)] parseDeref :: UserParser a Deref parseHash :: UserParser a (Either String Deref) parseVar :: Char -> UserParser a (Either String Deref) parseVarString :: Char -> UserParser a (Either String String) parseAt :: UserParser a (Either String (Deref, Bool)) parseUrl :: Char -> Char -> UserParser a (Either String (Deref, Bool)) parseUrlString :: Char -> Char -> UserParser a (Either String String) parseCaret :: UserParser a (Either String Deref) parseUnder :: UserParser a (Either String Deref) parseInt :: Char -> UserParser a (Either String Deref) parseIntString :: Char -> UserParser a (Either String String) derefToExp :: Scope -> Deref -> Exp flattenDeref :: Deref -> Maybe [String] readUtf8File :: FilePath -> IO Text instance GHC.Classes.Ord Text.Shakespeare.Base.Deref instance Data.Data.Data Text.Shakespeare.Base.Deref instance GHC.Read.Read Text.Shakespeare.Base.Deref instance GHC.Classes.Eq Text.Shakespeare.Base.Deref instance GHC.Show.Show Text.Shakespeare.Base.Deref instance GHC.Classes.Ord Text.Shakespeare.Base.Ident instance Data.Data.Data Text.Shakespeare.Base.Ident instance GHC.Read.Read Text.Shakespeare.Base.Ident instance GHC.Classes.Eq Text.Shakespeare.Base.Ident instance GHC.Show.Show Text.Shakespeare.Base.Ident instance Language.Haskell.TH.Syntax.Lift Text.Shakespeare.Base.Ident instance Language.Haskell.TH.Syntax.Lift Text.Shakespeare.Base.Deref -- | This module provides a type-based system for providing translations -- for text strings. -- -- It is similar in purpose to gettext or Java message bundles. -- -- The core idea is to create simple data type where each constructor -- represents a phrase, sentence, paragraph, etc. For example: -- --
-- data AppMessages = Hello | Goodbye ---- -- The RenderMessage class is used to retrieve the appropriate -- translation for a message value: -- --
-- class RenderMessage master message where -- renderMessage :: master -- ^ type that specifies which set of translations to use -- -> [Lang] -- ^ acceptable languages in descending order of preference -- -> message -- ^ message to translate -- -> Text ---- -- Defining the translation type and providing the RenderMessage -- instance in Haskell is not very translator friendly. Instead, -- translations are generally provided in external translations files. -- Then the mkMessage Template Haskell function is used to read -- the external translation files and automatically create the -- translation type and the RenderMessage instance. -- -- A full description of using this module to create translations for -- Hamlet can be found here: -- -- http://www.yesodweb.com/book/internationalization -- -- A full description of using the module to create translations for -- HSP can be found here: -- -- http://happstack.com/docs/crashcourse/Templates.html#hsp-i18n -- -- You can also adapt those instructions for use with other systems. module Text.Shakespeare.I18N -- | generate translations from translation files -- -- This function will: -- --
-- renderJavascriptUrl (\_ _ -> undefined) javascriptUrl ---- -- When using Yesod, a renderer is generated for you, which can be -- accessed within the GHandler monad: getUrlRenderParams. renderJavascriptUrl :: (url -> [(Text, Text)] -> Text) -> JavascriptUrl url -> Text javascriptSettings :: Q ShakespeareSettings -- | Determine which identifiers are used by the given template, useful for -- creating systems like yesod devel. juliusUsedIdentifiers :: String -> [(Deref, VarType)] asJavascriptUrl :: JavascriptUrl url -> JavascriptUrl url instance GHC.Base.Monoid Text.Julius.Javascript instance Text.Julius.ToJavascript GHC.Types.Bool instance Text.Julius.ToJavascript Data.Aeson.Types.Internal.Value instance Text.Julius.ToJavascript Text.Julius.RawJavascript instance Text.Julius.RawJS [GHC.Types.Char] instance Text.Julius.RawJS Data.Text.Internal.Text instance Text.Julius.RawJS Data.Text.Internal.Lazy.Text instance Text.Julius.RawJS Data.Text.Internal.Builder.Builder instance Text.Julius.RawJS GHC.Types.Bool -- | A Shakespearean module for Roy, introducing type-safe, compile-time -- variable and url interpolation. It is exactly the same as -- Text.Julius, except that the template is first compiled to -- Javascript with the system tool roy. -- -- To use this module, roy must be installed on your system. -- -- If you interpolate variables, the template is first wrapped with a -- function containing javascript variables representing shakespeare -- variables, then compiled with roy, and then the value of the -- variables are applied to the function. This means that in production -- the template can be compiled once at compile time and there will be no -- dependency in your production system on roy. -- -- Your code: -- --
-- let b = 1
-- console.log(#{a} + b)
--
--
-- Final Result:
--
--
-- ;(function(shakespeare_var_a){
-- var b = 1;
-- console.log(shakespeare_var_a + b);
-- })(#{a});
--
--
-- Further reading:
--
--
-- var b = 1
-- console.log(#{a} + b)
--
--
-- Final Result:
--
--
-- ;(function(shakespeare_var_a){
-- var b = 1;
-- console.log(shakespeare_var_a + b);
-- })(#{a});
--
--
-- Important Warnings! This integration is not ideal.
--
-- Due to the function wrapper, all type declarations must be in separate
-- .d.ts files. However, if you don't interpolate variables, no function
-- wrapper will be created, and you can make type declarations in the
-- same file.
--
-- This does not work cross-platform!
--
-- Unfortunately tsc does not support stdin and stdout. So a hack of
-- writing to temporary files using the mktemp command is used. This
-- works on my version of Linux, but not for windows unless perhaps you
-- install a mktemp utility, which I have not tested. Please vote up this
-- bug: http://typescript.codeplex.com/workitem/600
--
-- Making this work on Windows would not be very difficult, it will just
-- require a new package with a dependency on a package like temporary.
--
-- Further reading:
--
--
-- >>> renderCss ([lucius|foo{bar:baz}|] undefined)
-- "foo{bar:baz}"
--
lucius :: QuasiQuoter
luciusFile :: FilePath -> Q Exp
luciusFileDebug :: FilePath -> Q Exp
luciusFileReload :: FilePath -> Q Exp
luciusMixin :: QuasiQuoter
data Mixin
luciusRT :: Text -> [(Text, Text)] -> Either String Text
luciusRT' :: Text -> Either String ([(Text, Text)] -> Either String [TopLevel Resolved])
-- | Same as luciusRT, but output has no added whitespace.
--
-- Since 1.0.3
luciusRTMinified :: Text -> [(Text, Text)] -> Either String Text
-- | Runtime Lucius with mixin support.
--
-- Since 1.0.6
luciusRTMixin :: Text -> Bool -> [(Text, RTValue)] -> Either String Text
data RTValue
RTVRaw :: Text -> RTValue
RTVMixin :: Mixin -> RTValue
data Css
type CssUrl url = (url -> [(Text, Text)] -> Text) -> Css
class ToCss a
toCss :: ToCss a => a -> Builder
renderCss :: Css -> Text
renderCssUrl :: (url -> [(Text, Text)] -> Text) -> CssUrl url -> Text
data Color
Color :: Word8 -> Word8 -> Word8 -> Color
colorRed :: Color
colorBlack :: Color
-- | Create a CSS size, e.g. $(mkSize "100px").
mkSize :: String -> ExpQ
-- | Absolute size units.
data AbsoluteUnit
Centimeter :: AbsoluteUnit
Inch :: AbsoluteUnit
Millimeter :: AbsoluteUnit
Pica :: AbsoluteUnit
Point :: AbsoluteUnit
-- | Not intended for direct use, see mkSize.
data AbsoluteSize
AbsoluteSize :: AbsoluteUnit -> Rational -> AbsoluteSize
-- | Units used for text formatting.
[absoluteSizeUnit] :: AbsoluteSize -> AbsoluteUnit
-- | Normalized value in centimeters.
[absoluteSizeValue] :: AbsoluteSize -> Rational
-- | Constructs AbsoluteSize. Not intended for direct use, see
-- mkSize.
absoluteSize :: AbsoluteUnit -> Rational -> AbsoluteSize
data EmSize
EmSize :: Rational -> EmSize
data ExSize
ExSize :: Rational -> ExSize
-- | Not intended for direct use, see mkSize.
data PercentageSize
PercentageSize :: Rational -> PercentageSize
-- | Normalized value, 1 == 100%.
[percentageSizeValue] :: PercentageSize -> Rational
-- | Constructs PercentageSize. Not intended for direct use, see
-- mkSize.
percentageSize :: Rational -> PercentageSize
data PixelSize
PixelSize :: Rational -> PixelSize
parseTopLevels :: Parser [TopLevel Unresolved]
-- | Determine which identifiers are used by the given template, useful for
-- creating systems like yesod devel.
luciusUsedIdentifiers :: String -> [(Deref, VarType)]
-- | Provides functionality for runtime Hamlet templates. Please use
-- Text.Hamlet.Runtime instead.
module Text.Hamlet.RT
newtype HamletRT
HamletRT :: [SimpleDoc] -> HamletRT
data HamletData url
HDHtml :: Html -> HamletData url
HDUrl :: url -> HamletData url
HDUrlParams :: url -> [(Text, Text)] -> HamletData url
HDTemplate :: HamletRT -> HamletData url
HDBool :: Bool -> HamletData url
HDMaybe :: (Maybe (HamletMap url)) -> HamletData url
HDList :: [HamletMap url] -> HamletData url
type HamletMap url = [([String], HamletData url)]
data HamletException
HamletParseException :: String -> HamletException
HamletUnsupportedDocException :: Doc -> HamletException
HamletRenderException :: String -> HamletException
parseHamletRT :: MonadThrow m => HamletSettings -> String -> m HamletRT
renderHamletRT :: MonadThrow m => HamletRT -> HamletMap url -> UrlRenderer url -> m Html
renderHamletRT' :: MonadThrow m => Bool -> HamletRT -> HamletMap url -> (url -> [(Text, Text)] -> Text) -> m Html
data SimpleDoc
SDRaw :: String -> SimpleDoc
SDVar :: [String] -> SimpleDoc
SDUrl :: Bool -> [String] -> SimpleDoc
SDTemplate :: [String] -> SimpleDoc
SDForall :: [String] -> String -> [SimpleDoc] -> SimpleDoc
SDMaybe :: [String] -> String -> [SimpleDoc] -> [SimpleDoc] -> SimpleDoc
SDCond :: [([String], [SimpleDoc])] -> [SimpleDoc] -> SimpleDoc
instance GHC.Show.Show Text.Hamlet.RT.HamletException
instance GHC.Exception.Exception Text.Hamlet.RT.HamletException
module Text.Hamlet
type Html = Markup
-- | "Simple Hamlet" quasi-quoter. May only be used to generate
-- expressions.
--
-- Generated expressions have type Html.
--
-- -- >>> putStrLn (renderHtml [shamlet|<div>Hello, world!|]) -- <div>Hello, world!</div> --shamlet :: QuasiQuoter shamletFile :: FilePath -> Q Exp -- | Like shamlet, but produces XHTML. xshamlet :: QuasiQuoter -- | Like shamletFile, but produces XHTML. xshamletFile :: FilePath -> Q Exp -- | A function generating an Html given a URL-rendering function. type HtmlUrl url = Render url -> Html type Render url = url -> [(Text, Text)] -> Text -- | Hamlet quasi-quoter. May only be used to generate expressions. -- -- Generated expression have type HtmlUrl url, for some -- url. -- --
-- data MyRoute = Home
--
-- render :: Render MyRoute
-- render Home _ = "/home"
--
-- >>> putStrLn (renderHtml ([hamlet|<a href=@{Home}>Home|] render))
-- <a href="/home">Home</a>
--
hamlet :: QuasiQuoter
hamletFile :: FilePath -> Q Exp
-- | Like hamletFile, but the external file is parsed at runtime.
-- Allows for more rapid development, but should not be used in
-- production.
hamletFileReload :: FilePath -> Q Exp
-- | Like hamlet, but produces XHTML.
xhamlet :: QuasiQuoter
-- | Like hamletFile, but produces XHTML.
xhamletFile :: FilePath -> Q Exp
-- | A function generating an Html given a message translator and a
-- URL rendering function.
type HtmlUrlI18n msg url = Translate msg -> Render url -> Html
type Translate msg = msg -> Html
-- | Hamlet quasi-quoter with internationalization. May only be used to
-- generate expressions.
--
-- Generated expressions have type HtmlUrlI18n msg url,
-- for some msg and url.
--
--
-- data MyMsg = Hi | Bye
--
-- data MyRoute = Home
--
-- renderEnglish :: Translate MyMsg
-- renderEnglish Hi = "hi"
-- renderEnglish Bye = "bye"
--
-- renderUrl :: Render MyRoute
-- renderUrl Home _ = "/home"
--
-- >>> putStrLn (renderHtml ([ihamlet|@{Home} _{Hi} _{Bye}|] renderEnglish renderUrl))
-- <div>/home hi bye <div>
--
ihamlet :: QuasiQuoter
ihamletFile :: FilePath -> Q Exp
-- | Like ihamletFile, but the external file is parsed at runtime.
-- Allows for more rapid development, but should not be used in
-- production.
ihamletFileReload :: FilePath -> Q Exp
-- | Convert some value to a list of attribute pairs.
class ToAttributes a
toAttributes :: ToAttributes a => a -> [(Text, Text)]
-- | Settings for parsing of a hamlet document.
data HamletSettings
HamletSettings :: String -> NewlineStyle -> (String -> CloseStyle) -> [(String, String)] -> HamletSettings
-- | The value to replace a "!!!" with. Do not include the trailing
-- newline.
[hamletDoctype] :: HamletSettings -> String
-- | Should we add newlines to the output, making it more human-readable?
-- Useful for client-side debugging but may alter browser page layout.
[hamletNewlines] :: HamletSettings -> NewlineStyle
-- | How a tag should be closed. Use this to switch between HTML, XHTML or
-- even XML output.
[hamletCloseStyle] :: HamletSettings -> String -> CloseStyle
-- | Mapping from short names in "$doctype" statements to full doctype.
[hamletDoctypeNames] :: HamletSettings -> [(String, String)]
data NewlineStyle
-- | never add newlines
NoNewlines :: NewlineStyle
-- | add newlines between consecutive text lines
NewlinesText :: NewlineStyle
-- | add newlines everywhere
AlwaysNewlines :: NewlineStyle
DefaultNewlineStyle :: NewlineStyle
hamletWithSettings :: Q HamletRules -> HamletSettings -> QuasiQuoter
hamletFileWithSettings :: Q HamletRules -> HamletSettings -> FilePath -> Q Exp
-- | Defaults settings: HTML5 doctype and HTML-style empty tags.
defaultHamletSettings :: HamletSettings
xhtmlHamletSettings :: HamletSettings
data Env
Env :: Maybe ((Exp -> Q Exp) -> Q Exp) -> Maybe ((Exp -> Q Exp) -> Q Exp) -> Env
[urlRender] :: Env -> Maybe ((Exp -> Q Exp) -> Q Exp)
[msgRender] :: Env -> Maybe ((Exp -> Q Exp) -> Q Exp)
data HamletRules
HamletRules :: Exp -> ((Env -> Q Exp) -> Q Exp) -> (Env -> Exp -> Q Exp) -> HamletRules
[hrFromHtml] :: HamletRules -> Exp
[hrWithEnv] :: HamletRules -> (Env -> Q Exp) -> Q Exp
[hrEmbed] :: HamletRules -> Env -> Exp -> Q Exp
hamletRules :: Q HamletRules
ihamletRules :: Q HamletRules
htmlRules :: Q HamletRules
data CloseStyle
NoClose :: CloseStyle
CloseInside :: CloseStyle
CloseSeparate :: CloseStyle
-- | Checks for truth in the left value in each pair in the first argument.
-- If a true exists, then the corresponding right action is performed.
-- Only the first is performed. In there are no true values, then the
-- second argument is performed, if supplied.
condH :: Monad m => [(Bool, m ())] -> Maybe (m ()) -> m ()
-- | Runs the second argument with the value in the first, if available.
-- Otherwise, runs the third argument, if available.
maybeH :: Monad m => Maybe v -> (v -> m ()) -> Maybe (m ()) -> m ()
asHtmlUrl :: HtmlUrl url -> HtmlUrl url
attrsToHtml :: [(Text, Text)] -> Html
hamletFromString :: Q HamletRules -> HamletSettings -> String -> Q Exp
instance Text.Hamlet.ToAttributes (Data.Text.Internal.Text, Data.Text.Internal.Text)
instance Text.Hamlet.ToAttributes (GHC.Base.String, GHC.Base.String)
instance Text.Hamlet.ToAttributes [(Data.Text.Internal.Text, Data.Text.Internal.Text)]
instance Text.Hamlet.ToAttributes [(GHC.Base.String, GHC.Base.String)]
instance GHC.Show.Show (Text.Hamlet.VarExp msg url)
-- | Module for parsing and rendering Hamlet templates at runtime, not
-- compile time. This uses the same Hamlet parsing as compile-time
-- Hamlet, but has some limitations, such as:
--
--
-- {-# LANGUAGE OverloadedStrings #-}
-- import Text.Hamlet.Runtime
-- import qualified Data.Map as Map
-- import Text.Blaze.Html.Renderer.String (renderHtml)
--
-- main :: IO ()
-- main = do
-- template <- parseHamletTemplate defaultHamletSettings $ unlines
-- [ "<p>Hello, #{name}"
-- , "$if hungry"
-- , " <p>Available food:"
-- , " <ul>"
-- , " $forall food <- foods"
-- , " <li>#{food}"
-- ]
-- let hamletDataMap = Map.fromList
-- [ ("name", "Michael")
-- , ("hungry", toHamletData True) -- always True
-- , ("foods", toHamletData
-- [ "Apples"
-- , "Bananas"
-- , "Carrots"
-- ])
-- ]
-- html <- renderHamletTemplate template hamletDataMap
-- putStrLn $ renderHtml html
--
module Text.Hamlet.Runtime
-- | A parsed Hamlet template. See parseHamletTemplate and
-- readHamletTemplateFile.
data HamletTemplate
-- | Settings for parsing of a hamlet document.
data HamletSettings
-- | Defaults settings: HTML5 doctype and HTML-style empty tags.
defaultHamletSettings :: HamletSettings
-- | A piece of data that can be embedded and passed to a Hamlet template
-- (via renderHamletTemplate).
--
-- This supplies an IsString instance, so with
-- OverloadedStrings it will support literal strings, which are
-- converted to HTML via toHtml. For other datatypes, use
-- toHamletData.
data HamletData
-- | Data which can be passed to a Hamlet template.
class ToHamletData a
toHamletData :: ToHamletData a => a -> HamletData
-- | Parse an in-memory Hamlet template. This operation may fail if the
-- template is not parsable.
parseHamletTemplate :: MonadThrow m => HamletSettings -> String -> m HamletTemplate
-- | Same as parseHamletTemplate, but reads from a file. The file is
-- assumed to be UTF-8 encoded (same assumption as compile-time Hamlet).
readHamletTemplateFile :: (MonadThrow m, MonadIO m) => HamletSettings -> FilePath -> m HamletTemplate
-- | Render a runtime Hamlet template, together with a Map of
-- variables to pass in, into an Html value. This can fail if the
-- template references a variable that is not present in the
-- Map.
renderHamletTemplate :: MonadThrow m => HamletTemplate -> Map Text HamletData -> m Html
instance Data.String.IsString Text.Hamlet.Runtime.HamletData
instance Text.Hamlet.Runtime.ToHamletData Text.Hamlet.Runtime.HamletData
instance a ~ Text.Hamlet.Runtime.HamletData => Text.Hamlet.Runtime.ToHamletData [a]
instance a ~ Text.Hamlet.Runtime.HamletData => Text.Hamlet.Runtime.ToHamletData (GHC.Base.Maybe a)
instance Text.Hamlet.Runtime.ToHamletData Data.Text.Internal.Text
instance Text.Hamlet.Runtime.ToHamletData Text.Blaze.Html.Html
instance Text.Hamlet.Runtime.ToHamletData GHC.Types.Bool
-- | A Shakespearean module for CoffeeScript, introducing type-safe,
-- compile-time variable and url interpolation. It is exactly the same as
-- Text.Julius, except that the template is first compiled to
-- Javascript with the system tool coffee.
--
-- To use this module, coffee must be installed on your system.
--
-- #{...} is the Shakespearean standard for variable
-- interpolation, but CoffeeScript already uses that sequence for string
-- interpolation. Therefore, Shakespearean interpolation is introduced
-- with %{...}.
--
-- If you interpolate variables, the template is first wrapped with a
-- function containing javascript variables representing shakespeare
-- variables, then compiled with coffee, and then the value of
-- the variables are applied to the function. This means that in
-- production the template can be compiled once at compile time and there
-- will be no dependency in your production system on coffee.
--
-- Your code:
--
--
-- b = 1
-- console.log(#{a} + b)
--
--
-- Function wrapper added to your coffeescript code:
--
-- -- ((shakespeare_var_a) => -- b = 1 -- console.log(shakespeare_var_a + b) -- ) ---- -- This is then compiled down to javascript, and the variables are -- applied: -- --
-- ;(function(shakespeare_var_a){
-- var b = 1;
-- console.log(shakespeare_var_a + b);
-- })(#{a});
--
--
-- Further reading:
--
--