heist-emanote-1.2.1.0: An Haskell template system supporting both HTML5 and XML.
Safe HaskellNone
LanguageHaskell2010

Heist.Common

Synopsis

Documentation

runMapNoErrors :: (Eq k, Hashable k) => MapSyntaxM k v a -> HashMap k v Source #

orError :: Monad m => HeistT n m b -> String -> HeistT n m b Source #

If Heist is running in fail fast mode, then this function will throw an exception with the second argument as the error message. Otherwise, the first argument will be executed to represent silent failure.

This behavior allows us to fail quickly if an error crops up during load-time splice processing or degrade more gracefully if the error occurs while a user request is being processed.

heistErrMsg :: Monad m => Text -> HeistT n m Text Source #

Prepends the location of the template currently being processed to an error message.

tellSpliceError :: Monad m => Text -> HeistT n m () Source #

Adds an error message to the list of splice processing errors.

showTPath :: TPath -> String Source #

Function for showing a TPath.

tpathName :: TPath -> ByteString Source #

Convert a TPath into a ByteString path.

setCurTemplateFile :: Maybe FilePath -> HeistState n -> HeistState n Source #

Sets the current template file.

attParser :: Parser [AttAST] Source #

Parser for attribute variable substitution.

splitPathWith :: Char -> ByteString -> TPath Source #

Converts a path into an array of the elements in reverse order. If the path is absolute, we need to remove the leading slash so the split doesn't leave "" as the last element of the TPath.

FIXME ".." currently doesn't work in paths, the solution is non-trivial

splitLocalPath :: ByteString -> TPath Source #

Converts a path into an array of the elements in reverse order using the path separator of the local operating system. See splitPathWith for more details.

splitTemplatePath :: ByteString -> TPath Source #

Converts a path into an array of the elements in reverse order using a forward slash (/) as the path separator. See splitPathWith for more details.

lookupTemplate :: ByteString -> HeistState n -> (HeistState n -> HashMap TPath t) -> Maybe (t, TPath) Source #

Convenience function for looking up a template.

hasTemplate :: ByteString -> HeistState n -> Bool Source #

Returns True if the given template can be found in the heist state.

singleLookup :: (Eq a, Hashable a) => HashMap [a] t -> [a] -> a -> Maybe (t, [a]) Source #

Does a single template lookup without cascading up.

traversePath :: (Eq a, Hashable a) => HashMap [a] t -> [a] -> a -> Maybe (t, [a]) Source #

Searches for a template by looking in the full path then backing up into each of the parent directories until the template is found.

mapSplices Source #

Arguments

:: (Monad m, Monoid b) 
=> (a -> m b)

Splice generating function

-> [a]

List of items to generate splices for

-> m b

The result of all splices concatenated together.

Maps a splice generating function over a list and concatenates the results. This function now has a more general type signature so it works with both compiled and interpreted splices. The old type signature was this:

mapSplices :: (Monad n)
        => (a -> Splice n n)
        -> [a]
        -> Splice n n

getContext :: Monad m => HeistT n m TPath Source #

Gets the current context

getTemplateFilePath :: Monad m => HeistT n m (Maybe FilePath) Source #

Gets the full path to the file holding the template currently being processed. Returns Nothing if the template is not associated with a file on disk or if there is no template being processed.

loadTemplate Source #

Arguments

:: String

path of the template root

-> String

full file path (includes the template root)

-> IO [Either String (TPath, DocumentFile)] 

Loads a template with the specified path and filename. The template is only loaded if it has a ".tpl" or ".xtpl" extension.

loadTemplate' :: String -> IO [Either String DocumentFile] Source #

Loads a template at the specified path, choosing the appropriate parser based on the file extension. The template is only loaded if it has a ".tpl" or ".xtpl" extension. Returns an empty list if the extension doesn't match.

type ParserFun = String -> ByteString -> Either String Document Source #

Type synonym for parsers.

getDocWith :: ParserFun -> String -> IO (Either String DocumentFile) Source #

Reads an HTML or XML template from disk.

getDoc :: String -> IO (Either String DocumentFile) Source #

Reads an HTML template from disk.

getXMLDoc :: String -> IO (Either String DocumentFile) Source #

Reads an XML template from disk.

setTemplates :: HashMap TPath DocumentFile -> HeistState n -> HeistState n Source #

Sets the templateMap in a HeistState.

insertTemplate :: TPath -> DocumentFile -> HeistState n -> HeistState n Source #

Adds a template to the heist state.

bindAttributeSplices Source #

Arguments

:: Splices (AttrSplice n)

splices to bind

-> HeistState n

start state

-> HeistState n 

Binds a set of new splice declarations within a HeistState.

addDoctype :: Monad m => [DocType] -> HeistT n m () Source #

Mappends a doctype to the state.