Server: add Default instance for Params.
This commit is contained in:
parent
55c524e83c
commit
4dfc30ca10
2 changed files with 18 additions and 5 deletions
|
@ -799,6 +799,7 @@ executable pandoc-server
|
||||||
pandoc,
|
pandoc,
|
||||||
aeson,
|
aeson,
|
||||||
text,
|
text,
|
||||||
|
data-default,
|
||||||
bytestring,
|
bytestring,
|
||||||
base64 >= 0.4,
|
base64 >= 0.4,
|
||||||
servant-server,
|
servant-server,
|
||||||
|
|
|
@ -22,6 +22,7 @@ import Data.Maybe (fromMaybe)
|
||||||
import Data.Char (isAlphaNum)
|
import Data.Char (isAlphaNum)
|
||||||
import Data.ByteString.Lazy (fromStrict, toStrict)
|
import Data.ByteString.Lazy (fromStrict, toStrict)
|
||||||
import Data.ByteString.Base64
|
import Data.ByteString.Base64
|
||||||
|
import Data.Default
|
||||||
|
|
||||||
-- This is the data to be supplied by the JSON payload
|
-- This is the data to be supplied by the JSON payload
|
||||||
-- of requests. Maybe values may be omitted and will be
|
-- of requests. Maybe values may be omitted and will be
|
||||||
|
@ -36,6 +37,17 @@ data Params = Params
|
||||||
, template :: Maybe Text
|
, template :: Maybe Text
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
|
instance Default Params where
|
||||||
|
def = Params
|
||||||
|
{ text = ""
|
||||||
|
, from = Nothing
|
||||||
|
, to = Nothing
|
||||||
|
, wrapText = Nothing
|
||||||
|
, columns = Nothing
|
||||||
|
, standalone = Nothing
|
||||||
|
, template = Nothing
|
||||||
|
}
|
||||||
|
|
||||||
-- Automatically derive code to convert to/from JSON.
|
-- Automatically derive code to convert to/from JSON.
|
||||||
$(deriveJSON defaultOptions ''Params)
|
$(deriveJSON defaultOptions ''Params)
|
||||||
|
|
||||||
|
@ -65,10 +77,9 @@ server = convert
|
||||||
:<|> pure pandocVersion
|
:<|> pure pandocVersion
|
||||||
where
|
where
|
||||||
babelmark text' from' to' standalone' = do
|
babelmark text' from' to' standalone' = do
|
||||||
res <- convert Params{ text = text',
|
res <- convert def{ text = text',
|
||||||
from = from', to = to',
|
from = from', to = to',
|
||||||
standalone = Just standalone', wrapText = Nothing,
|
standalone = Just standalone' }
|
||||||
columns = Nothing, template = Nothing }
|
|
||||||
return $ toJSON $ object [ "html" .= res, "version" .= pandocVersion ]
|
return $ toJSON $ object [ "html" .= res, "version" .= pandocVersion ]
|
||||||
|
|
||||||
-- We use runPure for the pandoc conversions, which ensures that
|
-- We use runPure for the pandoc conversions, which ensures that
|
||||||
|
@ -98,7 +109,8 @@ server = convert
|
||||||
compileCustomTemplate toformat t
|
compileCustomTemplate toformat t
|
||||||
else return Nothing
|
else return Nothing
|
||||||
let readeropts = def{ readerExtensions = readerExts
|
let readeropts = def{ readerExtensions = readerExts
|
||||||
, readerStandalone = isStandalone }
|
, readerStandalone = isStandalone
|
||||||
|
}
|
||||||
let writeropts = def{ writerExtensions = writerExts
|
let writeropts = def{ writerExtensions = writerExts
|
||||||
, writerWrapText = fromMaybe WrapAuto (wrapText params)
|
, writerWrapText = fromMaybe WrapAuto (wrapText params)
|
||||||
, writerColumns = fromMaybe 72 (columns params)
|
, writerColumns = fromMaybe 72 (columns params)
|
||||||
|
|
Loading…
Add table
Reference in a new issue