diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-15 02:53:12 +0000 |
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2016-01-15 02:53:12 +0000 |
| commit | a39c0ae45bf3485fbcb080576f8089ead05a94af (patch) | |
| tree | 671f7209e8cb2e2c84fe38283316799cff4ae639 /spec | |
| parent | 98ad4fe1c478aa7135a3085b8c0937ce08638843 (diff) | |
| download | thermoprint-a39c0ae45bf3485fbcb080576f8089ead05a94af.tar thermoprint-a39c0ae45bf3485fbcb080576f8089ead05a94af.tar.gz thermoprint-a39c0ae45bf3485fbcb080576f8089ead05a94af.tar.bz2 thermoprint-a39c0ae45bf3485fbcb080576f8089ead05a94af.tar.xz thermoprint-a39c0ae45bf3485fbcb080576f8089ead05a94af.zip | |
More framework for DomTree -> Printout
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/src/Thermoprint/Printout/BBCode.hs | 26 | ||||
| -rw-r--r-- | spec/thermoprint-spec.cabal | 1 | ||||
| -rw-r--r-- | spec/thermoprint-spec.nix | 9 |
3 files changed, 30 insertions, 6 deletions
diff --git a/spec/src/Thermoprint/Printout/BBCode.hs b/spec/src/Thermoprint/Printout/BBCode.hs index ca69efc..f80f780 100644 --- a/spec/src/Thermoprint/Printout/BBCode.hs +++ b/spec/src/Thermoprint/Printout/BBCode.hs | |||
| @@ -9,7 +9,13 @@ module Thermoprint.Printout.BBCode | |||
| 9 | ) where | 9 | ) where |
| 10 | 10 | ||
| 11 | import Data.Text (Text) | 11 | import Data.Text (Text) |
| 12 | import qualified Data.Text as T () | 12 | import qualified Data.Text as T (unpack) |
| 13 | |||
| 14 | import Data.Map (Map) | ||
| 15 | import qualified Data.Map as Map (lookup) | ||
| 16 | |||
| 17 | import Data.CaseInsensitive (CI) | ||
| 18 | import qualified Data.CaseInsensitive as CI | ||
| 13 | 19 | ||
| 14 | import GHC.Generics (Generic) | 20 | import GHC.Generics (Generic) |
| 15 | import Control.Exception (Exception) | 21 | import Control.Exception (Exception) |
| @@ -18,6 +24,10 @@ import Data.Typeable (Typeable) | |||
| 18 | import Data.Bifunctor (bimap, first) | 24 | import Data.Bifunctor (bimap, first) |
| 19 | import Control.Monad (join) | 25 | import Control.Monad (join) |
| 20 | 26 | ||
| 27 | import Text.Read (readMaybe) | ||
| 28 | |||
| 29 | import Data.Maybe (fromMaybe) | ||
| 30 | |||
| 21 | import Text.BBCode (DomTree(..), TreeError(..)) | 31 | import Text.BBCode (DomTree(..), TreeError(..)) |
| 22 | import qualified Text.BBCode as Raw (bbcode, BBCodeError(..)) | 32 | import qualified Text.BBCode as Raw (bbcode, BBCodeError(..)) |
| 23 | 33 | ||
| @@ -31,7 +41,8 @@ data BBCodeError = LexerError String -- ^ Error while parsing input to stream of | |||
| 31 | 41 | ||
| 32 | instance Exception BBCodeError | 42 | instance Exception BBCodeError |
| 33 | 43 | ||
| 34 | data SemanticError = Placeholder | 44 | data SemanticError = BlockTagInLineContext Text |
| 45 | | UnmappedTag Text | ||
| 35 | deriving (Show, Eq, Generic, Typeable) | 46 | deriving (Show, Eq, Generic, Typeable) |
| 36 | 47 | ||
| 37 | instance Exception SemanticError | 48 | instance Exception SemanticError |
| @@ -45,3 +56,14 @@ morph' (Raw.TreeError x) = TreeError x | |||
| 45 | 56 | ||
| 46 | morph :: [DomTree] -> Either SemanticError Printout | 57 | morph :: [DomTree] -> Either SemanticError Printout |
| 47 | morph = undefined | 58 | morph = undefined |
| 59 | |||
| 60 | asBlock :: CI Text -> Map (CI Text) Text -> Either SemanticError Block | ||
| 61 | asBlock "VSpace" = Right . VSpace . lookupAttr "size" 1 | ||
| 62 | asBlock t = Left . const (UnmappedTag . CI.original $ t) | ||
| 63 | |||
| 64 | asLine :: CI Text -> Map (CI Text) Text -> Either SemanticError Line | ||
| 65 | asLine "HSpace" = Right . HSpace . lookupAttr "size" 1 | ||
| 66 | asLine t = Left . const (UnmappedTag . CI.original $ t) | ||
| 67 | |||
| 68 | lookupAttr :: Read a => CI Text -> a -> Map (CI Text) Text -> a | ||
| 69 | lookupAttr t def attrs = fromMaybe def $ Map.lookup t attrs >>= (readMaybe . T.unpack) | ||
diff --git a/spec/thermoprint-spec.cabal b/spec/thermoprint-spec.cabal index 40978c3..eb9d6d3 100644 --- a/spec/thermoprint-spec.cabal +++ b/spec/thermoprint-spec.cabal | |||
| @@ -41,6 +41,7 @@ library | |||
| 41 | , aeson >=0.9.0 && <1 | 41 | , aeson >=0.9.0 && <1 |
| 42 | , base64-bytestring >=1.0.0 && <2 | 42 | , base64-bytestring >=1.0.0 && <2 |
| 43 | , encoding >=0.8 && <1 | 43 | , encoding >=0.8 && <1 |
| 44 | , case-insensitive >=1.2 && <2 | ||
| 44 | -- hs-source-dirs: | 45 | -- hs-source-dirs: |
| 45 | default-language: Haskell2010 | 46 | default-language: Haskell2010 |
| 46 | 47 | ||
diff --git a/spec/thermoprint-spec.nix b/spec/thermoprint-spec.nix index 368f3a9..d20a8e6 100644 --- a/spec/thermoprint-spec.nix +++ b/spec/thermoprint-spec.nix | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | { mkDerivation, aeson, base, base64-bytestring, bbcode, bytestring | 1 | { mkDerivation, aeson, base, base64-bytestring, bbcode, bytestring |
| 2 | , Cabal, cabal-test-quickcheck, containers, deepseq, encoding | 2 | , Cabal, cabal-test-quickcheck, case-insensitive, containers |
| 3 | , hspec, QuickCheck, quickcheck-instances, servant, stdenv, text | 3 | , deepseq, encoding, hspec, QuickCheck, quickcheck-instances |
| 4 | , servant, stdenv, text | ||
| 4 | }: | 5 | }: |
| 5 | mkDerivation { | 6 | mkDerivation { |
| 6 | pname = "thermoprint-spec"; | 7 | pname = "thermoprint-spec"; |
| @@ -8,8 +9,8 @@ mkDerivation { | |||
| 8 | src = ./.; | 9 | src = ./.; |
| 9 | libraryHaskellDepends = [ | 10 | libraryHaskellDepends = [ |
| 10 | aeson base base64-bytestring bbcode bytestring Cabal | 11 | aeson base base64-bytestring bbcode bytestring Cabal |
| 11 | cabal-test-quickcheck containers deepseq encoding QuickCheck | 12 | cabal-test-quickcheck case-insensitive containers deepseq encoding |
| 12 | quickcheck-instances servant text | 13 | QuickCheck quickcheck-instances servant text |
| 13 | ]; | 14 | ]; |
| 14 | testHaskellDepends = [ | 15 | testHaskellDepends = [ |
| 15 | aeson base hspec QuickCheck quickcheck-instances | 16 | aeson base hspec QuickCheck quickcheck-instances |
