{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Diagrams.Backend.Html5.CmdLine
(
mainWith
, defaultMain
, multiMain
, Html5
, B
) where
import Diagrams.Prelude hiding (width, height, option, (<>), value, output)
import Diagrams.Backend.CmdLine
import Diagrams.Backend.Html5
import Data.List.Split (splitOn)
defaultMain :: QDiagram Html5 V2 Double Any -> IO ()
defaultMain :: QDiagram Html5 V2 Double Any -> IO ()
defaultMain = forall d. (Mainable d, Parseable (MainOpts d)) => d -> IO ()
mainWith
instance Mainable (QDiagram Html5 V2 Double Any) where
type MainOpts (QDiagram Html5 V2 Double Any) = DiagramOpts
mainRender :: MainOpts (QDiagram Html5 V2 Double Any)
-> QDiagram Html5 V2 Double Any -> IO ()
mainRender = DiagramOpts -> QDiagram Html5 V2 Double Any -> IO ()
html5Render
html5Render :: DiagramOpts -> QDiagram Html5 V2 Double Any -> IO ()
html5Render :: DiagramOpts -> QDiagram Html5 V2 Double Any -> IO ()
html5Render DiagramOpts
opts QDiagram Html5 V2 Double Any
d =
case forall a. Eq a => [a] -> [a] -> [[a]]
splitOn String
"." (DiagramOpts
optsforall s a. s -> Getting a s a -> a
^.Lens' DiagramOpts String
output) of
[String
""] -> String -> IO ()
putStrLn String
"No output file given."
[String]
ps | forall a. [a] -> a
last [String]
ps forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String
"html"] -> do
let szSpec :: SizeSpec V2 Double
szSpec = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall n. Num n => Maybe n -> Maybe n -> SizeSpec V2 n
mkSizeSpec2D (DiagramOpts
optsforall s a. s -> Getting a s a -> a
^.Lens' DiagramOpts (Maybe Int)
width) (DiagramOpts
optsforall s a. s -> Getting a s a -> a
^.Lens' DiagramOpts (Maybe Int)
height)
String
-> SizeSpec V2 Double -> QDiagram Html5 V2 Double Any -> IO ()
renderHtml5 (DiagramOpts
optsforall s a. s -> Getting a s a -> a
^.Lens' DiagramOpts String
output) SizeSpec V2 Double
szSpec QDiagram Html5 V2 Double Any
d
| Bool
otherwise -> String -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ String
"Unknown file type: " forall a. [a] -> [a] -> [a]
++ forall a. [a] -> a
last [String]
ps
multiMain :: [(String, QDiagram Html5 V2 Double Any)] -> IO ()
multiMain :: [(String, QDiagram Html5 V2 Double Any)] -> IO ()
multiMain = forall d. (Mainable d, Parseable (MainOpts d)) => d -> IO ()
mainWith
instance Mainable [(String, QDiagram Html5 V2 Double Any)] where
type MainOpts [(String, QDiagram Html5 V2 Double Any)] =
(MainOpts (QDiagram Html5 V2 Double Any), DiagramMultiOpts)
mainRender :: MainOpts [(String, QDiagram Html5 V2 Double Any)]
-> [(String, QDiagram Html5 V2 Double Any)] -> IO ()
mainRender = forall d.
Mainable d =>
(MainOpts d, DiagramMultiOpts) -> [(String, d)] -> IO ()
defaultMultiMainRender