hakyll-4.13.0.1: A static website compiler library

Safe Haskell | None
Language | Haskell2010

Hakyll.Core.Compiler.Internal

Contents

- Types
- Core operations
- Error operations
- Utilities

Description

Internally used compiler module

Synopsis

- type Snapshot = String
- data CompilerRead = CompilerRead {
  - compilerConfig :: Configuration
  - compilerUnderlying :: Identifier
  - compilerProvider :: Provider
  - compilerUniverse :: Set Identifier
  - compilerRoutes :: Routes
  - compilerStore :: Store
  - compilerLogger :: Logger
  }
- data CompilerWrite = CompilerWrite {
  - compilerDependencies :: [Dependency]
  - compilerCacheHits :: Int
  }
- data CompilerErrors a
  - = CompilationFailure (NonEmpty a)
  - | CompilationNoResult [a]
- data CompilerResult a
  - = CompilerDone a CompilerWrite
  - | CompilerSnapshot Snapshot (Compiler a)
  - | CompilerRequire (Identifier, Snapshot) (Compiler a)
  - | CompilerError (CompilerErrors String)
- newtype Compiler a = Compiler {
  - unCompiler :: CompilerRead -> IO (CompilerResult a)
  }
- runCompiler :: Compiler a -> CompilerRead -> IO (CompilerResult a)
- compilerResult :: CompilerResult a -> Compiler a
- compilerTell :: CompilerWrite -> Compiler ()
- compilerAsk :: Compiler CompilerRead
- compilerUnsafeIO :: IO a -> Compiler a
- compilerThrow :: [String] -> Compiler a
- compilerNoResult :: [String] -> Compiler a
- compilerCatch :: Compiler a -> (CompilerErrors String -> Compiler a) -> Compiler a
- compilerTry :: Compiler a -> Compiler (Either (CompilerErrors String) a)
- compilerErrorMessages :: CompilerErrors a -> [a]
- compilerDebugEntries :: String -> [String] -> Compiler ()
- compilerTellDependencies :: [Dependency] -> Compiler ()
- compilerTellCacheHits :: Int -> Compiler ()

# Types

type Snapshot = String Source #

Whilst compiling an item, it possible to save multiple snapshots of it, and not just the final result.

data CompilerRead Source #

Environment in which a compiler runs

Constructors

CompilerRead |

Fields

- compilerConfig :: Configuration

  Main configuration

- compilerUnderlying :: Identifier

  Underlying identifier

- compilerProvider :: Provider

  Resource provider

- compilerUniverse :: Set Identifier

  List of all known identifiers

- compilerRoutes :: Routes

  Site routes

- compilerStore :: Store

  Compiler store

- compilerLogger :: Logger

  Logger

data CompilerWrite Source #

Constructors

CompilerWrite |

Fields

- compilerDependencies :: [Dependency]
- compilerCacheHits :: Int

Instances

Show CompilerWrite Source # |
Instance details Defined in Hakyll.Core.Compiler.Internal Methods showsPrec :: Int -> CompilerWrite -> ShowS Source # show :: CompilerWrite -> String Source # showList :: [CompilerWrite] -> ShowS Source #
Semigroup CompilerWrite Source # |
Instance details Defined in Hakyll.Core.Compiler.Internal Methods (<>) :: CompilerWrite -> CompilerWrite -> CompilerWrite Source # sconcat :: NonEmpty CompilerWrite -> CompilerWrite Source # stimes :: Integral b => b -> CompilerWrite -> CompilerWrite Source #
Monoid CompilerWrite Source # |
Instance details Defined in Hakyll.Core.Compiler.Internal Methods mempty :: CompilerWrite Source # mappend :: CompilerWrite -> CompilerWrite -> CompilerWrite Source # mconcat :: [CompilerWrite] -> CompilerWrite Source #

data CompilerErrors a Source #

Distinguishes reasons in a `CompilerError`

Constructors

CompilationFailure (NonEmpty a) | One or more exceptions occured during compilation
CompilationNoResult [a] | Absence of any result, most notably in template contexts. May still have error messages.

Instances

Functor CompilerErrors Source # |
Instance details Defined in Hakyll.Core.Compiler.Internal Methods fmap :: (a -> b) -> CompilerErrors a -> CompilerErrors b Source # (<$) :: a -> CompilerErrors b -> CompilerErrors a Source #

data CompilerResult a Source #

An intermediate result of a compilation step

Constructors

CompilerDone a CompilerWrite |
CompilerSnapshot Snapshot (Compiler a) |
CompilerRequire (Identifier, Snapshot) (Compiler a) |
CompilerError (CompilerErrors String) |

newtype Compiler a Source #

A monad which lets you compile items and takes care of dependency tracking for you.

Constructors

Compiler |

Fields

- unCompiler :: CompilerRead -> IO (CompilerResult a)

Instances

Monad Compiler Source # |
Instance details Defined in Hakyll.Core.Compiler.Internal Methods (>>=) :: Compiler a -> (a -> Compiler b) -> Compiler b Source # (>>) :: Compiler a -> Compiler b -> Compiler b Source # return :: a -> Compiler a Source # fail :: String -> Compiler a Source #
Functor Compiler Source # |
Instance details Defined in Hakyll.Core.Compiler.Internal Methods fmap :: (a -> b) -> Compiler a -> Compiler b Source # (<$) :: a -> Compiler b -> Compiler a Source #
Applicative Compiler Source # |
Instance details Defined in Hakyll.Core.Compiler.Internal Methods pure :: a -> Compiler a Source # (<*>) :: Compiler (a -> b) -> Compiler a -> Compiler b Source # liftA2 :: (a -> b -> c) -> Compiler a -> Compiler b -> Compiler c Source # (*>) :: Compiler a -> Compiler b -> Compiler b Source # (<*) :: Compiler a -> Compiler b -> Compiler a Source #
Alternative Compiler Source # | Trying alternative compilers if the first fails, regardless whether through `fail`, `throwError` or `noResult`. Aggregates error messages if all fail.
Instance details Defined in Hakyll.Core.Compiler.Internal Methods empty :: Compiler a Source # (<|>) :: Compiler a -> Compiler a -> Compiler a Source # some :: Compiler a -> Compiler [a] Source # many :: Compiler a -> Compiler [a] Source #
MonadMetadata Compiler Source # | Access provided metadata from anywhere
Instance details Defined in Hakyll.Core.Compiler.Internal Methods getMetadata :: Identifier -> Compiler Metadata Source # getMatches :: Pattern -> Compiler [Identifier] Source # getAllMetadata :: Pattern -> Compiler [(Identifier, Metadata)] Source #
MonadError [String] Compiler Source # | Compilation may fail with multiple error messages. `catchError` handles errors from `throwError`, `fail` and `noResult`
Instance details Defined in Hakyll.Core.Compiler.Internal Methods throwError :: [String] -> Compiler a Source # catchError :: Compiler a -> ([String] -> Compiler a) -> Compiler a Source #

runCompiler :: Compiler a -> CompilerRead -> IO (CompilerResult a) Source #

Like `unCompiler` but treating IO exceptions as `CompilerError`s

# Core operations

compilerResult :: CompilerResult a -> Compiler a Source #

Put the result back in a compiler

compilerTell :: CompilerWrite -> Compiler () Source #

Put a `CompilerWrite`

compilerAsk :: Compiler CompilerRead Source #

Get the current environment

compilerUnsafeIO :: IO a -> Compiler a Source #

Run an IO computation without dependencies in a Compiler

# Error operations

compilerThrow :: [String] -> Compiler a Source #

Throw errors in the `Compiler`.

If no messages are given, this is considered a `CompilationNoResult` error. Otherwise, it is treated as a proper compilation failure.

compilerNoResult :: [String] -> Compiler a Source #

Put a `CompilerError` with multiple messages as `CompilationNoResult`

compilerCatch :: Compiler a -> (CompilerErrors String -> Compiler a) -> Compiler a Source #

Allows you to recover from `CompilerError`s. Uses the same parameter order as `catchError` so that it can be used infix.

    c `compilerCatch` f = compilerTry c >>= either f return

compilerTry :: Compiler a -> Compiler (Either (CompilerErrors String) a) Source #

Allows to distinguish `CompilerError`s and branch on them with `Either`

    compilerTry = (`compilerCatch` return . Left) . fmap Right

compilerErrorMessages :: CompilerErrors a -> [a] Source #

Unwrap a `CompilerErrors`

# Utilities

compilerDebugEntries :: String -> [String] -> Compiler () Source #

Pass a list of messages with a heading to the debug logger

compilerTellDependencies :: [Dependency] -> Compiler () Source #

compilerTellCacheHits :: Int -> Compiler () Source #