module Data.Hoodle.Generic where
import Control.Category
import Control.Lens
import Data.ByteString.Char8 hiding (map,zip)
import Data.Foldable
import Data.Functor
import qualified Data.IntMap as IM
import qualified Data.Sequence as Seq
import Data.UUID.V4
import Data.Hoodle.Simple
import Prelude hiding ((.),id)
data GHoodle cntnr pg = GHoodle
{ ghoodle_id :: ByteString
, ghoodle_ttl :: ByteString
, ghoodle_embeddedpdf :: Maybe ByteString
, ghoodle_pgs :: cntnr pg }
data GPage bkg cntnr lyr = GPage
{ gpage_dim :: Dimension
, gpage_bkg :: bkg
, gpage_lyrs :: cntnr lyr }
data GLayer buf cntnr itm = GLayer
{ glayer_buf :: buf
, glayer_itms :: cntnr itm
}
instance (Functor cntnr) => Functor (GLayer buf cntnr) where
fmap f (GLayer buf itms) = GLayer buf (fmap f itms)
instance (Functor cntnr) => Functor (GPage bkg cntnr) where
fmap f (GPage dim bkg lyrs) = GPage dim bkg (fmap f lyrs)
instance (Functor cntnr) => Functor (GHoodle cntnr) where
fmap f (GHoodle hid ttl pdf pgs) = GHoodle hid ttl pdf (fmap f pgs)
ghoodleID :: Simple Lens (GHoodle cntnr pg) ByteString
ghoodleID = lens ghoodle_id (\f a -> f { ghoodle_id = a } )
gtitle :: Simple Lens (GHoodle cntnr pg) ByteString
gtitle = lens ghoodle_ttl (\f a -> f { ghoodle_ttl = a } )
gembeddedpdf :: Simple Lens (GHoodle cntnr pg) (Maybe ByteString)
gembeddedpdf = lens ghoodle_embeddedpdf (\f a -> f { ghoodle_embeddedpdf = a } )
gpages :: Simple Lens (GHoodle cntnr pg) (cntnr pg)
gpages = lens ghoodle_pgs (\f a -> f { ghoodle_pgs = a } )
gdimension :: Simple Lens (GPage bkg cntnr pg) Dimension
gdimension = lens gpage_dim (\f a -> f { gpage_dim = a } )
gbackground :: Simple Lens (GPage bkg cntnr lyr) bkg
gbackground = lens gpage_bkg (\f a -> f { gpage_bkg = a } )
glayers :: Simple Lens (GPage bkg cntnr lyr) (cntnr lyr)
glayers = lens gpage_lyrs (\f a -> f { gpage_lyrs = a } )
gitems :: Simple Lens (GLayer buf cntnr itm) (cntnr itm)
gitems = lens glayer_itms (\f a -> f { glayer_itms = a } )
gbuffer :: Simple Lens (GLayer buf cntnr itm) buf
gbuffer = lens glayer_buf (\f a -> f { glayer_buf = a } )
class (Foldable s) => Listable s where
fromList :: [a] -> s a
instance Listable [] where
fromList = id
instance Listable IM.IntMap where
fromList = IM.fromList . zip [0..]
instance Listable Seq.Seq where
fromList = Seq.fromList
emptyGHoodle :: (Listable m) => IO (GHoodle m a)
emptyGHoodle = do
uuid <- nextRandom
return $ GHoodle ((pack.show) uuid) "" Nothing (fromList [])
emptyGPage :: (Listable cntnr) => Dimension -> bkg -> GPage bkg cntnr a
emptyGPage dim bkg = GPage dim bkg (fromList [])