aboutsummaryrefslogtreecommitdiffhomepage
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md75
1 files changed, 64 insertions, 11 deletions
diff --git a/README.md b/README.md
index 0169fab..853f1e2 100644
--- a/README.md
+++ b/README.md
@@ -26,14 +26,14 @@ accumulating log or other diagnostic output
26doing `IO` (like database access) are the first things that come to 26doing `IO` (like database access) are the first things that come to
27mind. 27mind.
28 28
29The initial reason of existence of this library is its use 29The reason of existence of this library is its use
30in [Lykah](http://johannesgerer.com/Lykah), which powers my personal 30in [Lykah](http://johannesgerer.com/Lykah), which powers my personal
31website 31website
32[http://johannesgerer.com](http://johannesgerer.com/johannesgerer.com). In 32[http://johannesgerer.com](http://johannesgerer.com/johannesgerer.com). In
33Lykah, the HTML templates have access to the whole site structure (to 33Lykah, the HTML templates have access to the whole site structure (to
34build things like menus) and automatically check, insert and keep 34build things like menus or blog post lists) and automatically check,
35track of referenced pages and assets, which turns out to be very 35insert and keep track of referenced pages and assets, which turns out
36useful for the task of static website generation. 36to be very useful functionality of a static website generator.
37 37
38# How to use it? 38# How to use it?
39 39
@@ -51,20 +51,73 @@ their [documentation](https://jaspervdj.be/blaze/).
51 51
52## Unleash the monads 52## Unleash the monads
53 53
54[Text.BlazeT](https://hackage.haskell.org/package/blazeT/docs/Text-BlazeT.html) exports
55`runWith` and `execWith`, which work on any
56`Text.Blaze.Renderer.*`. The rendered markup will be returned within
57the base monad, whose actions can
58be
59[`lift`ed](https://hackage.haskell.org/package/transformers-0.5.2.0/docs/Control-Monad-Trans-Class.html) into
60the Markup, as shown in the following example
61(from [here](src/Readme.hs)):
54 62
63```Haskell
64{-# LANGUAGE OverloadedStrings #-}
65
66import Data.Time (getCurrentTime)
67import Text.BlazeT.Html5 hiding (main)
68import Text.BlazeT.Renderer.String
69import Control.Monad.Trans.Class (lift)
70
71-- Backwords compatible Blaze HTML
72old :: Markup
73old = do
74 p $ "created with blaze-html"
75
76-- BlazeT HTML with lifted IO actions
77new :: MarkupT IO ()
78new = do
79 time <- lift getCurrentTime
80 p $ string $ "created with blazeT at " ++ show time
81
82main :: IO ()
83main = do
84 putStrLn $ renderMarkup old
85 putStrLn =<< execWith renderMarkup new
86
87```
88
89prints:
90
91```HTML
92<p>created with blaze-html</p>
93<p>created with blazeT at 2016-10-26 01:09:16.969147361 UTC</p>
94```
95
96# Installation
97
981. To make it available on your system (or sandbox) use `cabal install blazeT`.
99
1002. To play around with the source, obtain by cloning this repo or use
101 `cabal get blazet`, enter the directory and run:
102
103```bash
104cabal sandbox init #optional
105cabal install
106```
107
108# Documentation on [Hackage](https://hackage.haskell.org/package/blazeT)
55 109
56# Implementation 110# Implementation
57 111
58... is located 112... is contained
59in 113in
60[Text.BlazeT.Internals](https://hackage.haskell.org/package/blazeT/docs/Text-BlazeT-Internals.html). 114[Text.BlazeT.Internals](https://hackage.haskell.org/package/blazeT/docs/Text-BlazeT-Internals.html).
61 115
62Everything build around the simple `newtype` definition of the 116Everything is build around the simple `newtype` definition of the
63`MarkupT` transformer, which makes use of the fact that `Blaze.Markup` 117`MarkupT` transformer, which makes use
64is 118the
65a 119[Monoid](https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Monoid.html) instance
66[Monoid](https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Monoid.html) and 120of `Blaze.Markup` and is basically a `WriterT` writing `Blaze.Markup`:
67which is basically a `WriterT` transformer writing `Blaze.Markup`:
68 121
69```Haskell 122```Haskell
70newtype MarkupT m a = MarkupT { fromMarkupT :: WriterT B.Markup m a } 123newtype MarkupT m a = MarkupT { fromMarkupT :: WriterT B.Markup m a }