project-template-0.2.1.0: Specify Haskell project templates and generate files

Safe Haskell | None
Language | Haskell2010

Text.ProjectTemplate

Contents

- Create a template
- Unpack a template
  - Receivers
- Exceptions

Synopsis

- createTemplate :: Monad m => ConduitM (FilePath, m ByteString) ByteString m ()
- unpackTemplate :: forall (m :: Type -> Type) o. MonadThrow m => (FilePath -> ConduitM ByteString o m ()) -> (Text -> Text) -> ConduitM ByteString o m ()
- type FileReceiver (m :: Type -> Type) = FilePath -> ConduitM ByteString Void m ()
- receiveMem :: forall (m :: Type -> Type). MonadWriter (Map FilePath ByteString) m => FileReceiver m
- receiveFS :: forall (m :: Type -> Type). MonadResource m => FilePath -> FileReceiver m
- data ProjectTemplateException
  - = InvalidInput Text
  - | BinaryLoopNeedsOneLine

# Create a template

createTemplate :: Monad m => ConduitM (FilePath, m ByteString) ByteString m () Source #

Create a template file from a stream of file/contents combinations.

Since 0.1.0

# Unpack a template

unpackTemplate Source #

Arguments

:: forall (m :: Type -> Type) o. MonadThrow m |
=> (FilePath -> ConduitM ByteString o m ()) | receive individual files
-> (Text -> Text) | fix each input line, good for variables
-> ConduitM ByteString o m () |

Unpack a template to some destination. Destination is provided by the first argument.

The second argument allows you to modify the incoming stream, usually to replace variables. For example, to replace PROJECTNAME with myproject, you could use:

    Data.Text.replace "PROJECTNAME" "myproject"

Note that this will affect both file contents and file names.

Since 0.1.0

## Receivers

type FileReceiver (m :: Type -> Type) = FilePath -> ConduitM ByteString Void m () Source #

The first argument to `unpackTemplate`, specifying how to receive a file.

Since 0.1.0

receiveMem :: forall (m :: Type -> Type). MonadWriter (Map FilePath ByteString) m => FileReceiver m Source #

Receive files to a `Writer` monad in memory.

    execWriter $ runExceptionT_ $ src $$ unpackTemplate receiveMem id

Since 0.1.0

receiveFS Source #

Arguments

:: forall (m :: Type -> Type). MonadResource m |
=> FilePath | root
-> FileReceiver m |

Receive files to the given folder on the filesystem.

    unpackTemplate (receiveFS "some-destination") (T.replace "PROJECTNAME" "foo")

Since 0.1.0

# Exceptions

data ProjectTemplateException Source #

Exceptions that can be thrown.

Since 0.1.0

Constructors

InvalidInput Text |
BinaryLoopNeedsOneLine |

#### Instances

Instances details

Exception ProjectTemplateException Source # |
Instance details Defined in Text.ProjectTemplate Methods toException :: ProjectTemplateException -> SomeException Source # fromException :: SomeException -> Maybe ProjectTemplateException Source # displayException :: ProjectTemplateException -> String Source # backtraceDesired :: ProjectTemplateException -> Bool Source #
Show ProjectTemplateException Source # |
Instance details Defined in Text.ProjectTemplate Methods showsPrec :: Int -> ProjectTemplateException -> ShowS Source # show :: ProjectTemplateException -> String Source # showList :: [ProjectTemplateException] -> ShowS Source #