module Language.Drasil.Output.Formats where
import Data.Char (toLower)
import Build.Drasil ((+:+), Command, makeS, mkCheckedCommand, mkCommand, mkFreeVar,
mkFile, mkRule, RuleTransformer(makeRule))
import Language.Drasil.Printers (DocType(..), Format(TeX, MDBook))
import Metadata.Drasil.DrasilMetaCall (watermark)
type Filename = String
data DocChoices = DC {
DocChoices -> DocType
doctype :: DocType,
DocChoices -> [Format]
format :: [Format]
}
data DocSpec = DocSpec DocChoices Filename
instance RuleTransformer DocSpec where
makeRule :: DocSpec -> [Rule]
makeRule (DocSpec (DC DocType
dt [Format
TeX]) Filename
fn) = [
Annotation -> Target -> Dependencies -> [Command] -> Rule
mkRule [Filename
watermark] (Filename -> Target
makeS (Filename -> Target) -> Filename -> Target
forall a b. (a -> b) -> a -> b
$ (Char -> Char) -> Filename -> Filename
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower (Filename -> Filename) -> Filename -> Filename
forall a b. (a -> b) -> a -> b
$ DocType -> Filename
forall a. Show a => a -> Filename
show DocType
dt) [Target
pdfName] [],
Annotation -> Target -> Dependencies -> [Command] -> Rule
mkFile [] Target
pdfName [Filename -> Target
makeS (Filename -> Target) -> Filename -> Target
forall a b. (a -> b) -> a -> b
$ Filename
fn Filename -> Filename -> Filename
forall a. [a] -> [a] -> [a]
++ Filename
".tex"] ([Command] -> Rule) -> [Command] -> Rule
forall a b. (a -> b) -> a -> b
$
((Filename -> Command) -> Command)
-> [Filename -> Command] -> [Command]
forall a b. (a -> b) -> [a] -> [b]
map ((Filename -> Command) -> Filename -> Command
forall a b. (a -> b) -> a -> b
$ Filename
fn) [Filename -> Command
lualatex, Filename -> Command
bibtex, Filename -> Command
lualatex, Filename -> Command
lualatex]] where
lualatex, bibtex :: String -> Command
lualatex :: Filename -> Command
lualatex = Target -> Command
mkCheckedCommand (Target -> Command) -> (Filename -> Target) -> Filename -> Command
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Target -> Target -> Target
(+:+) (Filename -> Target
makeS Filename
"lualatex" Target -> Target -> Target
+:+ Filename -> Target
mkFreeVar Filename
"TEXFLAGS") (Target -> Target) -> (Filename -> Target) -> Filename -> Target
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Filename -> Target
makeS
bibtex :: Filename -> Command
bibtex = Target -> Command
mkCommand (Target -> Command) -> (Filename -> Target) -> Filename -> Command
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Target -> Target -> Target
(+:+) (Filename -> Target
makeS Filename
"bibtex" Target -> Target -> Target
+:+ Filename -> Target
mkFreeVar Filename
"BIBTEXFLAGS") (Target -> Target) -> (Filename -> Target) -> Filename -> Target
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Filename -> Target
makeS
pdfName :: Target
pdfName = Filename -> Target
makeS (Filename -> Target) -> Filename -> Target
forall a b. (a -> b) -> a -> b
$ Filename
fn Filename -> Filename -> Filename
forall a. [a] -> [a] -> [a]
++ Filename
".pdf"
makeRule (DocSpec (DC DocType
_ [Format
MDBook]) Filename
_) = [
Annotation -> Target -> Dependencies -> [Command] -> Rule
mkRule [Filename
watermark] (Filename -> Target
makeS Filename
"build") [] [Command
build],
Annotation -> Target -> Dependencies -> [Command] -> Rule
mkRule [] (Filename -> Target
makeS Filename
"server") [] [Command
server]]
where
build :: Command
build = Target -> Command
mkCheckedCommand (Target -> Command) -> Target -> Command
forall a b. (a -> b) -> a -> b
$ Filename -> Target
makeS Filename
"mdbook build"
server :: Command
server = Target -> Command
mkCheckedCommand (Target -> Command) -> Target -> Command
forall a b. (a -> b) -> a -> b
$ Filename -> Target
makeS Filename
"mdbook serve --open"
makeRule DocSpec
_ = []
data DocClass = DocClass (Maybe String) String
newtype UsePackages = UsePackages [String]
data ExDoc = ExDoc (Maybe String) String