[Added template replacement code Dino Morelli **20140309191714 Ignore-this: feaa8f5c9ec6c8c8dd914085e3c37504 The project is now building the real Markdown README file ] hunk ./README.md.template 13 -... +$projects hunk ./README.md.template 20 -This would be my only github repo. It's purpose is to build this document you're reading. To change the contents of it, make changes to README.md.template +This would be my only github repo. It's purpose is to build this document you're reading. To change this content, make changes to README.md.template hunk ./mywork.cabal 26 + bytestring, hunk ./mywork.cabal 32 + template, + text, addfile ./src/Mywork/Template.hs hunk ./src/Mywork/Template.hs 1 +{-# LANGUAGE OverloadedStrings #-} + +module Mywork.Template + ( producePage ) + where + +import qualified Data.Text as T +import Data.Text.Lazy ( toStrict ) +import Data.Text.Template +import Text.Printf + +import Mywork.Project + + +producePage :: String -> [Project] -> String +producePage templateString projects = + T.unpack $ toStrict $ substitute (T.pack templateString) context + + where + context = mkContext + [ ("projects", formatAllProjects projects) + ] + + +-- Create 'Context' from association list. +mkContext :: [(T.Text, T.Text)] -> Context +mkContext assocs x = maybe err id . lookup x $ assocs + where err = error $ "Could not find key: " ++ T.unpack x + + +formatAllProjects :: [Project] -> T.Text +formatAllProjects ps = T.unlines $ + "" : map formatProject ps ++ ["
"] + + +formatProject :: Project -> T.Text +formatProject p = T.pack $ printf + "%s%s[source](%s)" + (pName p) (pSynopsis p) (pSource p) hunk ./src/mywork.hs 6 ---import System.Environment ---import System.Exit hunk ./src/mywork.hs 11 - - -{- +import Mywork.Template + + hunk ./src/mywork.hs 17 --} hunk ./src/mywork.hs 30 - mapM_ print projects - putStrLn "" hunk ./src/mywork.hs 31 - putStrLn "" - - putStrLn =<< dateFormat "%FT%T%z" + + templateString <- readFile templateInFile + let content = producePage templateString projects + writeFile templateOutFile content