summaryrefslogtreecommitdiff
path: root/ymir/mlmmj-expose/FoxReplace.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2018-09-06 17:29:54 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2018-09-06 17:29:54 +0200
commite28b7def6cb2e4542c5fcbfc478dde85cd73ea3f (patch)
tree50891015f579511bdb4bc236562a6622d4e601b5 /ymir/mlmmj-expose/FoxReplace.hs
parentbec99bf3ad9c1ab09ee08fade347d9191a986fe1 (diff)
downloadnixos-e28b7def6cb2e4542c5fcbfc478dde85cd73ea3f.tar
nixos-e28b7def6cb2e4542c5fcbfc478dde85cd73ea3f.tar.gz
nixos-e28b7def6cb2e4542c5fcbfc478dde85cd73ea3f.tar.bz2
nixos-e28b7def6cb2e4542c5fcbfc478dde85cd73ea3f.tar.xz
nixos-e28b7def6cb2e4542c5fcbfc478dde85cd73ea3f.zip
Better mlmmj-expose
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"