{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Kerry.Engine (
Template (..)
, RawTemplate
, toTemplate
, renderRawTemplate
, user
, templateVariable
, buildName
, buildType
, env
, isotime
, lower
, pwd
, sed
, split
, templateDir
, timestamp
, uuid
, upper
, packerVersion
, cleanResourceName
) where
import qualified Data.Text as T
import Kerry.Internal.Prelude
newtype Template =
Template {
renderTemplate :: Text
} deriving (Eq, Ord, Show)
newtype RawTemplate =
RawTemplate {
_rawTemplate :: Text
} deriving (Eq, Ord, Show)
toTemplate :: RawTemplate -> Template
toTemplate (RawTemplate raw) =
Template $ "{{" <> raw <> "}}"
renderRawTemplate :: RawTemplate -> Text
renderRawTemplate =
renderTemplate . toTemplate
user :: Text -> RawTemplate
user variable =
RawTemplate $ " user `" <> variable <> "` "
templateVariable :: Text -> Template
templateVariable variable =
Template $ "{{." <> variable <> "}}"
buildName :: RawTemplate
buildName =
RawTemplate "build_name"
buildType :: RawTemplate
buildType =
RawTemplate "build_type"
env :: Text -> RawTemplate
env variable =
RawTemplate $ "env `" <> variable <> "`"
isotime :: Text -> RawTemplate
isotime format =
RawTemplate $ "isotime " <> format
lower :: RawTemplate
lower =
RawTemplate "lower"
pwd :: RawTemplate
pwd =
RawTemplate "pwd"
sed :: Text -> Text -> RawTemplate
sed a b =
RawTemplate $ "sed " <> a <> " " <> b <> ""
split :: Text -> Text -> Int -> RawTemplate
split a b c =
RawTemplate $ "split " <> a <> " " <> b <> " " <> (T.pack $ show c) <> ""
templateDir :: RawTemplate
templateDir =
RawTemplate "template_dir"
timestamp :: RawTemplate
timestamp =
RawTemplate "timestamp"
uuid :: RawTemplate
uuid =
RawTemplate "uuid"
upper :: RawTemplate
upper =
RawTemplate "upper"
packerVersion :: RawTemplate
packerVersion =
RawTemplate "packer_version"
cleanResourceName :: RawTemplate
cleanResourceName =
RawTemplate "clean_resource_name"