on master help sign in
Merge pull request #91 from sol/master

Use pandoc-unlit for README

commitbe3dcd20a89a81d4bc919f7406bb58d5956a4ba5 authorMichael Snoyman <michael@snoyman.com> dateMon 16 Jul 2012, 11:27 (14 years ago) parent8b23847fd05d31
4 files changed+57−182
wai/.ghci+1 wai/README.lhs+1−113 wai/README.md+55−48 wai/lhs2md.sh−21
wai/.ghcinew file+1
@@ -0,0 +1 @@
1+:set -i../warp -i../warp/dist/build/autogen/ -pgmL pandoc-unlit
wai/README.lhsmode 100644 → 120000+1−113
@@ -1,113 +0,0 @@
1−WAI: Web Application Interface
2−==============================
3−
4−Getting started
5−---------------
6−
7−You want a minimal example? Here it is!
8−
9−> {-# LANGUAGE OverloadedStrings #-}
10−> import Network.Wai
11−> import Network.HTTP.Types
12−> import Network.Wai.Handler.Warp (run)
13−> import Data.ByteString.Lazy.Char8 () -- Just for an orphan instance
14−> import Control.Monad.IO.Class (liftIO)
15−>
16−> app :: Application
17−> app _ = do
18−> liftIO $ putStrLn "I've done some IO here"
19−> return $ responseLBS
20−> status200
21−> [("Content-Type", "text/plain")]
22−> "Hello, Web!"
23−>
24−> main :: IO ()
25−> main = do
26−> putStrLn $ "http://localhost:8080/"
27−> run 8080 app
28−
29−Put that code into a file named _hello.hs_ and install [wai] and
30−[warp] from Hackage:
31−
32− cabal install wai warp
33−
34−Run it:
35−
36− runhaskell hello.hs
37−
38−Point your browser to:
39−
40− http://localhost:8080/
41−
42−
43−Serving static content
44−----------------------
45−
46−We can modify our previous example to serve static content. For this
47−create a file named _index.html_:
48−
49− <p>Hello, Web!</p>
50−
51−Now we redefine `responseBody` to refer to that file:
52−
53−> app2 :: Application
54−> app2 _ = return index
55−>
56−> index = ResponseFile
57−> status200
58−> [("Content-Type", "text/html")]
59−> "index.html"
60−> Nothing
61−
62−
63−Basic dispatching
64−-----------------
65−
66−An `Application` maps `Request`s to `Response`s:
67−
68− ghci> :info Application
69− type Application = Request -> IO Response
70−
71−Depending on the path info provided with each `Request` we can serve
72−different `Response`s:
73−
74−> app3 :: Application
75−> app3 request = case rawPathInfo request of
76−> "/" -> return index
77−> "/raw/" -> return plainIndex
78−> _ -> return notFound
79−>
80−> plainIndex = ResponseFile
81−> status200
82−> [("Content-Type", "text/plain")]
83−> "index.html"
84−> Nothing
85−>
86−> notFound = responseLBS
87−> status404
88−> [("Content-Type", "text/plain")]
89−> "404 - Not Found"
90−
91−
92−Doing without overloaded strings
93−--------------------------------
94−
95−For the sake of efficiency, WAI uses the [bytestring] package. We used
96−GHCs [overloaded strings] to almost hide this fact. But we can easily do
97−without. What follows is a more verbose definition of `notFound`, that
98−works without GHC extensions:
99−
100− import qualified Data.ByteString.Char8 as B8
101− import qualified Data.ByteString.Lazy.Char8 as LB8
102− import Data.CaseInsensitive (mk)
103−
104− notFound = responseLBS
105− status404
106− [(mk $ B8.pack "Content-Type", B8.pack "text/plain")]
107− (LB8.pack "404 - Not Found")
108−
109−
110− [wai]: http://hackage.haskell.org/package/wai
111− [warp]: http://hackage.haskell.org/package/warp
112− [overloaded strings]: http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class-extensions.html#overloaded-strings
113− [bytestring]: http://hackage.haskell.org/package/bytestring
@@ -0,0 +1 @@
1+README.md
wai/README.md+55−48
@@ -1,4 +1,3 @@
1−<!-- Generated from README.lhs, do not modify! -->
21WAI: Web Application Interface
32==============================
43
@@ -7,25 +6,27 @@ Getting started
76
87You want a minimal example? Here it is!
98
10− {-# LANGUAGE OverloadedStrings #-}
11− import Network.Wai
12− import Network.HTTP.Types
13− import Network.Wai.Handler.Warp (run)
14− import Data.ByteString.Lazy.Char8 () -- Just for an orphan instance
15− import Control.Monad.IO.Class (liftIO)
16−
17− app :: Application
18− app _ = do
19− liftIO $ putStrLn "I've done some IO here"
20− return $ responseLBS
21− status200
22− [("Content-Type", "text/plain")]
23− "Hello, Web!"
24−
25− main :: IO ()
26− main = do
27− putStrLn $ "http://localhost:8080/"
28− run 8080 app
9+~~~ {.haskell .literate}
10+{-# LANGUAGE OverloadedStrings #-}
11+import Network.Wai
12+import Network.HTTP.Types
13+import Network.Wai.Handler.Warp (run)
14+import Data.ByteString.Lazy.Char8 () -- Just for an orphan instance
15+import Control.Monad.IO.Class (liftIO)
16+
17+app :: Application
18+app _ = do
19+ liftIO $ putStrLn "I've done some IO here"
20+ return $ responseLBS
21+ status200
22+ [("Content-Type", "text/plain")]
23+ "Hello, Web!"
24+
25+main :: IO ()
26+main = do
27+ putStrLn $ "http://localhost:8080/"
28+ run 8080 app
29+~~~
2930
3031Put that code into a file named _hello.hs_ and install [wai] and [warp] from Hackage:
3132
@@ -49,14 +50,16 @@ We can modify our previous example to serve static content. For this create a fi
4950
5051Now we redefine `responseBody` to refer to that file:
5152
52− app2 :: Application
53− app2 _ = return index
53+~~~ {.haskell .literate}
54+app2 :: Application
55+app2 _ = return index
5456
55− index = ResponseFile
56− status200
57− [("Content-Type", "text/html")]
58− "index.html"
59− Nothing
57+index = ResponseFile
58+ status200
59+ [("Content-Type", "text/html")]
60+ "index.html"
61+ Nothing
62+~~~
6063
6164
6265Basic dispatching
@@ -69,22 +72,24 @@ An `Application` maps `Request`s to `Response`s:
6972
7073Depending on the path info provided with each `Request` we can serve different `Response`s:
7174
72− app3 :: Application
73− app3 request = case rawPathInfo request of
74− "/" -> return index
75− "/raw/" -> return plainIndex
76− _ -> return notFound
75+~~~ {.haskell .literate}
76+app3 :: Application
77+app3 request = case rawPathInfo request of
78+ "/" -> return index
79+ "/raw/" -> return plainIndex
80+ _ -> return notFound
7781
78− plainIndex = ResponseFile
79− status200
80− [("Content-Type", "text/plain")]
81− "index.html"
82− Nothing
82+plainIndex = ResponseFile
83+ status200
84+ [("Content-Type", "text/plain")]
85+ "index.html"
86+ Nothing
8387
84− notFound = responseLBS
85− status404
86− [("Content-Type", "text/plain")]
87− "404 - Not Found"
88+notFound = responseLBS
89+ status404
90+ [("Content-Type", "text/plain")]
91+ "404 - Not Found"
92+~~~
8893
8994
9095Doing without overloaded strings
@@ -92,14 +97,16 @@ Doing without overloaded strings
9297
9398For the sake of efficiency, WAI uses the [bytestring] package. We used GHCs [overloaded strings] to almost hide this fact. But we can easily do without. What follows is a more verbose definition of `notFound`, that works without GHC extensions:
9499
95− import qualified Data.ByteString.Char8 as B8
96− import qualified Data.ByteString.Lazy.Char8 as LB8
97− import Data.CaseInsensitive (mk)
100+~~~ {.haskell}
101+import qualified Data.ByteString.Char8 as B8
102+import qualified Data.ByteString.Lazy.Char8 as LB8
103+import Data.CaseInsensitive (mk)
98104
99− notFound = responseLBS
100− status404
101− [(mk $ B8.pack "Content-Type", B8.pack "text/plain")]
102− (LB8.pack "404 - Not Found")
105+notFound = responseLBS
106+ status404
107+ [(mk $ B8.pack "Content-Type", B8.pack "text/plain")]
108+ (LB8.pack "404 - Not Found")
109+~~~
103110
104111
105112 [wai]: http://hackage.haskell.org/package/wai
wai/lhs2md.shdeleted−21
@@ -1,21 +0,0 @@
1−#!/bin/sh
2−#
3−# Convert a literate Haskell program (README.lhs) to GitHub Flavored
4−# Markdown (README.md).
5−#
6−# For more on GitHub Flavored Markdown see:
7−#
8−# http://github.github.com/github-flavored-markdown/
9−#
10−
11−# add a disclaimer
12−echo '<!-- Generated from README.lhs, do not modify! -->' > README.md
13−
14−cat README.lhs | \
15−
16− # GFM does not ignore line breaks in paragraphs, so we remove them
17− perl -0777 -pe 's/([]a-zA-Z,.`])\n([[a-zA-Z`])/\1 \2/g' | \
18−
19− # convert Bird-style literate Haskell to Markdown code blocks
20− perl -pe 's/^> / /' | \
21− perl -pe 's/^>$//' >> README.md