GaBuZoMeu/Registry/registry2mulhtml.hs

41 lines
1.2 KiB
Haskell
Raw Normal View History

2023-06-09 09:42:58 +02:00
import qualified System.IO as IO
2023-06-08 21:49:35 +02:00
import Registry.Utils
import Registry.Grammar (registry)
import Registry.Registry
import System.Directory (createDirectoryIfMissing)
2023-06-08 21:49:35 +02:00
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"]
(\arg ->
createDirectoryIfMissing True (outdir ++ "/" ++ arg) >>
toHTMLFiles theregistry arg)
2023-06-08 21:49:35 +02:00