diff options
author | Johannes Gerer <oss@johannesgerer.com> | 2016-10-26 03:39:23 +0200 |
---|---|---|
committer | Johannes Gerer <oss@johannesgerer.com> | 2016-10-26 03:39:23 +0200 |
commit | 86d89e47d648770ae36dba01f7ae09d34f2ee171 (patch) | |
tree | 504457544a461b341bf5a8c9f56368b5e2cba554 /README.md | |
parent | 675085c2e0b0b851378da08b7d73024766107c87 (diff) | |
download | blazeT-86d89e47d648770ae36dba01f7ae09d34f2ee171.tar.gz blazeT-86d89e47d648770ae36dba01f7ae09d34f2ee171.tar.zst blazeT-86d89e47d648770ae36dba01f7ae09d34f2ee171.zip |
a
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 75 |
1 files changed, 64 insertions, 11 deletions
@@ -26,14 +26,14 @@ accumulating log or other diagnostic output | |||
26 | doing `IO` (like database access) are the first things that come to | 26 | doing `IO` (like database access) are the first things that come to |
27 | mind. | 27 | mind. |
28 | 28 | ||
29 | The initial reason of existence of this library is its use | 29 | The reason of existence of this library is its use |
30 | in [Lykah](http://johannesgerer.com/Lykah), which powers my personal | 30 | in [Lykah](http://johannesgerer.com/Lykah), which powers my personal |
31 | website | 31 | website |
32 | [http://johannesgerer.com](http://johannesgerer.com/johannesgerer.com). In | 32 | [http://johannesgerer.com](http://johannesgerer.com/johannesgerer.com). In |
33 | Lykah, the HTML templates have access to the whole site structure (to | 33 | Lykah, the HTML templates have access to the whole site structure (to |
34 | build things like menus) and automatically check, insert and keep | 34 | build things like menus or blog post lists) and automatically check, |
35 | track of referenced pages and assets, which turns out to be very | 35 | insert and keep track of referenced pages and assets, which turns out |
36 | useful for the task of static website generation. | 36 | to 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 | ||
57 | the base monad, whose actions can | ||
58 | be | ||
59 | [`lift`ed](https://hackage.haskell.org/package/transformers-0.5.2.0/docs/Control-Monad-Trans-Class.html) into | ||
60 | the Markup, as shown in the following example | ||
61 | (from [here](src/Readme.hs)): | ||
54 | 62 | ||
63 | ```Haskell | ||
64 | {-# LANGUAGE OverloadedStrings #-} | ||
65 | |||
66 | import Data.Time (getCurrentTime) | ||
67 | import Text.BlazeT.Html5 hiding (main) | ||
68 | import Text.BlazeT.Renderer.String | ||
69 | import Control.Monad.Trans.Class (lift) | ||
70 | |||
71 | -- Backwords compatible Blaze HTML | ||
72 | old :: Markup | ||
73 | old = do | ||
74 | p $ "created with blaze-html" | ||
75 | |||
76 | -- BlazeT HTML with lifted IO actions | ||
77 | new :: MarkupT IO () | ||
78 | new = do | ||
79 | time <- lift getCurrentTime | ||
80 | p $ string $ "created with blazeT at " ++ show time | ||
81 | |||
82 | main :: IO () | ||
83 | main = do | ||
84 | putStrLn $ renderMarkup old | ||
85 | putStrLn =<< execWith renderMarkup new | ||
86 | |||
87 | ``` | ||
88 | |||
89 | prints: | ||
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 | |||
98 | 1. To make it available on your system (or sandbox) use `cabal install blazeT`. | ||
99 | |||
100 | 2. 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 | ||
104 | cabal sandbox init #optional | ||
105 | cabal 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 |
59 | in | 113 | in |
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 | ||
62 | Everything build around the simple `newtype` definition of the | 116 | Everything 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 |
64 | is | 118 | the |
65 | a | 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 | 120 | of `Blaze.Markup` and is basically a `WriterT` writing `Blaze.Markup`: |
67 | which is basically a `WriterT` transformer writing `Blaze.Markup`: | ||
68 | 121 | ||
69 | ```Haskell | 122 | ```Haskell |
70 | newtype MarkupT m a = MarkupT { fromMarkupT :: WriterT B.Markup m a } | 123 | newtype MarkupT m a = MarkupT { fromMarkupT :: WriterT B.Markup m a } |