summaryrefslogtreecommitdiff
path: root/ymir/mlmmj-expose/FoxReplace.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ymir/mlmmj-expose/FoxReplace.hs')
-rw-r--r--ymir/mlmmj-expose/FoxReplace.hs67
1 files changed, 67 insertions, 0 deletions
diff --git a/ymir/mlmmj-expose/FoxReplace.hs b/ymir/mlmmj-expose/FoxReplace.hs
new file mode 100644
index 00000000..ca28fa43
--- /dev/null
+++ b/ymir/mlmmj-expose/FoxReplace.hs
@@ -0,0 +1,67 @@
1{-# LANGUAGE RecordWildCards, OverloadedStrings #-}
2
3module FoxReplace where
4
5import Data.Aeson
6
7import Data.Set (Set)
8import qualified Data.Set as Set
9
10
11newtype FoxReplace = FoxReplace (Set FoxReplaceGroup)
12 deriving (Ord, Eq, Show)
13
14data FoxReplaceGroup = FoxReplaceGroup
15 { groupName :: String
16 , groupUrls :: Set String
17 , groupSubs :: Set FoxReplaceSub
18 , groupHtmlMode :: FoxReplaceHTML
19 }
20 deriving (Ord, Eq, Show)
21
22data FoxReplaceHTML = NoHTML | OutputOnlyHTML | BothHTML
23 deriving (Ord, Eq, Enum, Show)
24
25data FoxReplaceSub = FoxReplaceSub
26 { rInput, rOutput :: String
27 , rInputType :: SubInput
28 , rCaseSensitive :: Bool
29 }
30 deriving (Ord, Eq, Show)
31
32data SubInput = TextInput | WordInput | RegexpInput
33 deriving (Ord, Eq, Enum, Show)
34
35
36instance ToJSON FoxReplace where
37 toJSON (FoxReplace groupSet) = object
38 [ "version" .= ("0.15" :: String)
39 , "groups" .= groupSet
40 ]
41
42instance ToJSON FoxReplaceGroup where
43 toJSON FoxReplaceGroup{..} = object
44 [ "name" .= groupName
45 , "html" .= groupHtmlMode
46 , "enabled" .= True
47 , "urls" .= groupUrls
48 , "substitutions" .= groupSubs
49 ]
50
51instance ToJSON FoxReplaceHTML where
52 toJSON NoHTML = String "none"
53 toJSON OutputOnlyHTML = String "output"
54 toJSON BothHTML = String "inputoutput"
55
56instance ToJSON FoxReplaceSub where
57 toJSON FoxReplaceSub{..} = object
58 [ "input" .= rInput
59 , "output" .= rOutput
60 , "inputType" .= rInputType
61 , "caseSensitive" .= rCaseSensitive
62 ]
63
64instance ToJSON SubInput where
65 toJSON TextInput = String "text"
66 toJSON WordInput = String "wholewords"
67 toJSON RegexpInput = String "regexp"