on master help sign in
Added link function.
547f98dJasper Van der Jeugt
examples/hakyll/philosophy.markdown+1−1
@@ -18,7 +18,7 @@ never exceed a 100 lines of code.
18Hakyll tries to provide as many high-level functions as possible for common
18Hakyll tries to provide as many high-level functions as possible for common
19tasks, while the lower-level functions should also be accessible. If you think
19tasks, while the lower-level functions should also be accessible. If you think
20you're writing something that can be used for many sites, please send a patch,
20you're writing something that can be used for many sites, please send a patch,
21−our your `hakyll.hs`, and we will see what we can do.
21+or your `hakyll.hs`, and we will see what we can do.
22
22
23## Well-documented
23## Well-documented
24
24
src/Text/Hakyll/File.hs+1
@@ -50,6 +50,7 @@ getRecursiveContents topdir = do
50
50
51-- | A filter that takes all file names with a given extension. Prefix the
51-- | A filter that takes all file names with a given extension. Prefix the
52-- extension with a dot:
52-- extension with a dot:
53+--
53-- > havingExtension ".markdown" ["index.markdown", "style.css"] == ["index.markdown"]
54-- > havingExtension ".markdown" ["index.markdown", "style.css"] == ["index.markdown"]
54havingExtension :: String -> [FilePath] -> [FilePath]
55havingExtension :: String -> [FilePath] -> [FilePath]
55havingExtension extension = filter ((==) extension . takeExtension)
56havingExtension extension = filter ((==) extension . takeExtension)
src/Text/Hakyll/Util.hs+8
@@ -2,6 +2,7 @@ module Text.Hakyll.Util
2 ( trim
2 ( trim
3 , split
3 , split
4 , stripHTML
4 , stripHTML
5+ , link
5 ) where
6 ) where
6
7
7import Data.Char (isSpace)
8import Data.Char (isSpace)
@@ -26,3 +27,10 @@ stripHTML str = let (beforeTag, rest) = break (== '<') str
26split :: String -> String -> [String]
27split :: String -> String -> [String]
27split pattern = filter (not . null)
28split pattern = filter (not . null)
28 . splitRegex (mkRegex pattern)
29 . splitRegex (mkRegex pattern)
30+
31+-- | Make a HTML link.
32+--
33+-- > link "foo" "bar.html" == "<a href='bar.html'>foo</a>"
34+link :: String -> String -> String
35+link text destination = "<a href=\"" ++ destination ++ "\">"
36+ ++ text ++ "</a>"
tests/Tests.hs+6
@@ -23,6 +23,8 @@ tests = [ testGroup "Util group" [ testProperty "trim length" prop_trim_length
23 , testCase "stripHTML 3" test_strip_html3
23 , testCase "stripHTML 3" test_strip_html3
24 , testCase "split 1" test_split1
24 , testCase "split 1" test_split1
25 , testCase "split 2" test_split2
25 , testCase "split 2" test_split2
26+ , testCase "link 1" test_link1
27+ , testCase "link 2" test_link2
26 ]
28 ]
27
29
28 , testGroup "CompressCSS group" [ testProperty "compressCSS length" prop_compress_css_length
30 , testGroup "CompressCSS group" [ testProperty "compressCSS length" prop_compress_css_length
@@ -63,6 +65,10 @@ test_strip_html3 = stripHTML "<b>Hakyll</b> is an <i>awesome</i> web framework <
63test_split1 = split "," "1,2,3" @?= ["1", "2", "3"]
65test_split1 = split "," "1,2,3" @?= ["1", "2", "3"]
64test_split2 = split "," ",1,2," @?= ["1", "2"]
66test_split2 = split "," ",1,2," @?= ["1", "2"]
65
67
68+-- Link test cases.
69+test_link1 = link "foo bar" "/foo/bar.html" @?= "<a href=\"/foo/bar.html\">foo bar</a>"
70+test_link2 = link "back home" "/" @?= "<a href=\"/\">back home</a>"
71+
66-- CSS compression should always decrease the text length.
72-- CSS compression should always decrease the text length.
67prop_compress_css_length str = length str >= length (compressCSS str)
73prop_compress_css_length str = length str >= length (compressCSS str)
68
74