{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeApplications #-}
module Headroom.Embedded.TH
( embedConfigFile
, embedDefaultConfig
, embedTemplate
)
where
import Data.FileEmbed ( embedStringFile )
import Headroom.Configuration.Types ( LicenseType(..) )
import Headroom.Data.EnumExtra ( EnumExtra(..) )
import Headroom.FileType.Types ( FileType(..) )
import Headroom.Meta ( TemplateType )
import Headroom.Template ( Template(..) )
import Language.Haskell.TH.Syntax ( Exp
, Q
)
import RIO
import qualified RIO.NonEmpty as NE
import qualified RIO.Text as T
embedConfigFile :: Q Exp
embedConfigFile = embedStringFile "embedded/config-file.yaml"
embedDefaultConfig :: Q Exp
embedDefaultConfig = embedStringFile "embedded/default-config.yaml"
embedTemplate :: LicenseType
-> FileType
-> Q Exp
embedTemplate lt ft = (embedStringFile . mconcat)
["embedded/license/", toStringLC lt, "/", toStringLC ft, ".", ext]
where ext = T.unpack . NE.head $ templateExtensions @TemplateType
toStringLC :: EnumExtra a => a -> String
toStringLC = T.unpack . T.toLower . enumToText