{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NoImplicitPrelude #-}

-- |

-- Module      : $header$

-- Copyright   : (c) Laurent P René de Cotret, 2019 - present

-- License     : GNU GPL, version 2 or above

-- Maintainer  : laurent.decotret@outlook.com

-- Stability   : internal

-- Portability : portable

--

-- Rendering Asymptote plots code blocks

module Text.Pandoc.Filter.Plot.Renderers.Asymptote
  ( asymptote,
    asymptoteSupportedSaveFormats,
  )
where

import Text.Pandoc.Filter.Plot.Renderers.Prelude
import Data.Char(toLower)

asymptote :: PlotM Renderer
asymptote :: PlotM Renderer
asymptote = do
  Text
cmdargs <- forall a. (Configuration -> a) -> PlotM a
asksConfig Configuration -> Text
asyCmdArgs
  forall (m :: * -> *) a. Monad m => a -> m a
return
    forall a b. (a -> b) -> a -> b
$ Renderer
      { rendererToolkit :: Toolkit
rendererToolkit = Toolkit
Asymptote,
        rendererCapture :: FigureSpec -> FilePath -> Text
rendererCapture = FigureSpec -> FilePath -> Text
asymptoteCapture,
        rendererCommand :: OutputSpec -> Text
rendererCommand = Text -> OutputSpec -> Text
asymptoteCommand Text
cmdargs,
        rendererAvailability :: AvailabilityCheck
rendererAvailability = (Executable -> Text) -> AvailabilityCheck
CommandSuccess forall a b. (a -> b) -> a -> b
$ \Executable
exe -> [st|#{pathToExe exe} -environment|],
        rendererSupportedSaveFormats :: [SaveFormat]
rendererSupportedSaveFormats = [SaveFormat]
asymptoteSupportedSaveFormats,
        rendererChecks :: [Text -> CheckResult]
rendererChecks = forall a. Monoid a => a
mempty,
        rendererLanguage :: Text
rendererLanguage = Text
"asy",
        rendererComment :: Text -> Text
rendererComment = forall a. Monoid a => a -> a -> a
mappend Text
"// ",
        rendererScriptExtension :: FilePath
rendererScriptExtension = FilePath
".asy"
      }

asymptoteSupportedSaveFormats :: [SaveFormat]
asymptoteSupportedSaveFormats :: [SaveFormat]
asymptoteSupportedSaveFormats = [SaveFormat
PDF, SaveFormat
EPS, SaveFormat
PNG]

asymptoteCommand :: Text -> OutputSpec -> Text
asymptoteCommand :: Text -> OutputSpec -> Text
asymptoteCommand Text
cmdArgs OutputSpec {FilePath
FigureSpec
Executable
oCWD :: OutputSpec -> FilePath
oExecutable :: OutputSpec -> Executable
oFigurePath :: OutputSpec -> FilePath
oScriptPath :: OutputSpec -> FilePath
oFigureSpec :: OutputSpec -> FigureSpec
oCWD :: FilePath
oExecutable :: Executable
oFigurePath :: FilePath
oScriptPath :: FilePath
oFigureSpec :: FigureSpec
..} =
  [st|#{pathToExe oExecutable} #{cmdArgs} -f #{toLower <$> show (saveFormat oFigureSpec)} -o "#{oFigurePath}" "#{oScriptPath}"|]

-- Asymptote export is entirely based on command-line arguments

-- so there is no need to modify the script itself.

asymptoteCapture :: FigureSpec -> FilePath -> Script
asymptoteCapture :: FigureSpec -> FilePath -> Text
asymptoteCapture FigureSpec {Bool
Int
FilePath
[FilePath]
[(Text, Text)]
Attr
Text
Renderer
SaveFormat
Executable
blockAttrs :: FigureSpec -> Attr
extraAttrs :: FigureSpec -> [(Text, Text)]
dependencies :: FigureSpec -> [FilePath]
dpi :: FigureSpec -> Int
directory :: FigureSpec -> FilePath
script :: FigureSpec -> Text
withSource :: FigureSpec -> Bool
caption :: FigureSpec -> Text
fsExecutable :: FigureSpec -> Executable
renderer_ :: FigureSpec -> Renderer
blockAttrs :: Attr
extraAttrs :: [(Text, Text)]
dependencies :: [FilePath]
dpi :: Int
directory :: FilePath
saveFormat :: SaveFormat
script :: Text
withSource :: Bool
caption :: Text
fsExecutable :: Executable
renderer_ :: Renderer
saveFormat :: FigureSpec -> SaveFormat
..} FilePath
_ = Text
script