Created
March 2, 2012 11:44
-
-
Save dmatveev/1957949 to your computer and use it in GitHub Desktop.
Dummy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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