Skip to content

Commit 39dad70

Browse files
committed
Made Main.hs call Utils createFile function
1 parent d7d252f commit 39dad70

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

code/drasil-code/test/Main.hs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ import Language.Drasil.GOOL (AuxiliarySym(..), package,
1515
unPP, unJP, unCSP, unCPPP, unSP, unJLP)
1616
import qualified Language.Drasil.GOOL as D (filePath, FileAndContents(..))
1717

18-
import Utils.Drasil (createDirIfMissing)
18+
import Utils.Drasil (createDirIfMissing, createFile)
1919

2020
import Text.PrettyPrint.HughesPJ (render)
2121
import Control.Monad.State (evalState, runState)
2222
import Control.Lens ((^.))
2323
import Data.Functor ((<&>))
2424
import Data.Foldable (traverse_)
2525
import System.Directory (setCurrentDirectory, getCurrentDirectory)
26-
import System.FilePath.Posix (takeDirectory)
27-
import System.IO (hClose, hPutStrLn, openFile, IOMode(WriteMode))
2826
import Prelude hiding (return,print,log,exp,sin,cos,tan)
2927

3028
import HelloWorld (helloWorldOO, helloWorldProc)
@@ -104,17 +102,6 @@ jlClasses unRepr unRepr' = zipWith
104102

105103
-- | Creates the requested 'Code' by producing files.
106104
createCodeFiles :: [(Label, D.FileAndContents)] -> IO ()
107-
createCodeFiles = traverse_ createCodeFile
108-
109-
-- | Helper that creates the file and renders code.
110-
createCodeFile :: (Label, D.FileAndContents) -> IO ()
111-
createCodeFile (n, file) = do
112-
let path = D.filePath file
113-
code = D.fileDoc file
114-
createDirIfMissing False n
115-
setCurrentDirectory n
116-
createDirIfMissing True (takeDirectory path)
117-
h <- openFile path WriteMode
118-
hPutStrLn h (render code)
119-
hClose h
120-
setCurrentDirectory ".."
105+
createCodeFiles = traverse_ $ \(name, file) -> do
106+
let path = name ++ "/" ++ D.filePath file
107+
createFile path (render $ D.fileDoc file)

0 commit comments

Comments
 (0)