on master help sign in
Merge pull request #482 from nickie/fix-yaml-number
0382eeeJasper Van der Jeugt
src/Data/Yaml/Extended.hs+5−1
@@ -7,12 +7,16 @@ module Data.Yaml.Extended
7import qualified Data.Text as T
7import qualified Data.Text as T
8import qualified Data.Vector as V
8import qualified Data.Vector as V
9import Data.Yaml
9import Data.Yaml
10+import Data.Scientific
10
11
11toString :: Value -> Maybe String
12toString :: Value -> Maybe String
12toString (String t) = Just (T.unpack t)
13toString (String t) = Just (T.unpack t)
13toString (Bool True) = Just "true"
14toString (Bool True) = Just "true"
14toString (Bool False) = Just "false"
15toString (Bool False) = Just "false"
16+-- | Make sure that numeric fields containing integer numbers are shown as
17+-- | integers (i.e., "42" instead of "42.0").
18+toString (Number d) | isInteger d = Just (formatScientific Fixed (Just 0) d)
15−toString (Number d) = Just (show d)
19+ | otherwise = Just (show d)
16toString _ = Nothing
20toString _ = Nothing
17
21
18toList :: Value -> Maybe [Value]
22toList :: Value -> Maybe [Value]
tests/Hakyll/Web/Template/Tests.hs+1
@@ -29,6 +29,7 @@ tests :: TestTree
29tests = testGroup "Hakyll.Core.Template.Tests" $ concat
29tests = testGroup "Hakyll.Core.Template.Tests" $ concat
30 [ [ testCase "case01" $ test ("template.html.out", "template.html", "example.md")
30 [ [ testCase "case01" $ test ("template.html.out", "template.html", "example.md")
31 , testCase "case02" $ test ("strip.html.out", "strip.html", "example.md")
31 , testCase "case02" $ test ("strip.html.out", "strip.html", "example.md")
32+ , testCase "case03" $ test ("just-meta.html.out", "just-meta.html", "example.md")
32 , testCase "applyJoinTemplateList" testApplyJoinTemplateList
33 , testCase "applyJoinTemplateList" testApplyJoinTemplateList
33 ]
34 ]
34
35
tests/data/example.md.metadata+2
@@ -1,3 +1,5 @@
1external: External data
1external: External data
2date: 2012-10-22 14:35:24
2date: 2012-10-22 14:35:24
3subblog: food
3subblog: food
4+intfield: 42
5+numfield: 3.14
tests/data/just-meta.htmlnew file+7
@@ -0,0 +1,7 @@
1+<pre>
2+external: {$external$}
3+date: {$date$}
4+subblog: {$subblog$}
5+intfield: {$intfield$}
6+numfield: {$numfield$}
7+</pre>
tests/data/just-meta.html.outnew file+7
@@ -0,0 +1,7 @@
1+<pre>
2+external: {External data}
3+date: {2012-10-22 14:35:24}
4+subblog: {food}
5+intfield: {42}
6+numfield: {3.14}
7+</pre>