git.iko.soy/typeable/country-codes
on master help sign in
shakespeare instances
commit6e89b051a1b6e2602e8f07a1e89bc43d59e95e35 authorjpmoresmau <jp@moresmau.fr> dateSat 26 Apr 2014, 17:59 (12 years ago) parent3849dc6
3 files changed+23−4
country-codes.cabal+1 exe/Main.hs+11−3 src/Data/CountryCodes/ISO31661.hs+11−1
country-codes.cabal+1
@@ -30,6 +30,7 @@ library
3030 base >= 4 && < 5
3131 , text >= 0.11
3232 , aeson >= 0.5 && < 0.8
33+ , shakespeare == 2.0.*
3334 ghc-options: -Wall
3435 other-modules: Data.CountryCodes.ISO31661
3536 exposed-modules: Data.CountryCodes
exe/Main.hs+11−3
@@ -51,7 +51,7 @@ extract txt =
5151generate :: [(T.Text,T.Text)] -> T.Text
5252generate assocs =
5353 let
54− header = "{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude, PatternGuards #-}" <> nl <>
54+ header = "{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude, PatternGuards, FlexibleInstances, MultiParamTypeClasses #-}" <> nl <>
5555 "-- | This file is generated from the Wikipedia page" <> nl <>
5656 "-- <http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>" <> nl <>
5757 "module Data.CountryCodes.ISO31661 (" <> nl <>
@@ -69,6 +69,7 @@ generate assocs =
6969 "import Data.Typeable" <> nl <>
7070 "import qualified Data.Text as T" <> nl <>
7171 "import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail)" <> nl <>
72+ "import Text.Shakespeare.I18N" <> nl <>
7273 nl
7374 cons = snd (foldl' constructor (True, header) assocs) <> nl <>
7475 " deriving (Show,Read,Eq,Ord,Bounded,Enum,Typeable)"
@@ -107,8 +108,15 @@ generate assocs =
107108 "instance FromJSON CountryCode where" <> nl <>
108109 " parseJSON (String s)" <> nl <>
109110 " | Just a <- fromMText s=pure a" <> nl <>
110− " parseJSON _ =fail \"CountryCode\"" <> nl
111− in json
111+ " parseJSON _ =fail \"CountryCode\"" <> nl <> nl
112+ sp = json <>
113+ "-- | show user readable name" <> nl <>
114+ "instance ToMessage CountryCode where" <> nl <>
115+ " toMessage = toName" <> nl <> nl <>
116+ "-- | show user readable name, in english (ignoring locale for now)" <> nl <>
117+ "instance RenderMessage master CountryCode where" <> nl <>
118+ " renderMessage _ _ = toName" <> nl <> nl
119+ in sp
112120
113121 where
114122 constructor :: (Bool,T.Text) -> (T.Text,T.Text) -> (Bool,T.Text)
src/Data/CountryCodes/ISO31661.hs+11−1
@@ -1,4 +1,4 @@
1−{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude, PatternGuards #-}
1+{-# LANGUAGE DeriveDataTypeable, OverloadedStrings, NoImplicitPrelude, PatternGuards, FlexibleInstances, MultiParamTypeClasses #-}
22-- | This file is generated from the Wikipedia page
33-- <http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>
44module Data.CountryCodes.ISO31661 (
@@ -16,6 +16,7 @@ import Data.Aeson
1616import Data.Typeable
1717import qualified Data.Text as T
1818import Prelude (Show,Read,Eq,Ord,Bounded,Enum,error,($),(++),Maybe(..),(.),fail)
19+import Text.Shakespeare.I18N
1920
2021data CountryCode =
2122 AD
@@ -1298,3 +1299,12 @@ instance FromJSON CountryCode where
12981299 parseJSON (String s)
12991300 | Just a <- fromMText s=pure a
13001301 parseJSON _ =fail "CountryCode"
1302+
1303+-- | show user readable name
1304+instance ToMessage CountryCode where
1305+ toMessage = toName
1306+
1307+-- | show user readable name, in english (ignoring locale for now)
1308+instance RenderMessage master CountryCode where
1309+ renderMessage _ _ = toName
1310+