module Drasil.LessonPlan.Renderer (render) where
import Control.Lens ((^.))
import Drasil.Database (ChunkDB)
import Language.Drasil (Sentence(S), CI, foldlList, SepType(Comma),
FoldType(List), fullName, Idea, titleize, titleize')
import Language.Drasil.Document (Section, Document(Notebook), Contents(UlC),
ulcc, RawContent(Bib), section, makeSecRef)
import Drasil.System (HasSystemMeta(..))
import Drasil.Metadata.Documentation (notebook)
import qualified Drasil.Metadata.Documentation as Doc (caseProb, introduction,
learnObj, review, summary, example, appendix, reference)
import Drasil.LessonPlan.Core (LessonPlan)
import Drasil.LessonPlan.Document (LsnDesc, LsnChapter(..))
import Drasil.LessonPlan.ExtractBib (extractBib)
render :: LessonPlan -> LsnDesc -> (CI -> CI -> Sentence) -> Document
render :: LessonPlan -> LsnDesc -> (CI -> CI -> Sentence) -> Document
render LessonPlan
plan LsnDesc
dd CI -> CI -> Sentence
comb = Sentence -> Sentence -> [Section] -> Document
Notebook Sentence
nm Sentence
as ([Section] -> Document) -> [Section] -> Document
forall a b. (a -> b) -> a -> b
$ ChunkDB -> LsnDesc -> [Section]
mkSections (LessonPlan
plan LessonPlan -> Getting ChunkDB LessonPlan ChunkDB -> ChunkDB
forall s a. s -> Getting a s a -> a
^. Getting ChunkDB LessonPlan ChunkDB
forall c. HasSystemMeta c => Lens' c ChunkDB
Lens' LessonPlan ChunkDB
systemdb) LsnDesc
dd
where
nm :: Sentence
nm = CI
notebook CI -> CI -> Sentence
`comb` (LessonPlan
plan LessonPlan -> Getting CI LessonPlan CI -> CI
forall s a. s -> Getting a s a -> a
^. Getting CI LessonPlan CI
forall c. HasSystemMeta c => Lens' c CI
Lens' LessonPlan CI
sysName)
as :: Sentence
as = SepType -> FoldType -> [Sentence] -> Sentence
foldlList SepType
Comma FoldType
List ([Sentence] -> Sentence) -> [Sentence] -> Sentence
forall a b. (a -> b) -> a -> b
$ (Person -> Sentence) -> [Person] -> [Sentence]
forall a b. (a -> b) -> [a] -> [b]
map (String -> Sentence
S (String -> Sentence) -> (Person -> String) -> Person -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Person -> String
forall n. HasName n => n -> String
fullName) ([Person] -> [Sentence]) -> [Person] -> [Sentence]
forall a b. (a -> b) -> a -> b
$ LessonPlan
plan LessonPlan -> Getting [Person] LessonPlan [Person] -> [Person]
forall s a. s -> Getting a s a -> a
^. Getting [Person] LessonPlan [Person]
forall c. HasSystemMeta c => Lens' c [Person]
Lens' LessonPlan [Person]
authors
mkSections :: ChunkDB -> LsnDesc -> [Section]
mkSections :: ChunkDB -> LsnDesc -> [Section]
mkSections ChunkDB
db LsnDesc
dd = (LsnChapter -> Section) -> LsnDesc -> [Section]
forall a b. (a -> b) -> [a] -> [b]
map LsnChapter -> Section
doit LsnDesc
dd
where
bib :: [Contents]
bib = [UnlabelledContent -> Contents
UlC (UnlabelledContent -> Contents) -> UnlabelledContent -> Contents
forall a b. (a -> b) -> a -> b
$ RawContent -> UnlabelledContent
ulcc (BibRef -> RawContent
Bib (BibRef -> RawContent) -> BibRef -> RawContent
forall a b. (a -> b) -> a -> b
$ ChunkDB -> LsnDesc -> BibRef
extractBib ChunkDB
db LsnDesc
dd)]
doit :: LsnChapter -> Section
doit :: LsnChapter -> Section
doit (Intro [Contents]
i) = String -> IdeaDict -> [Contents] -> [Section] -> Section
forall c.
Idea c =>
String -> c -> [Contents] -> [Section] -> Section
mkLsnSec String
"Intro" IdeaDict
Doc.introduction [Contents]
i []
doit (LearnObj [Contents]
lo) = String -> CI -> [Contents] -> [Section] -> Section
forall c.
Idea c =>
String -> c -> [Contents] -> [Section] -> Section
mkLsnSec' String
"LearnObj" CI
Doc.learnObj [Contents]
lo []
doit (Review [Contents]
r [Section]
ss) = String -> IdeaDict -> [Contents] -> [Section] -> Section
forall c.
Idea c =>
String -> c -> [Contents] -> [Section] -> Section
mkLsnSec String
"Review" IdeaDict
Doc.review [Contents]
r [Section]
ss
doit (CaseProb [Contents]
cp [Section]
ss) = String -> IdeaDict -> [Contents] -> [Section] -> Section
forall c.
Idea c =>
String -> c -> [Contents] -> [Section] -> Section
mkLsnSec String
"CaseProb" IdeaDict
Doc.caseProb [Contents]
cp [Section]
ss
doit (Example [Contents]
e) = String -> IdeaDict -> [Contents] -> [Section] -> Section
forall c.
Idea c =>
String -> c -> [Contents] -> [Section] -> Section
mkLsnSec String
"Example" IdeaDict
Doc.example [Contents]
e []
doit (Smmry [Contents]
s) = String -> IdeaDict -> [Contents] -> [Section] -> Section
forall c.
Idea c =>
String -> c -> [Contents] -> [Section] -> Section
mkLsnSec String
"Summary" IdeaDict
Doc.summary [Contents]
s []
doit LsnChapter
BibSec = String -> IdeaDict -> [Contents] -> [Section] -> Section
forall c.
Idea c =>
String -> c -> [Contents] -> [Section] -> Section
mkLsnSec' String
"References" IdeaDict
Doc.reference [Contents]
bib []
doit (Apndx [Contents]
a) = String -> IdeaDict -> [Contents] -> [Section] -> Section
forall c.
Idea c =>
String -> c -> [Contents] -> [Section] -> Section
mkLsnSec String
"Appendix" IdeaDict
Doc.appendix [Contents]
a []
mkLsnSec :: Idea c => String -> c -> [Contents] -> [Section] -> Section
mkLsnSec :: forall c.
Idea c =>
String -> c -> [Contents] -> [Section] -> Section
mkLsnSec String
r c
c [Contents]
cs [Section]
ss = Sentence -> [Contents] -> [Section] -> Reference -> Section
section Sentence
t [Contents]
cs [Section]
ss (String -> Sentence -> Reference
makeSecRef String
r Sentence
t)
where t :: Sentence
t = c -> Sentence
forall n. NamedIdea n => n -> Sentence
titleize c
c
mkLsnSec' :: Idea c => String -> c -> [Contents] -> [Section] -> Section
mkLsnSec' :: forall c.
Idea c =>
String -> c -> [Contents] -> [Section] -> Section
mkLsnSec' String
r c
c [Contents]
cs [Section]
ss = Sentence -> [Contents] -> [Section] -> Reference -> Section
section Sentence
t [Contents]
cs [Section]
ss (String -> Sentence -> Reference
makeSecRef String
r Sentence
t)
where t :: Sentence
t = c -> Sentence
forall n. NamedIdea n => n -> Sentence
titleize' c
c