diff options
Diffstat (limited to 'spec/src')
| -rw-r--r-- | spec/src/Thermoprint/Printout.hs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/spec/src/Thermoprint/Printout.hs b/spec/src/Thermoprint/Printout.hs index 1106d2f..397a1af 100644 --- a/spec/src/Thermoprint/Printout.hs +++ b/spec/src/Thermoprint/Printout.hs | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | {-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} | 1 | {-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} |
| 2 | {-# LANGUAGE OverloadedStrings #-} | 2 | {-# LANGUAGE OverloadedStrings #-} |
| 3 | {-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-} | ||
| 3 | {-# OPTIONS_HADDOCK show-extensions #-} | 4 | {-# OPTIONS_HADDOCK show-extensions #-} |
| 4 | 5 | ||
| 5 | -- | This module contains the definition of the structure -- 'Printout' -- used to represent the content of a job | 6 | -- | This module contains the definition of the structure -- 'Printout' -- used to represent the content of a job |
| @@ -20,13 +21,16 @@ import Data.Sequence (Seq, (|>), (<|)) | |||
| 20 | import Data.Text.Lazy (Text) | 21 | import Data.Text.Lazy (Text) |
| 21 | 22 | ||
| 22 | import Data.ByteString.Lazy (ByteString) | 23 | import Data.ByteString.Lazy (ByteString) |
| 24 | import qualified Data.ByteString.Lazy as LBS (toStrict) | ||
| 23 | 25 | ||
| 24 | import GHC.Generics (Generic) | 26 | import GHC.Generics (Generic) |
| 25 | import Control.DeepSeq (NFData) | 27 | import Control.DeepSeq (NFData) |
| 26 | import Data.Aeson (FromJSON(..), ToJSON(..), Value(..)) | 28 | import Data.Aeson (FromJSON(..), ToJSON(..), Value(..)) |
| 27 | import qualified Data.Aeson as JSON (encode, decode) | 29 | import qualified Data.Aeson as JSON (encode, decode, eitherDecodeStrict') |
| 28 | import Data.Aeson.Types (typeMismatch) | 30 | import Data.Aeson.Types (typeMismatch) |
| 29 | 31 | ||
| 32 | import Database.Persist.Class (PersistField(..)) | ||
| 33 | |||
| 30 | import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary, genericShrink) | 34 | import Test.QuickCheck.Arbitrary (Arbitrary(..), CoArbitrary, genericShrink) |
| 31 | import Test.QuickCheck.Modifiers (NonNegative(..)) | 35 | import Test.QuickCheck.Modifiers (NonNegative(..)) |
| 32 | import Test.QuickCheck.Gen (oneof, scale) | 36 | import Test.QuickCheck.Gen (oneof, scale) |
| @@ -48,6 +52,9 @@ import Data.Function (on) | |||
| 48 | 52 | ||
| 49 | import Data.Foldable (toList, fold) | 53 | import Data.Foldable (toList, fold) |
| 50 | 54 | ||
| 55 | import Data.Bifunctor | ||
| 56 | import Control.Monad ((<=<)) | ||
| 57 | |||
| 51 | import Data.Encoding (encodeLazyByteStringExplicit, decodeLazyByteString) | 58 | import Data.Encoding (encodeLazyByteStringExplicit, decodeLazyByteString) |
| 52 | import Data.Encoding.UTF8 | 59 | import Data.Encoding.UTF8 |
| 53 | import qualified Data.ByteString.Base64.Lazy as Base64 (encode, decode) | 60 | import qualified Data.ByteString.Base64.Lazy as Base64 (encode, decode) |
| @@ -58,6 +65,10 @@ import Prelude hiding (fold) | |||
| 58 | -- | A 'Printout' is a sequence of visually seperated 'Paragraph's | 65 | -- | A 'Printout' is a sequence of visually seperated 'Paragraph's |
| 59 | type Printout = Seq Paragraph | 66 | type Printout = Seq Paragraph |
| 60 | 67 | ||
| 68 | instance PersistField Printout where | ||
| 69 | toPersistValue = toPersistValue . LBS.toStrict . JSON.encode | ||
| 70 | fromPersistValue = first T.pack . JSON.eitherDecodeStrict' <=< fromPersistValue | ||
| 71 | |||
| 61 | -- | A 'Paragraph' is a non-seperated sequence of 'Chunk's | 72 | -- | A 'Paragraph' is a non-seperated sequence of 'Chunk's |
| 62 | type Paragraph = Seq Chunk | 73 | type Paragraph = Seq Chunk |
| 63 | 74 | ||
| @@ -127,7 +138,6 @@ instance Monoid Line where | |||
| 127 | | otherwise = JuxtaPos (x <| ys) | 138 | | otherwise = JuxtaPos (x <| ys) |
| 128 | x `mappend` y = JuxtaPos $ Seq.fromList [x, y] | 139 | x `mappend` y = JuxtaPos $ Seq.fromList [x, y] |
| 129 | 140 | ||
| 130 | |||
| 131 | text :: Text -> Either Block Line | 141 | text :: Text -> Either Block Line |
| 132 | -- ^ Smart constructor for 'Line'/'Block' which maps word and line boundaries (as determined by 'isSpace' and '(== '\n')' respectively) to the structure of 'Block' and 'Line'. | 142 | -- ^ Smart constructor for 'Line'/'Block' which maps word and line boundaries (as determined by 'isSpace' and '(== '\n')' respectively) to the structure of 'Block' and 'Line'. |
| 133 | -- | 143 | -- |
