Skip to content

Instantly share code, notes, and snippets.

@dmatveev
Created March 2, 2012 11:44
Show Gist options
  • Save dmatveev/1957949 to your computer and use it in GitHub Desktop.
Save dmatveev/1957949 to your computer and use it in GitHub Desktop.
Dummy
import Data.List (isSuffixOf)
import Data.Char (ord)
import Control.Monad (forM)
import System.IO (IOMode(..), withFile, hPutStrLn)
import System.FilePath (dropExtension)
import System.Directory (getDirectoryContents)
target :: FilePath -> Bool
target p = ".htm" `isSuffixOf` p
fillDummies :: FilePath -> IO ()
fillDummies path = do
files <- getDirectoryContents path
forM (filter target files) fillDummy
return ()
fillDummy :: FilePath -> IO ()
fillDummy path = withFile path WriteMode writeTemplate
where writeTemplate h = hPutStrLn h (templateFor path)
templateFor :: FilePath -> String
templateFor path = concat [p1, title, p2, title, p3]
where title = escape $ dropExtension path
p1 = "<html><head><title>"
p2 = "</title></head><body>"
p3 = "</body></html>"
escape :: String -> String
escape xs = concat $ map code xs
where code c = "&#" ++ show (ord c) ++ ";"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment