mirror of
https://github.com/Avi-D-coder/implicit-hie.git
synced 2024-11-23 02:06:17 +03:00
Split formatting from rendering
This commit is contained in:
parent
cdccf36665
commit
7f8eb6f0f7
@ -9,38 +9,40 @@ where
|
||||
import qualified Data.Text as T
|
||||
import Hie.Cabal.Parser
|
||||
|
||||
cabalHieYaml :: Package -> T.Text
|
||||
cabalHieYaml :: Package -> String
|
||||
cabalHieYaml (Package n cs) =
|
||||
"cradle:\n"
|
||||
<> indentT ("cabal:\n" <> indentT (T.unlines (map (cabalComponent n) cs)))
|
||||
<> indent'
|
||||
("cabal:\n" <> indent' (unlines (map (fmtComponent . cabalComponent n) cs)))
|
||||
|
||||
stackHieYaml :: Package -> T.Text
|
||||
stackHieYaml :: Package -> String
|
||||
stackHieYaml (Package n cs) =
|
||||
"cradle:\n"
|
||||
<> indentT ("stack:\n" <> indentT (T.unlines (map (stackComponent n) cs)))
|
||||
<> indent'
|
||||
("stack:\n" <> indent' (unlines (map (fmtComponent . stackComponent n) cs)))
|
||||
|
||||
indentT :: T.Text -> T.Text
|
||||
indentT = T.unlines . map (" " <>) . T.lines
|
||||
indent' :: String -> String
|
||||
indent' = unlines . map (" " <>) . lines
|
||||
|
||||
cabalComponent :: Name -> Component -> T.Text
|
||||
cabalComponent n (Lib "" p) = comp p $ "lib:" <> n
|
||||
cabalComponent n (Lib cn p) = comp p $ "lib:" <> n <> ":" <> cn
|
||||
cabalComponent n (Exe cn p) = comp p $ n <> ":exe:" <> cn
|
||||
cabalComponent n (Test cn p) = comp p $ n <> ":test:" <> cn
|
||||
cabalComponent :: Name -> Component -> (FilePath, String)
|
||||
cabalComponent n (Lib "" p) = (T.unpack p, T.unpack $ "lib:" <> n)
|
||||
cabalComponent n (Lib cn p) = (T.unpack p, T.unpack $ "lib:" <> n <> ":" <> cn)
|
||||
cabalComponent n (Exe cn p) = (T.unpack p, T.unpack $ n <> ":exe:" <> cn)
|
||||
cabalComponent n (Test cn p) = (T.unpack p, T.unpack $ n <> ":test:" <> cn)
|
||||
|
||||
stackComponent :: Name -> Component -> T.Text
|
||||
stackComponent n (Lib "" p) = comp p $ n <> ":lib"
|
||||
stackComponent n (Lib cn p) = comp p $ n <> ":lib:" <> cn
|
||||
stackComponent n (Exe cn p) = comp p $ n <> ":exe:" <> cn
|
||||
stackComponent n (Test cn p) = comp p $ n <> ":test:" <> cn
|
||||
stackComponent :: Name -> Component -> (FilePath, String)
|
||||
stackComponent n (Lib "" p) = (T.unpack p, T.unpack $ n <> ":lib")
|
||||
stackComponent n (Lib cn p) = (T.unpack p, T.unpack $ n <> ":lib:" <> cn)
|
||||
stackComponent n (Exe cn p) = (T.unpack p, T.unpack $ n <> ":exe:" <> cn)
|
||||
stackComponent n (Test cn p) = (T.unpack p, T.unpack $ n <> ":test:" <> cn)
|
||||
|
||||
comp :: T.Text -> T.Text -> T.Text
|
||||
comp p c =
|
||||
fmtComponent :: (FilePath, String) -> String
|
||||
fmtComponent (p, c) =
|
||||
"- path: "
|
||||
<> dQuote p
|
||||
<> "\n "
|
||||
<> "component: "
|
||||
<> dQuote c
|
||||
|
||||
dQuote :: T.Text -> T.Text
|
||||
dQuote t = T.cons '"' t `T.snoc` '"'
|
||||
dQuote :: String -> String
|
||||
dQuote t = '"' : t <> "\""
|
||||
|
Loading…
Reference in New Issue
Block a user