-- | Standard code to make a table of units.
-- First true example of a (small) recipe.
module Drasil.Sections.TableOfUnits (tOfUnitDesc, tOfUnitSIName, unitTableRef, tunit, tunit', tuIntro, defaultTUI) where

import Control.Lens ((^.))
import Language.Drasil
import Data.Drasil.Concepts.Documentation (symbol_, description, tOfUnit)
import Drasil.DocumentLanguage.Core (TUIntro(..), RefTab(..))

-- | Creates the Table of Units with an "SI Name" column.
tOfUnitSIName :: IsUnit s => [s] -> LabelledContent
tOfUnitSIName :: [s] -> LabelledContent
tOfUnitSIName = [Sentence] -> [s -> Sentence] -> [s] -> LabelledContent
forall s. [Sentence] -> [s -> Sentence] -> [s] -> LabelledContent
tOfUnitHelper [NamedChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
atStart NamedChunk
symbol_, NamedChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
atStart NamedChunk
description, String -> Sentence
S "SI Name"]
                  [USymb -> Sentence
Sy (USymb -> Sentence) -> (s -> USymb) -> s -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> USymb
forall u. HasUnitSymbol u => u -> USymb
usymb, (s -> Getting Sentence s Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence s Sentence
forall c. Definition c => Lens' c Sentence
defn), s -> Sentence
forall n. (HasUID n, NamedIdea n) => n -> Sentence
phrase]

-- | Creates the Table of Units with SI name in the "Description" column.
tOfUnitDesc :: IsUnit s => [s] -> LabelledContent
tOfUnitDesc :: [s] -> LabelledContent
tOfUnitDesc = [Sentence] -> [s -> Sentence] -> [s] -> LabelledContent
forall s. [Sentence] -> [s -> Sentence] -> [s] -> LabelledContent
tOfUnitHelper [NamedChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
atStart NamedChunk
symbol_, NamedChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
atStart NamedChunk
description]
                 [USymb -> Sentence
Sy (USymb -> Sentence) -> (s -> USymb) -> s -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s -> USymb
forall u. HasUnitSymbol u => u -> USymb
usymb, \x :: s
x -> (s
x s -> Getting Sentence s Sentence -> Sentence
forall s a. s -> Getting a s a -> a
^. Getting Sentence s Sentence
forall c. Definition c => Lens' c Sentence
defn) Sentence -> Sentence -> Sentence
+:+ Sentence -> Sentence
sParen (s -> Sentence
forall n. (HasUID n, NamedIdea n) => n -> Sentence
phrase s
x)]

-- | Helper for making a Table of Units.
tOfUnitHelper :: [Sentence] -> [s -> Sentence] -> [s] -> LabelledContent
tOfUnitHelper :: [Sentence] -> [s -> Sentence] -> [s] -> LabelledContent
tOfUnitHelper headers :: [Sentence]
headers fs :: [s -> Sentence]
fs u :: [s]
u = Reference -> RawContent -> LabelledContent
llcc Reference
unitTableRef (RawContent -> LabelledContent) -> RawContent -> LabelledContent
forall a b. (a -> b) -> a -> b
$ [Sentence] -> [[Sentence]] -> Sentence -> Bool -> RawContent
Table [Sentence]
headers
  ([s -> Sentence] -> [s] -> [[Sentence]]
forall a b. [a -> b] -> [a] -> [[b]]
mkTable [s -> Sentence]
fs [s]
u) (String -> Sentence
S "Table of Units") Bool
True

-- | Makes a reference to the Table of Units.
unitTableRef :: Reference
unitTableRef :: Reference
unitTableRef = String -> Reference
makeTabRef "ToU"

----- Table of units section helper functions -----

-- | Table of units constructors.
tunit, tunit' :: [TUIntro] -> RefTab
-- | Table of units with an SI Name.
tunit :: [TUIntro] -> RefTab
tunit  t :: [TUIntro]
t = [TUIntro] -> ([UnitDefn] -> LabelledContent) -> RefTab
TUnits' [TUIntro]
t [UnitDefn] -> LabelledContent
forall s. IsUnit s => [s] -> LabelledContent
tOfUnitSIName
-- | Table of units with SI name in the description column.
tunit' :: [TUIntro] -> RefTab
tunit' t :: [TUIntro]
t = [TUIntro] -> ([UnitDefn] -> LabelledContent) -> RefTab
TUnits' [TUIntro]
t [UnitDefn] -> LabelledContent
forall s. IsUnit s => [s] -> LabelledContent
tOfUnitDesc

-- | Table of units introduction builder. Used by 'mkRefSec'.
tuIntro :: [TUIntro] -> Contents
tuIntro :: [TUIntro] -> Contents
tuIntro x :: [TUIntro]
x = Sentence -> Contents
mkParagraph (Sentence -> Contents) -> Sentence -> Contents
forall a b. (a -> b) -> a -> b
$ (TUIntro -> Sentence -> Sentence)
-> Sentence -> [TUIntro] -> Sentence
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Sentence -> Sentence -> Sentence
(+:+) (Sentence -> Sentence -> Sentence)
-> (TUIntro -> Sentence) -> TUIntro -> Sentence -> Sentence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TUIntro -> Sentence
tuI) Sentence
EmptyS [TUIntro]
x

-- | Table of units introduction writer. Translates a 'TUIntro' to a 'Sentence'.
tuI :: TUIntro -> Sentence
tuI :: TUIntro -> Sentence
tuI System  = 
  String -> Sentence
S "The unit system used throughout is SI (Système International d'Unités)."
tuI TUPurpose = 
  String -> Sentence
S "For each unit" Sentence -> Sentence -> Sentence
`sC` String -> Sentence
S "the" Sentence -> Sentence -> Sentence
+:+ Reference -> Sentence -> Sentence
forall r.
(HasUID r, HasRefAddress r, HasShortName r) =>
r -> Sentence -> Sentence
namedRef Reference
unitTableRef (NamedChunk -> Sentence
forall n. NamedIdea n => n -> Sentence
titleize' NamedChunk
tOfUnit) Sentence -> Sentence -> Sentence
+:+. String -> Sentence
S "lists the symbol, a description and the SI name"
tuI Derived = 
  String -> Sentence
S "In addition to the basic units, several derived units are also used."

-- | Default table of units intro that contains the system, derivation, and purpose.
defaultTUI :: [TUIntro]
defaultTUI :: [TUIntro]
defaultTUI = [TUIntro
System, TUIntro
Derived, TUIntro
TUPurpose]