pencil-1.0.1: Static site generator

Safe HaskellNone
LanguageHaskell2010

Pencil.App.Internal

Description

Internal implementation of Pencil's main functionality.

Synopsis

Documentation

type PencilApp = ReaderT Config (ExceptT PencilException IO) Source #

The primary monad transformer stack for a Pencil application.

This unrolls to:

PencilApp a = Config -> IO (Except PencilException a)

The ExceptT monad allows us to catch "checked" exceptions; errors that we know how to handle, in PencilException. Note that Unknown "unchecked" exceptions can still go through IO.

data PencilException Source #

Known Pencil errors that we know how to either recover from or quit gracefully.

Constructors

NotTextFile (Maybe FilePath)

Failed to read a file as a text file.

FileNotFound (Maybe FilePath)

File not found. We may or may not know the file we were looking for.

CollectionNotLastInStructure Text

The collection in the structure was not the last element in the structure.

CollectionFirstInStructure Text

A collection cannot be the first element in the structure (it's useless there, as nothing can reference the pages in the collection).

toPencilException :: IOError -> Maybe PencilException Source #

Converts the IOError to a known PencilException.

How to test errors:

import Control.Exception
import qualified Data.Text.IO as TIO

(e -> print (ioe_description (e :: IOError)) >> return "") handle (TIO.readFile "foo")

isInvalidByteSequence :: IOError -> Bool Source #

Returns true if the IOError is an invalid byte sequence error. This suggests that the file is a binary file.

isNoSuchFile :: IOError -> Bool Source #

Returns true if the IOError is due to missing file.

printAsList :: [String] -> IO () Source #

Print the list of Strings, one line at a time, prefixed with "-".