@@ -10,8 +10,6 @@ import Data.Map (fromList, member, keys, elems)
1010import Data.Maybe (maybeToList , catMaybes )
1111import Data.Foldable (traverse_ )
1212import System.Directory (setCurrentDirectory , getCurrentDirectory )
13- import System.FilePath.Posix (takeDirectory )
14- import System.IO (hPutStrLn , hClose , openFile , IOMode (WriteMode ))
1513import Text.PrettyPrint.HughesPJ (isEmpty , vcat , render )
1614
1715import Language.Drasil
@@ -23,7 +21,7 @@ import qualified Drasil.GProc as Proc (GSProgram, SFile, ProgramSym(..), unCI)
2321import Language.Drasil.Printers (SingleLine (OneLine ), sentenceDoc , piSys , plainConfiguration )
2422import Language.Drasil.Printing.Import (spec )
2523import Drasil.System
26- import Utils.Drasil (createDirIfMissing )
24+ import Utils.Drasil (createDirIfMissing , createFile )
2725
2826import Language.Drasil.Code.Imperative.ConceptMatch (chooseConcept )
2927import Language.Drasil.Code.Imperative.Descriptions (unmodularDesc )
@@ -47,7 +45,7 @@ import Language.Drasil.Code.Imperative.GOOL.ClassInterface (
4745 makeSds , AuxiliarySym (.. ), package )
4846import Language.Drasil.Code.Imperative.README (ReadMeInfo (.. ))
4947import Language.Drasil.Code.FileData (PackageData (.. ), FileAndContents (.. ),
50- fileAndContents , fileDataToFileAndContents )
48+ fileAndContents , hasPathAndDocToFileAndContents )
5149import Language.Drasil.Code.FileNames (sampleInputName )
5250import Language.Drasil.Code.ExtLibImport (auxMods , imports , modExports )
5351import Language.Drasil.Code.Lang (Lang (.. ))
@@ -131,8 +129,10 @@ generateCode l unReprProg unReprPack g = do
131129 aux
132130 | l == Python = fileAndContents " __init__.py" mempty : baseAux
133131 | otherwise = baseAux
134- packageFiles = map fileDataToFileAndContents (progMods $ packageProg $ unReprPack pckg) ++ aux
135- traverse_ createFile packageFiles
132+ packageFiles = map
133+ hasPathAndDocToFileAndContents (progMods $ packageProg $ unReprPack pckg)
134+ ++ aux
135+ traverse_ (\ file -> createFile (filePath file) (render $ fileDoc file)) packageFiles
136136 setCurrentDirectory workingDir
137137
138138-- | Generates a package, including a Makefile, sample input file, and Doxygen
@@ -243,8 +243,10 @@ generateCodeProc l unReprProg unReprPack g = do
243243 let (pckg, ds) = runState (genPackageProc unReprProg) g
244244 baseAux = [fileAndContents " designLog.txt" (ds ^. designLog) |
245245 not $ isEmpty $ ds ^. designLog] ++ packageAux (unReprPack pckg)
246- packageFiles = map fileDataToFileAndContents (progMods (packageProg $ unReprPack pckg)) ++ baseAux
247- traverse_ createFile packageFiles
246+ packageFiles = map
247+ hasPathAndDocToFileAndContents (progMods (packageProg $ unReprPack pckg))
248+ ++ baseAux
249+ traverse_ (\ file -> createFile (filePath file) (render $ fileDoc file)) packageFiles
248250 setCurrentDirectory workingDir
249251
250252-- | Generates a package, including a Makefile, sample input file, and Doxygen
@@ -338,17 +340,6 @@ genModulesProc = do
338340 if con then error " genModulesProc: Procedural renderers do not support classes"
339341 else return $ mn : inp ++ cal : out ++ moddef
340342
341- -- | Helper to convert a FileAndContents into a real file with the given document
342- -- at the given FilePath
343- createFile :: FileAndContents -> IO ()
344- createFile file = do
345- let path = filePath file
346- contents = fileDoc file
347- createDirIfMissing True (takeDirectory path)
348- h <- openFile path WriteMode
349- hPutStrLn h (render contents)
350- hClose h
351-
352343-- | Private utilities used in 'generateCode'.
353344getDir :: Lang -> String
354345getDir Cpp = " cpp"
0 commit comments