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