summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolaos S. Papaspyrou <nickie@softlab.ntua.gr>2016-10-31 10:36:41 +0200
committerNikolaos S. Papaspyrou <nickie@softlab.ntua.gr>2016-10-31 10:36:41 +0200
commit6fbffc586cd951180c5a4ed328bd43a1f3920a85 (patch)
tree4d8f54404faaa867866b116c4c596ad757bd01f3
parentab34240bb53565ce7179432cd75fd67adddb4e7c (diff)
downloadhakyll-6fbffc586cd951180c5a4ed328bd43a1f3920a85.tar.gz
Fix integer fields in YAML metadata
If a numeric field contains an integer number, it should be shown as an integer number. Without this patch, the field: answer = 42 would be shown as "42.0". Before the introduction of YAML in metadata, this was treated as a string and therefore shown as just "42". This patch reinstates the older (and IMHO correct) behavior.
-rw-r--r--src/Data/Yaml/Extended.hs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/Data/Yaml/Extended.hs b/src/Data/Yaml/Extended.hs
index 099e945..1600bab 100644
--- a/src/Data/Yaml/Extended.hs
+++ b/src/Data/Yaml/Extended.hs
@@ -7,12 +7,14 @@ module Data.Yaml.Extended
import qualified Data.Text as T
import qualified Data.Vector as V
import Data.Yaml
+import Data.Scientific
toString :: Value -> Maybe String
toString (String t) = Just (T.unpack t)
toString (Bool True) = Just "true"
toString (Bool False) = Just "false"
-toString (Number d) = Just (show d)
+toString (Number d) | isInteger d = Just (formatScientific Fixed (Just 0) d)
+ | otherwise = Just (show d)
toString _ = Nothing
toList :: Value -> Maybe [Value]