GaBuZoMeu/Registry/registry2mulhtml.hs

38 lines
1.1 KiB
Haskell

import qualified IO
import qualified System
import Registry.Utils
import Registry.Grammar (registry)
import Registry.Registry
infile = "./language-subtag-registry"
outdir = "./registry-html"
display reg thistype thisvalue =
-- We should always retrieve only one value, so we can take the head
toHTML ((filter (onlyThisValue thistype thisvalue)
(filter (onlyThisType thistype) reg)) !! 0)
toHTMLFiles reg thetype =
mapM (toHTMLfile reg thetype) (filter (onlyThisType thetype) reg)
toHTMLfile reg thistype thisvalue = do
let outfile = outdir ++ "/" ++ thistype ++ "/" ++ (toSubtag thisvalue) ++ ".html"
f <- IO.openFile (outfile) IO.WriteMode
IO.hPutStr f (display reg thistype (toSubtag thisvalue))
IO.hClose f
foreach [] func = return ()
foreach a func = do
func (head a)
foreach (tail a) func
main = do
f <- IO.openFile (infile) IO.ReadMode
input <- IO.hGetContents f
let theregistry = getRegistry input
foreach ["language", "script", "region", "variant",
"redundant", "grandfathered"]
(toHTMLFiles theregistry)