module Language.Drasil.Markdown.CreateMd (
makeMd,
introInfo, whatInfo, verInfo, unsupOS, extLibSec, regularSec, instDoc, endNote)
where
import Prelude hiding ((<>))
import Text.PrettyPrint.HughesPJ (Doc, empty, isEmpty, vcat, text, (<+>),
(<>), punctuate, hsep)
import Language.Drasil.Printing.Helpers (upcase)
import Utils.Drasil
makeMd :: [Doc] -> Doc
makeMd :: [Doc] -> Doc
makeMd = [Doc] -> Doc
vcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> [Doc] -> [Doc]
punctuate Doc
secSep forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> [Doc]
filterEmpty
introInfo :: String -> [String] -> Maybe String -> Doc
introInfo :: String -> [String] -> Maybe String -> Doc
introInfo String
name [String]
auths Maybe String
descr = Doc -> Doc -> Int -> Doc -> Doc
introSec (String -> Doc
text String
name) ([String] -> Doc
listToDoc [String]
auths) (forall (t :: * -> *) a. Foldable t => t a -> Int
length [String]
auths) (Maybe String -> Doc
maybePurpDoc Maybe String
descr)
instDoc :: [String] -> String -> (String, String) -> Doc
instDoc :: [String] -> String -> (String, String) -> Doc
instDoc [String]
cfp String
name (String, String)
inoutn = Doc -> Doc -> Doc
regularSec (String -> Doc
text String
"Making Examples")
((String, String) -> Doc
runInstDoc (String, String)
inoutn Doc -> Doc -> Doc
<> Doc
doubleSep Doc -> Doc -> Doc
<> Doc
makeInstDoc) Doc -> Doc -> Doc
<> String -> (String, String) -> Doc
inOutFile String
name (String, String)
inoutn Doc -> Doc -> Doc
<> [String] -> Doc
configSec [String]
cfp
maybePurpDoc :: Maybe String -> Doc
maybePurpDoc :: Maybe String -> Doc
maybePurpDoc = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
empty (\String
descr-> Doc
doubleSep Doc -> Doc -> Doc
<> String -> Doc
text String
"> Purpose:" Doc -> Doc -> Doc
<+> String -> Doc
upcase String
descr)
whatInfo :: Maybe String -> Doc
whatInfo :: Maybe String -> Doc
whatInfo = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
empty (Doc -> Doc -> Doc
regularSec (String -> Doc
text String
"What") forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc
text)
commandLine :: Doc
commandLine :: Doc
commandLine = String -> Doc
text forall a b. (a -> b) -> a -> b
$ String
"In your terminal command line, enter the same directory as this " forall a. [a] -> [a] -> [a]
++
String
"README file. Then enter the following line:"
runInstDoc :: (String, String) -> Doc
runInstDoc :: (String, String) -> Doc
runInstDoc (String
inFile, String
_) = String -> Doc
text String
"How to Run the Program:" Doc -> Doc -> Doc
<> Doc
contSep Doc -> Doc -> Doc
<>
Doc
commandLine Doc -> Doc -> Doc
<> Doc
contSep Doc -> Doc -> Doc
<> Doc
bkQuote3 Doc -> Doc -> Doc
<> Doc
contSep Doc -> Doc -> Doc
<> String -> Doc
text String
"make run RUNARGS=" Doc -> Doc -> Doc
<> String -> Doc
text String
inFile
Doc -> Doc -> Doc
<> Doc
contSep Doc -> Doc -> Doc
<> Doc
bkQuote3
makeInstDoc :: Doc
makeInstDoc :: Doc
makeInstDoc = String -> Doc
text String
"How to Build the Program:" Doc -> Doc -> Doc
<> Doc
contSep Doc -> Doc -> Doc
<> Doc
commandLine Doc -> Doc -> Doc
<> Doc
contSep Doc -> Doc -> Doc
<>
Doc
bkQuote3 Doc -> Doc -> Doc
<> Doc
contSep Doc -> Doc -> Doc
<> String -> Doc
text String
"make build" Doc -> Doc -> Doc
<> Doc
contSep Doc -> Doc -> Doc
<> Doc
bkQuote3
inOutFile :: String -> (String, String) -> Doc
inOutFile :: String -> (String, String) -> Doc
inOutFile String
name (String
inFile, String
outFile) = Doc
doubleSep Doc -> Doc -> Doc
<>
String -> Doc
text String
"How to Change Input:" Doc -> Doc -> Doc
<> Doc
contSep Doc -> Doc -> Doc
<> String -> Doc
text String
name Doc -> Doc -> Doc
<+>
String -> Doc
text String
"will take the inputs from" Doc -> Doc -> Doc
<+> Doc
bkQuote Doc -> Doc -> Doc
<> String -> Doc
text String
inFile Doc -> Doc -> Doc
<> Doc
bkQuote Doc -> Doc -> Doc
<+>
String -> Doc
text String
"and write the outputs to" Doc -> Doc -> Doc
<+> Doc
bkQuote Doc -> Doc -> Doc
<> String -> Doc
text String
outFile Doc -> Doc -> Doc
<> Doc
bkQuote Doc -> Doc -> Doc
<>
String -> Doc
text String
"." Doc -> Doc -> Doc
<> Doc
contSep Doc -> Doc -> Doc
<> String -> Doc
text String
"Inputs can be changed by editing" Doc -> Doc -> Doc
<+> Doc
bkQuote Doc -> Doc -> Doc
<>
String -> Doc
text String
inFile Doc -> Doc -> Doc
<> Doc
bkQuote Doc -> Doc -> Doc
<> String -> Doc
text String
"."
configSec :: [String] -> Doc
configSec :: [String] -> Doc
configSec [] = Doc
empty
configSec [String]
cfp = Doc
doubleSep Doc -> Doc -> Doc
<> Doc -> Doc -> Doc
regularSec (String -> Doc
text String
"Configuration Files")
(String -> Doc
text (String
"Configuration files are files that must be " forall a. [a] -> [a] -> [a]
++
String
"in the same directory as the executable in order to run or build successfully.")
Doc -> Doc -> Doc
<> Doc
doubleSep Doc -> Doc -> Doc
<> Doc
bkQuote Doc -> Doc -> Doc
<> [String] -> Doc
listToDoc [String]
cfp Doc -> Doc -> Doc
<> Doc
bkQuote)
verInfo :: String -> String -> Doc
verInfo :: String -> String -> Doc
verInfo String
pl String
plv = Doc -> Doc -> Doc
regularSec (String -> Doc
text String
"Version") (Doc
bkQuote Doc -> Doc -> Doc
<> String -> Doc
text String
pl Doc -> Doc -> Doc
<+> String -> Doc
text String
plv Doc -> Doc -> Doc
<> Doc
bkQuote)
unsupOS :: Maybe String -> Doc
unsupOS :: Maybe String -> Doc
unsupOS = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
empty (\String
uns-> Doc -> Doc -> Doc
regularSec (String -> Doc
text String
"Unsupported Operating Systems")
(String -> Doc
text forall a b. (a -> b) -> a -> b
$ String
"- " forall a. [a] -> [a] -> [a]
++ String
uns))
extLibSec:: [(String, String)] -> [String]-> Doc
extLibSec :: [(String, String)] -> [String] -> Doc
extLibSec [(String, String)]
libns [String]
libfps =
let libs :: [(String, String, String)]
libs = [(String, String)] -> [String] -> [(String, String, String)]
addListToTuple [(String, String)]
libns [String]
libfps
formattedLibs :: Doc
formattedLibs = ([Doc] -> Doc
hsep forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> [Doc] -> [Doc]
punctuate Doc
contSep forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> [Doc]
filterEmpty forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall a b. (a -> b) -> [a] -> [b]
map (String, String, String) -> Doc
libStatment) [(String, String, String)]
libs
in if Doc -> Bool
isEmpty Doc
formattedLibs then Doc
empty else
Doc -> Doc -> Doc
regularSec (String -> Doc
text String
"External Libraries") Doc
formattedLibs
libStatment :: (String, String, String) -> Doc
libStatment :: (String, String, String) -> Doc
libStatment (String
"",String
"", String
_) = Doc
empty
libStatment (String
nam,String
vers, String
fp) = Doc
bkQuote Doc -> Doc -> Doc
<> String -> Doc
text String
nam Doc -> Doc -> Doc
<+>
String -> Doc
text String
vers Doc -> Doc -> Doc
<> Doc
bkQuote Doc -> Doc -> Doc
<> if String
fp forall a. Eq a => a -> a -> Bool
== String
"" then Doc
empty else
String -> Doc
text String
". The local file path to the library is" Doc -> Doc -> Doc
<+> Doc
bkQuote Doc -> Doc -> Doc
<> String -> Doc
text String
fp Doc -> Doc -> Doc
<> Doc
bkQuote
addListToTuple :: [(String,String)] -> [String] -> [(String, String, String)]
addListToTuple :: [(String, String)] -> [String] -> [(String, String, String)]
addListToTuple [] [] = []
addListToTuple ((String
n,String
v):[(String, String)]
_) [] = [(String
n,String
v,String
"")]
addListToTuple ((String
n,String
v):[(String, String)]
xtup) (String
l:[String]
xlst) = (String
n,String
v,String
l)forall a. a -> [a] -> [a]
:[(String, String)] -> [String] -> [(String, String, String)]
addListToTuple [(String, String)]
xtup [String]
xlst
addListToTuple [(String, String)]
_ [String]
_ = []
license :: Doc -> Doc
license :: Doc -> Doc
license Doc
auth = String -> Doc
text String
"Copyright (c) 2021," Doc -> Doc -> Doc
<+> Doc
auth Doc -> Doc -> Doc
<>
String -> Doc
text String
". All rights reserved. Please see the [full license](https://github.com/JacquesCarette/Drasil/blob/4b9ad0a3016fecb3c7a2aa82ab142f9e805b5cc8/LICENSE) for more details."
endNote :: Int -> [String] -> Doc
endNote :: Int -> [String] -> Doc
endNote Int
num [String]
auth = String -> Doc
text String
"*This README is a software artifact generated by Drasil.*"
Doc -> Doc -> Doc
<> Doc
doubleSep Doc -> Doc -> Doc
<> Doc -> Doc
license ([String] -> Doc
listToDoc [String]
auth) Doc -> Doc -> Doc
<> Doc
doubleSep Doc -> Doc -> Doc
<>
Int -> Doc
drasilImage Int
num
secSep, doubleSep, bkQuote, bkQuote3 :: Separator
secSep :: Doc
secSep = String -> Doc
text String
"\n\n------------------------------------------------------------"
doubleSep :: Doc
doubleSep = String -> Doc
text String
"\n\n"
bkQuote :: Doc
bkQuote = String -> Doc
text String
"`"
bkQuote3 :: Doc
bkQuote3 = String -> Doc
text String
"```"
introSec :: Doc -> Doc -> Int -> Doc -> Doc
introSec :: Doc -> Doc -> Int -> Doc -> Doc
introSec Doc
hd Doc
ms1 Int
l Doc
descr = String -> Doc
text String
"#" Doc -> Doc -> Doc
<+> Doc
hd Doc -> Doc -> Doc
<+> Doc
contSep Doc -> Doc -> Doc
<> (if Int
l forall a. Eq a => a -> a -> Bool
== Int
1 then String -> Doc
text String
"> Author:" else String -> Doc
text String
"> Authors: ")
Doc -> Doc -> Doc
<+> Doc
ms1 Doc -> Doc -> Doc
<> Doc
descr
regularSec :: Doc -> Doc -> Doc
regularSec :: Doc -> Doc -> Doc
regularSec Doc
hd Doc
ms = String -> Doc
text String
"##" Doc -> Doc -> Doc
<+> Doc
hd Doc -> Doc -> Doc
<+> Doc
contSep Doc -> Doc -> Doc
<+> Doc
ms
buildPath :: Int -> String
buildPath :: Int -> String
buildPath Int
num = forall a. (a -> Bool) -> [a] -> [a]
filter (forall a. Eq a => a -> a -> Bool
/= Char
' ') forall a b. (a -> b) -> a -> b
$ [String] -> String
unwords forall a b. (a -> b) -> a -> b
$ forall a. Int -> a -> [a]
replicate Int
num String
"../"
drasilImage :: Int -> Doc
drasilImage :: Int -> Doc
drasilImage Int
num = String -> Doc
alignImage (Int -> String
buildPath Int
num forall a. [a] -> [a] -> [a]
++
String
"drasil-website/WebInfo/images/Icon.png")
alignImage :: FilePath -> Doc
alignImage :: String -> Doc
alignImage String
img = String -> Doc
text String
"<p align=\"center\">" Doc -> Doc -> Doc
<> Doc
contSep Doc -> Doc -> Doc
<> String -> Doc
text (String
"<img src=\""
forall a. [a] -> [a] -> [a]
++ String
img forall a. [a] -> [a] -> [a]
++ String
"\" alt=\"Drasil Tree\" width=\"200\" />") Doc -> Doc -> Doc
<> Doc
contSep Doc -> Doc -> Doc
<> String -> Doc
text String
"</p>"