mirror of
https://github.com/scarf-sh/tie.git
synced 2024-11-22 10:31:56 +03:00
Merge pull request #58 from scarf-sh/embed-templates
embed templates into the build
This commit is contained in:
commit
588cadee5a
@ -1,20 +1,22 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
|
||||||
module Tie.Codegen.Request (codegenRequestAuxFile) where
|
module Tie.Codegen.Request (codegenRequestAuxFile) where
|
||||||
|
|
||||||
import qualified Data.ByteString as ByteString
|
import qualified Data.ByteString as ByteString
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
import Paths_tie (getDataFileName)
|
import Data.FileEmbed (embedStringFile, makeRelativeToProject)
|
||||||
import Prettyprinter (Doc, hsep, vsep)
|
import Prettyprinter (Doc, hsep, vsep)
|
||||||
import qualified Prettyprinter.Util as Prettyprinter
|
import qualified Prettyprinter.Util as Prettyprinter
|
||||||
import System.IO.Unsafe (unsafePerformIO)
|
import System.IO.Unsafe (unsafePerformIO)
|
||||||
import Tie.Name (Name)
|
import Tie.Name (Name)
|
||||||
|
|
||||||
|
templateContents :: ByteString
|
||||||
|
templateContents = $(embedStringFile =<< makeRelativeToProject "Request.template.hs")
|
||||||
|
|
||||||
auxTemplate :: Text
|
auxTemplate :: Text
|
||||||
auxTemplate = unsafePerformIO $ do
|
auxTemplate = decodeUtf8 templateContents
|
||||||
file <- getDataFileName "Request.template.hs"
|
|
||||||
contents <- ByteString.readFile file
|
|
||||||
pure (decodeUtf8 contents)
|
|
||||||
{-# NOINLINE auxTemplate #-}
|
{-# NOINLINE auxTemplate #-}
|
||||||
|
|
||||||
codegenRequestAuxFile ::
|
codegenRequestAuxFile ::
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE RecordWildCards #-}
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
{-# LANGUAGE TypeApplications #-}
|
{-# LANGUAGE TypeApplications #-}
|
||||||
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
|
||||||
module Tie.Codegen.Response
|
module Tie.Codegen.Response
|
||||||
( codegenResponses,
|
( codegenResponses,
|
||||||
@ -13,7 +14,7 @@ import qualified Data.ByteString as ByteString
|
|||||||
import Data.List (lookup)
|
import Data.List (lookup)
|
||||||
import qualified Data.Text as Text
|
import qualified Data.Text as Text
|
||||||
import Network.HTTP.Media (renderHeader)
|
import Network.HTTP.Media (renderHeader)
|
||||||
import Paths_tie (getDataFileName)
|
import Data.FileEmbed (embedStringFile, makeRelativeToProject)
|
||||||
import Prettyprinter (Doc, (<+>))
|
import Prettyprinter (Doc, (<+>))
|
||||||
import qualified Prettyprinter as PP
|
import qualified Prettyprinter as PP
|
||||||
import qualified Prettyprinter.Render.Text as PP
|
import qualified Prettyprinter.Render.Text as PP
|
||||||
@ -313,11 +314,11 @@ codegenToResponses responseModuleName operationName responses defaultResponse =
|
|||||||
)
|
)
|
||||||
in decl
|
in decl
|
||||||
|
|
||||||
|
templateContents :: ByteString
|
||||||
|
templateContents = $(embedStringFile =<< makeRelativeToProject "Response.template.hs")
|
||||||
|
|
||||||
auxTemplate :: Text
|
auxTemplate :: Text
|
||||||
auxTemplate = unsafePerformIO $ do
|
auxTemplate = decodeUtf8 templateContents
|
||||||
file <- getDataFileName "Response.template.hs"
|
|
||||||
contents <- ByteString.readFile file
|
|
||||||
pure (decodeUtf8 contents)
|
|
||||||
{-# NOINLINE auxTemplate #-}
|
{-# NOINLINE auxTemplate #-}
|
||||||
|
|
||||||
codegenResponseAuxFile ::
|
codegenResponseAuxFile ::
|
||||||
|
@ -13,12 +13,10 @@ author: Alex Biehl (alex@scarf.sh)
|
|||||||
maintainer: alex@scarf.sh, engineering@scarf.sh
|
maintainer: alex@scarf.sh, engineering@scarf.sh
|
||||||
copyright: (c) 2022 Scarf Systems
|
copyright: (c) 2022 Scarf Systems
|
||||||
category:
|
category:
|
||||||
extra-source-files: CHANGELOG.md
|
extra-source-files:
|
||||||
data-files:
|
CHANGELOG.md
|
||||||
Response.template.hs
|
Response.template.hs
|
||||||
Request.template.hs
|
Request.template.hs
|
||||||
test/golden/**/*.out
|
|
||||||
test/golden/**/*.yaml
|
|
||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
@ -48,6 +46,7 @@ library
|
|||||||
, containers
|
, containers
|
||||||
, directory
|
, directory
|
||||||
, filepath
|
, filepath
|
||||||
|
, file-embed
|
||||||
, http-media
|
, http-media
|
||||||
, insert-ordered-containers
|
, insert-ordered-containers
|
||||||
, lens
|
, lens
|
||||||
@ -99,6 +98,7 @@ test-suite tie-tests
|
|||||||
, bytestring
|
, bytestring
|
||||||
, containers
|
, containers
|
||||||
, filepath
|
, filepath
|
||||||
|
, file-embed
|
||||||
, hspec
|
, hspec
|
||||||
, insert-ordered-containers
|
, insert-ordered-containers
|
||||||
, openapi3
|
, openapi3
|
||||||
|
Loading…
Reference in New Issue
Block a user