module Drasil.Generator.LessonPlan (
exportLessonPlan
) where
import Prelude hiding (id)
import Control.Lens ((^.))
import System.IO (hClose, hPutStrLn, openFile, IOMode(WriteMode))
import Text.PrettyPrint.HughesPJ (render)
import Drasil.DocumentLanguage.Notebook (LsnDesc, mkNb)
import Language.Drasil (Stage(Equational))
import qualified Language.Drasil.Sentence.Combinators as S
import Language.Drasil.Printers (defaultConfiguration, piSys,
genJupyterLessonPlan)
import Language.Drasil.Printing.Import (makeDocument)
import Drasil.System (System, refTable, systemdb)
import Utils.Drasil (createDirIfMissing)
exportLessonPlan :: System -> LsnDesc -> String -> IO ()
exportLessonPlan :: System -> LsnDesc -> String -> IO ()
exportLessonPlan System
syst LsnDesc
nbDecl String
lsnFileName = do
let nb :: Document
nb = LsnDesc -> (IdeaDict -> CI -> Sentence) -> System -> Document
mkNb LsnDesc
nbDecl IdeaDict -> CI -> Sentence
forall c d. (NamedIdea c, NamedIdea d) => c -> d -> Sentence
S.forT System
syst
printSetting :: PrintingInformation
printSetting = ChunkDB
-> Map UID Reference
-> Stage
-> PrintingConfiguration
-> PrintingInformation
piSys (System
syst System -> Getting ChunkDB System ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB System ChunkDB
forall c. HasSystem c => Lens' c ChunkDB
Lens' System ChunkDB
systemdb) (System
syst System
-> Getting (Map UID Reference) System (Map UID Reference)
-> Map UID Reference
forall s a. s -> Getting a s a -> a
^. Getting (Map UID Reference) System (Map UID Reference)
forall c. HasSystem c => Lens' c (Map UID Reference)
Lens' System (Map UID Reference)
refTable) Stage
Equational PrintingConfiguration
defaultConfiguration
dir :: String
dir = String
"Lesson/"
fn :: String
fn = String
lsnFileName String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
".ipynb"
pd :: Document
pd = PrintingInformation -> Document -> Document
makeDocument PrintingInformation
printSetting Document
nb
Bool -> String -> IO ()
createDirIfMissing Bool
True String
dir
Handle
outh <- String -> IOMode -> IO Handle
openFile (String
dir String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fn) IOMode
WriteMode
Handle -> String -> IO ()
hPutStrLn Handle
outh (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ Doc -> String
render (Doc -> String) -> Doc -> String
forall a b. (a -> b) -> a -> b
$ Document -> Doc
genJupyterLessonPlan Document
pd
Handle -> IO ()
hClose Handle
outh