on master help sign in
Added link function.
commit547f98dff029d011e6498c901190de11a0bc9c61 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 8 Jan 2010, 09:42 (17 years ago) parentd29e415
4 files changed+16−1
examples/hakyll/philosophy.markdown+1−1 src/Text/Hakyll/File.hs+1 src/Text/Hakyll/Util.hs+8 tests/Tests.hs+6
examples/hakyll/philosophy.markdown+1−1
@@ -18,7 +18,7 @@ never exceed a 100 lines of code.
1818Hakyll tries to provide as many high-level functions as possible for common
1919tasks, while the lower-level functions should also be accessible. If you think
2020you'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.
2222
2323## Well-documented
2424
src/Text/Hakyll/File.hs+1
@@ -50,6 +50,7 @@ getRecursiveContents topdir = do
5050
5151-- | A filter that takes all file names with a given extension. Prefix the
5252-- extension with a dot:
53+--
5354-- > havingExtension ".markdown" ["index.markdown", "style.css"] == ["index.markdown"]
5455havingExtension :: String -> [FilePath] -> [FilePath]
5556havingExtension extension = filter ((==) extension . takeExtension)
src/Text/Hakyll/Util.hs+8
@@ -2,6 +2,7 @@ module Text.Hakyll.Util
22 ( trim
33 , split
44 , stripHTML
5+ , link
56 ) where
67
78import Data.Char (isSpace)
@@ -26,3 +27,10 @@ stripHTML str = let (beforeTag, rest) = break (== '<') str
2627split :: String -> String -> [String]
2728split pattern = filter (not . null)
2829 . 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
2323 , testCase "stripHTML 3" test_strip_html3
2424 , testCase "split 1" test_split1
2525 , testCase "split 2" test_split2
26+ , testCase "link 1" test_link1
27+ , testCase "link 2" test_link2
2628 ]
2729
2830 , 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 <
6365test_split1 = split "," "1,2,3" @?= ["1", "2", "3"]
6466test_split2 = split "," ",1,2," @?= ["1", "2"]
6567
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+
6672-- CSS compression should always decrease the text length.
6773prop_compress_css_length str = length str >= length (compressCSS str)
6874