{-# Language TemplateHaskell #-}
module Language.Drasil.Document.Core where
import Language.Drasil.Chunk.Citation (BibRef)
import Language.Drasil.UID (HasUID(..))
import Language.Drasil.ShortName (HasShortName(shortname))
import Language.Drasil.ModelExpr.Lang (ModelExpr)
import Language.Drasil.CodeExpr.Lang (CodeExpr)
import Language.Drasil.Label.Type (getAdd, prepend, IRefProg,
LblType(..), Referable(..), HasRefAddress(..))
import Language.Drasil.Reference (Reference)
import Language.Drasil.Sentence (Sentence)
import Control.Lens ((^.), makeLenses, Lens', set, view)
data ListType = Bullet [(ItemType, Maybe String)]
| Numeric [(ItemType, Maybe String)]
| Simple [ListTuple]
| Desc [ListTuple]
| Definitions [ListTuple]
data ItemType = Flat Sentence
| Nested Header ListType
type MaxWidthPercent = Float
type Title = Sentence
type Author = Sentence
type = Sentence
type Depth = Int
type Width = Float
type Height = Float
type ListTuple = (Title, ItemType, Maybe String)
type Filepath = String
type Lbl = Sentence
data Contents = UlC UnlabelledContent
| LlC LabelledContent
data DType = General
| Instance
| Theory
| Data
data RawContent =
Table [Sentence] [[Sentence]] Title Bool
| Paragraph Sentence
| EqnBlock ModelExpr
| DerivBlock Sentence [RawContent]
| Enumeration ListType
| Defini DType [(Identifier, [Contents])]
| Figure Lbl Filepath MaxWidthPercent
| Bib BibRef
| Graph [(Sentence, Sentence)] (Maybe Width) (Maybe Height) Lbl
| CodeBlock CodeExpr
type Identifier = String
data LabelledContent = LblC { LabelledContent -> Reference
_ref :: Reference
, LabelledContent -> RawContent
_ctype :: RawContent
}
newtype UnlabelledContent = UnlblC { UnlabelledContent -> RawContent
_cntnts :: RawContent }
makeLenses ''LabelledContent
makeLenses ''UnlabelledContent
class HasContents c where
accessContents :: Lens' c RawContent
instance HasUID LabelledContent where uid :: Lens' LabelledContent UID
uid = Lens' LabelledContent Reference
ref forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c. HasUID c => Lens' c UID
uid
instance Eq LabelledContent where LabelledContent
a == :: LabelledContent -> LabelledContent -> Bool
== LabelledContent
b = (LabelledContent
a forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid) forall a. Eq a => a -> a -> Bool
== (LabelledContent
b forall s a. s -> Getting a s a -> a
^. forall c. HasUID c => Lens' c UID
uid)
instance HasRefAddress LabelledContent where getRefAdd :: LabelledContent -> LblType
getRefAdd (LblC Reference
lb RawContent
c) = IRefProg -> String -> LblType
RP (RawContent -> IRefProg
prependLabel RawContent
c) forall a b. (a -> b) -> a -> b
$ LblType -> String
getAdd forall a b. (a -> b) -> a -> b
$ forall b. HasRefAddress b => b -> LblType
getRefAdd Reference
lb
instance HasContents LabelledContent where accessContents :: Lens' LabelledContent RawContent
accessContents = Lens' LabelledContent RawContent
ctype
instance HasShortName LabelledContent where shortname :: LabelledContent -> ShortName
shortname = forall s. HasShortName s => s -> ShortName
shortname forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Lens' LabelledContent Reference
ref
instance HasContents UnlabelledContent where accessContents :: Lens' UnlabelledContent RawContent
accessContents = Iso' UnlabelledContent RawContent
cntnts
instance HasContents Contents where
accessContents :: Lens' Contents RawContent
accessContents RawContent -> f RawContent
f (UlC UnlabelledContent
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (UnlabelledContent -> Contents
UlC forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\RawContent
x -> forall s t a b. ASetter s t a b -> b -> s -> t
set Iso' UnlabelledContent RawContent
cntnts RawContent
x UnlabelledContent
c)) (RawContent -> f RawContent
f forall a b. (a -> b) -> a -> b
$ UnlabelledContent
c forall s a. s -> Getting a s a -> a
^. Iso' UnlabelledContent RawContent
cntnts)
accessContents RawContent -> f RawContent
f (LlC LabelledContent
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (LabelledContent -> Contents
LlC forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\RawContent
x -> forall s t a b. ASetter s t a b -> b -> s -> t
set Lens' LabelledContent RawContent
ctype RawContent
x LabelledContent
c)) (RawContent -> f RawContent
f forall a b. (a -> b) -> a -> b
$ LabelledContent
c forall s a. s -> Getting a s a -> a
^. Lens' LabelledContent RawContent
ctype)
instance Referable LabelledContent where
refAdd :: LabelledContent -> String
refAdd = LblType -> String
getAdd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall b. HasRefAddress b => b -> LblType
getRefAdd
renderRef :: LabelledContent -> LblType
renderRef = forall b. HasRefAddress b => b -> LblType
getRefAdd
prependLabel :: RawContent -> IRefProg
prependLabel :: RawContent -> IRefProg
prependLabel Table{} = String -> IRefProg
prepend String
"Tab"
prependLabel Figure{} = String -> IRefProg
prepend String
"Fig"
prependLabel Graph{} = String -> IRefProg
prepend String
"Fig"
prependLabel Defini{} = String -> IRefProg
prepend String
"Def"
prependLabel EqnBlock{} = String -> IRefProg
prepend String
"EqnB"
prependLabel CodeBlock{} = String -> IRefProg
prepend String
"CodeB"
prependLabel DerivBlock{} = String -> IRefProg
prepend String
"Deriv"
prependLabel Enumeration{} = String -> IRefProg
prepend String
"Lst"
prependLabel Paragraph{} = forall a. HasCallStack => String -> a
error String
"Shouldn't reference paragraphs"
prependLabel Bib{} = forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$
String
"Bibliography list of references cannot be referenced. " forall a. [a] -> [a] -> [a]
++
String
"You must reference the Section or an individual citation."