Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- compileTemplate' :: FilePath -> Action Template
- markdownToHTML :: Text -> Action Value
- markdownToHTML' :: FromJSON a => Text -> Action a
- makePandocReader :: PandocReader textType -> textType -> Action (Pandoc, Value)
- makePandocReader' :: FromJSON a => PandocReader textType -> textType -> Action (Pandoc, a)
- loadUsing :: PandocReader textType -> PandocWriter -> textType -> Action Value
- loadUsing' :: FromJSON a => PandocReader textType -> PandocWriter -> textType -> Action a
- convert :: (FromJSON a, ToJSON a, FromJSON b) => a -> Action b
- simpleJsonCache :: ShakeValue q => q -> Action Value -> Rules (Action Value)
- simpleJsonCache' :: forall q a. (ToJSON a, FromJSON a, ShakeValue q) => q -> Action a -> Rules (Action a)
- jsonCache :: ShakeValue q => (q -> Action Value) -> Rules (q -> Action Value)
- jsonCache' :: forall a q. (ToJSON a, FromJSON a, ShakeValue q) => (q -> Action a) -> Rules (q -> Action a)
- overText :: (Text -> Text) -> Value
- compileTemplate :: String -> Text -> Either ParseError Template
- compileTemplateWithCache :: [FilePath] -> TemplateCache -> FilePath -> IO (Either ParseError Template)
- localAutomaticCompile :: FilePath -> IO (Either ParseError Template)
- automaticCompile :: [FilePath] -> FilePath -> IO (Either ParseError Template)
- substituteNode :: Node Text -> SubM ()
- substituteAST :: STree -> SubM ()
- catchSubstitute :: SubM a -> SubM (a, Text)
- checkedSubstituteValue :: Template -> Value -> ([SubstitutionError], Text)
- substituteValue :: Template -> Value -> Text
- checkedSubstitute :: ToMustache k => Template -> k -> ([SubstitutionError], Text)
- substitute :: ToMustache k => Template -> k -> Text
- (~=) :: ToJSON ι => Text -> ι -> Pair
- object :: [Pair] -> Value
- class ToMustache ω where
- data Template = Template {}
Slick
This module re-exports everything you need to use Slick
Mustache
compileTemplate' :: FilePath -> Action Template Source #
Like compileTemplate
but tracks changes to template files and partials
within Shake.
Pandoc
markdownToHTML' :: FromJSON a => Text -> Action a Source #
Like markdownToHTML
but allows returning any JSON serializable object
makePandocReader' :: FromJSON a => PandocReader textType -> textType -> Action (Pandoc, a) Source #
Like makePandocReader
but will deserialize the metadata into any object
which implements FromJSON
. Failure to deserialize will fail the Shake
build.
loadUsing' :: FromJSON a => PandocReader textType -> PandocWriter -> textType -> Action a Source #
Aeson
convert :: (FromJSON a, ToJSON a, FromJSON b) => a -> Action b Source #
Attempt to convert between two JSON serializable objects (or Value
s).
Failure to deserialize fails the Shake build.
Shake
simpleJsonCache :: ShakeValue q => q -> Action Value -> Rules (Action Value) Source #
A wrapper around jsonCache
which simplifies caching of values which do NOT
depend on an input parameter. Unfortunately Shake still requires that the
key type implement several typeclasses, however this is easily accomplished
using GeneralizedNewtypeDeriving
and a wrapper around ()
.
example usage:
{-# LANGUAGE GeneralizedNewtypeDeriving #-} module Main where newtype ProjectList = ProjectList () deriving (Show, Eq, Hashable, Binary, NFData)
Within your shake Rules:
projectCache = simpleJsonCache (ProjectList ()) $ do -- load your project list here; returning it as a Value
simpleJsonCache' :: forall q a. (ToJSON a, FromJSON a, ShakeValue q) => q -> Action a -> Rules (Action a) Source #
Like simpleJsonCache
but allows caching any JSON serializable object.
jsonCache :: ShakeValue q => (q -> Action Value) -> Rules (q -> Action Value) Source #
A wrapper around addOracleCache
which given a q
which is a ShakeValue
allows caching and retrieving Value
s within Shake. See documentation on
addOracleCache
or see Slick examples for more info.
-- We need to define a unique datatype as our cache key newtype PostFilePath = PostFilePath String -- We can derive the classes we need (using GeneralizedNewtypeDeriving) -- so long as the underlying type implements them deriving (Show, Eq, Hashable, Binary, NFData) -- now in our shake rules we can create a cache by providing a loader action do postCache <- jsonCache $ \(PostFilePath path) -> readFile' path >>= markdownToHTML . Text.pack -- Now use postCache inside an Action to load your post with caching!
jsonCache' :: forall a q. (ToJSON a, FromJSON a, ShakeValue q) => (q -> Action a) -> Rules (q -> Action a) Source #
Like jsonCache
but allows caching/retrieving any JSON serializable
objects.
Re-exported
overText :: (Text -> Text) -> Value #
Creates a Lambda
which first renders the contained section and then applies the supplied function
compileTemplate :: String -> Text -> Either ParseError Template #
compileTemplateWithCache :: [FilePath] -> TemplateCache -> FilePath -> IO (Either ParseError Template) #
Compile a mustache template providing a list of precompiled templates that do not have to be recompiled.
localAutomaticCompile :: FilePath -> IO (Either ParseError Template) #
Compile the template with the search space set to only the current directory
automaticCompile :: [FilePath] -> FilePath -> IO (Either ParseError Template) #
Compiles a mustache template provided by name including the mentioned partials.
The same can be done manually using getFile
, mustacheParser
and getPartials
.
This function also ensures each partial is only compiled once even though it may be included by other partials including itself.
A reference to the included template will be found in each including templates
partials
section.
substituteNode :: Node Text -> SubM () #
Main substitution function
catchSubstitute :: SubM a -> SubM (a, Text) #
Catch the results of running the inner substitution.
checkedSubstituteValue :: Template -> Value -> ([SubstitutionError], Text) #
Substitutes all mustache defined tokens (or tags) for values found in the provided data structure and report any errors and warnings encountered during substitution.
This function always produces results, as in a fully substituted/rendered template, it never halts on errors. It simply reports them in the first part of the tuple. Sites with errors are usually substituted with empty string.
The second value in the tuple is a template rendered with errors ignored. Therefore if you must enforce that there were no errors during substitution you must check that the error list in the first tuple value is empty.
substituteValue :: Template -> Value -> Text #
Substitutes all mustache defined tokens (or tags) for values found in the provided data structure.
checkedSubstitute :: ToMustache k => Template -> k -> ([SubstitutionError], Text) #
Substitutes all mustache defined tokens (or tags) for values found in the provided data structure and report any errors and warnings encountered during substitution.
This function always produces results, as in a fully substituted/rendered template, it never halts on errors. It simply reports them in the first part of the tuple. Sites with errors are usually substituted with empty string.
The second value in the tuple is a template rendered with errors ignored. Therefore if you must enforce that there were no errors during substitution you must check that the error list in the first tuple value is empty.
Equivalent to checkedSubstituteValue . toMustache
.
substitute :: ToMustache k => Template -> k -> Text #
Substitutes all mustache defined tokens (or tags) for values found in the provided data structure.
Equivalent to substituteValue . toMustache
.
(~=) :: ToJSON ι => Text -> ι -> Pair infixr 8 #
Map keys to values that provide a ToJSON
instance
Recommended in conjunction with the OverloadedStrings
extension.
Convenience function for creating Object values.
This function is supposed to be used in conjuction with the ~>
and ~=
operators.
Examples
data Address = Address { ... } instance Address ToJSON where ... data Person = Person { name :: String, address :: Address } instance ToMustache Person where toMustache (Person { name, address }) = object [ "name" ~> name , "address" ~= address ]
Here we can see that we can use the ~>
operator for values that have
themselves a ToMustache
instance, or alternatively if they lack such an
instance but provide an instance for the ToJSON
typeclass we can use the
~=
operator.
class ToMustache ω where #
Conversion class
toMustache :: ω -> Value #
Instances
A compiled Template with metadata.
Instances
Show Template | |
Lift TemplateCache | |
Defined in Text.Mustache.Internal.Types lift :: TemplateCache -> Q Exp # | |
Lift Template | |
MonadReader (Context Value, TemplateCache) SubM | |
Defined in Text.Mustache.Internal.Types |