Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 50 lines (44 sloc) 1.48 kB
8983267 @lymar update README
lymar authored
1 #!/usr/local/bin/runhaskell
2 import Text.Hastache
3 import Text.Hastache.Context
4 import qualified Data.ByteString.Lazy as LZ
5 import System.Process (readProcess)
6 import System.Directory (setCurrentDirectory, getCurrentDirectory)
7 import System.FilePath ((</>))
8 import Data.List (span, lines, intersperse)
9 import Data.Char (isSpace)
10
11 main = do
12 res <- hastacheFile defaultConfig "README.md.ha"
13 (mkStrContext context)
14 LZ.writeFile "README.md" res
15 where
16 context "example" = MuLambdaM $ \fn -> do
17 cd <- setExampleDir
18 fc <- readFile $ exampleFile fn
19 let { forTC = case span (\t -> trim t /= be) (lines $ trim fc) of
20 (a,[]) -> a
21 (_,a) -> drop 1 a }
22 let explText = concat $ intersperse "\n" forTC
23
24 setCurrentDirectory cd
25 return $ concat [
26 "```haskell\n"
27 , explText
28 , "\n```"
29 ]
30
31 context "runExample" = MuLambdaM $ \fn -> do
32 cd <- setExampleDir
33 explRes <- readProcess "runhaskell" [exampleFile fn] []
34 setCurrentDirectory cd
35 return $ concat [
36 "```\n"
37 , trim explRes
38 , "\n```"
39 ]
40
41 be = "-- begin example"
42 setExampleDir = do
43 cd <- getCurrentDirectory
df218e6 @lymar fix dir name
lymar authored
44 setCurrentDirectory $ cd </> "examples"
8983267 @lymar update README
lymar authored
45 return cd
46 exampleFile fn = decodeStr fn ++ ".hs"
47
48 trim :: String -> String
49 trim = f . f where f = reverse . dropWhile isSpace
Something went wrong with that request. Please try again.