aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/src/Thermoprint/Printout.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/src/Thermoprint/Printout.hs b/spec/src/Thermoprint/Printout.hs
index 89be802..aae71aa 100644
--- a/spec/src/Thermoprint/Printout.hs
+++ b/spec/src/Thermoprint/Printout.hs
@@ -52,6 +52,7 @@ import Data.Monoid (Monoid(..), (<>))
52import Data.List (dropWhile, dropWhileEnd, groupBy, genericLength, genericReplicate) 52import Data.List (dropWhile, dropWhileEnd, groupBy, genericLength, genericReplicate)
53 53
54import Data.Sequence as Seq (fromList, null, singleton) 54import Data.Sequence as Seq (fromList, null, singleton)
55import Data.Sequence (ViewL(..), viewl)
55 56
56import Data.Function (on) 57import Data.Function (on)
57 58
@@ -80,6 +81,18 @@ instance PersistFieldSql Printout where
80-- | A 'Paragraph' is a non-seperated sequence of 'Chunk's 81-- | A 'Paragraph' is a non-seperated sequence of 'Chunk's
81type Paragraph = Seq Chunk 82type Paragraph = Seq Chunk
82 83
84instance FromJSON Paragraph where
85 parseJSON o@(Array _) = Seq.fromList <$> parseJSON o
86 parseJSON o@(Object _) = Seq.singleton <$> parseJSON o
87 parseJSON o@(String _) = Seq.singleton <$> parseJSON o
88 parseJSON v = typeMismatch "Paragraph" v
89
90instance ToJSON Paragraph where
91 toJSON cs
92 | (a :< as) <- viewl cs
93 , Seq.null as = toJSON a
94 | otherwise = toJSON $ toList cs
95
83-- | We introduce both 'Chunk' and 'Paragraph' mainly to allow 'Raw'. 96-- | We introduce both 'Chunk' and 'Paragraph' mainly to allow 'Raw'.
84-- 97--
85-- Were we to disallow 'Raw', 'Block' would be identical to 'Paragraph' 98-- Were we to disallow 'Raw', 'Block' would be identical to 'Paragraph'