From db602e8a79ad8eee652bd3d7e2be74787d11a34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Hahn?= Date: Tue, 26 Jan 2016 00:27:07 +0100 Subject: [PATCH] tutorial: add tutorial compiling script and conversion script --- .gitignore | 1 + servant-examples/tutorial/check/check.sh | 11 +++++++++ servant-examples/tutorial/check/tinc.yaml | 15 ++++++++++++ servant-examples/tutorial/convert.hs | 30 +++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100755 servant-examples/tutorial/check/check.sh create mode 100644 servant-examples/tutorial/check/tinc.yaml create mode 100644 servant-examples/tutorial/convert.hs diff --git a/.gitignore b/.gitignore index f42f014b..1ea6ffef 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ Setup shell.nix default.nix doc/_build +doc/venv diff --git a/servant-examples/tutorial/check/check.sh b/servant-examples/tutorial/check/check.sh new file mode 100755 index 00000000..5425d80a --- /dev/null +++ b/servant-examples/tutorial/check/check.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -o errexit + +# tinc + +cabal exec -- ghc -Wall -Werror -outputdir build-output ../api-type.lhs -O0 -c -pgmL markdown-unlit +#cabal exec -- ghc -Wall -Werror -outputdir build-output ../server.lhs -O0 -c -fno-warn-missing-methods -fno-warn-name-shadowing +#cabal exec -- ghc -Wall -Werror -outputdir build-output ../client.lhs -O0 -c -fno-warn-missing-methods -fno-warn-name-shadowing +#cabal exec -- ghc -Wall -Werror -outputdir build-output ../javascript.lhs -O0 -c -fno-warn-missing-methods +#cabal exec -- ghc -Wall -Werror -ibuild-output -outputdir build-output ../docs.lhs -O0 -c -fno-warn-missing-methods diff --git a/servant-examples/tutorial/check/tinc.yaml b/servant-examples/tutorial/check/tinc.yaml new file mode 100644 index 00000000..2a32c412 --- /dev/null +++ b/servant-examples/tutorial/check/tinc.yaml @@ -0,0 +1,15 @@ +dependencies: + - name: servant + path: ../../../servant + - name: servant-server + path: ../../../servant-server + - name: servant-client + path: ../../../servant-client + - name: servant-js + path: ../../../servant-js + - name: servant-lucid + path: ../../../servant-lucid + - name: servant-docs + path: ../../../servant-docs + - name: servant-foreign + path: ../../../servant-foreign diff --git a/servant-examples/tutorial/convert.hs b/servant-examples/tutorial/convert.hs new file mode 100644 index 00000000..ebcca21e --- /dev/null +++ b/servant-examples/tutorial/convert.hs @@ -0,0 +1,30 @@ + +import Control.Arrow +import Data.Foldable +import Data.List +import System.Environment + +main = do + files <- getArgs + forM_ files $ \ file -> do + convertM file + +convertM :: FilePath -> IO () +convertM file = do + contents <- readFile file + seq (length contents) (return ()) + writeFile file (convert contents) + +convert :: String -> String +convert = + lines >>> + groupBy (\ a b -> take 1 a == take 1 b) >>> + map go >>> + concat >>> + unlines + where + go :: [String] -> [String] + go (a : r) + | ">" `isPrefixOf` a + = "``` haskell" : map (drop 2) (a : r) ++ "```" : [] + go x = x