3 module Util.GenerateHtmlTCombinators where
5 import Control.Applicative
7 import Language.Haskell.TH
8 import System.Directory
12 import Text.Regex.TDFA
13 import Util.GenerateHtmlCombinators hiding (getModuleName, main)
15 declare :: HtmlVariant -> [Dec]
16 declare x = concatMap (\(w,ls) -> concatMap (g w) ls)
17 [(("wrapMarkup2","Markup2"),"docTypeHtml" : parents x)
18 ,(("wrapMarkup","Markup"), "docType" : leafs x)]
21 ,ValD (VarP l) (NormalB (AppE (VarE w)
22 $ VarE $ mkName $ getModuleName "Blaze" x ++"."++l')) []]
23 where [w,t,l] = fmap mkName [w',t',l']
27 writeSource :: HtmlVariant -> IO ()
28 writeSource v = mapM_ g [True, False]
31 let path = if attr then "Attributes" else ""
32 name = (if attr then "." else "") ++ path
33 [mT,m] = ((++ name) . flip getModuleName v) <$>
35 exports = if attr then [m] else [mT, "Text.BlazeT.Html"]
36 f = (joinPath $ ["src","Text","BlazeT"] ++ version v
38 body = if attr then "" else unlines $
39 map (printf "import Text.BlazeT%s") ["", ".Html", ".Internal"]
40 ++ ["", show ( ppr_list $ declare v)]
41 quali = if attr then "" else "qualified "
42 docs True = "This module simply reexports the corresponding @blaze-html@ module."
43 docs False = printf "This module wraps all exports of \"%s\" using 'wrapMarkup' and 'wrapMarkup'." m
44 createDirectoryIfMissing True $ takeDirectory $ f
45 writeFile f $ unlines $
48 ,printf "(Automatically generated by @%s:%d@)\n"
49 (subRegex (mkRegex "/") __FILE__ "\\\\/") ( __LINE__ :: Int)
53 ," (" ++ intercalate "\n ," (map ("module "++) exports)
55 ,"import "++ quali ++ m
58 main = mapM_ writeSource htmlVariants
61 getModuleName :: String -> HtmlVariant -> String
62 getModuleName base = (("Text."++base++".")++) . intercalate "." . version