From 7afabf5c098efc2f0df482ab66d9091d7aa3bd23 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sun, 31 Jan 2010 11:19:57 +0100 Subject: [PATCH] Better naming scheme. --- examples/categoryblog/hakyll.hs | 6 ++--- examples/hakyll/tutorial2.markdown | 2 +- examples/hakyll/tutorial5.markdown | 8 +++---- examples/hakyll/tutorial6.markdown | 2 +- examples/tagblog/hakyll.hs | 8 +++---- hakyll.cabal | 2 +- src/Text/Hakyll/File.hs | 6 ++--- .../{CompressCSS.hs => CompressCss.hs} | 8 +++---- src/Text/Hakyll/Internal/Render.hs | 2 +- src/Text/Hakyll/Page.hs | 8 +++---- src/Text/Hakyll/Render.hs | 6 ++--- src/Text/Hakyll/Renderable.hs | 4 ++-- src/Text/Hakyll/Renderables.hs | 24 +++++++++---------- src/Text/Hakyll/Util.hs | 10 ++++---- 14 files changed, 48 insertions(+), 48 deletions(-) rename src/Text/Hakyll/Internal/{CompressCSS.hs => CompressCss.hs} (90%) diff --git a/examples/categoryblog/hakyll.hs b/examples/categoryblog/hakyll.hs index e6d87ea..a5f3996 100644 --- a/examples/categoryblog/hakyll.hs +++ b/examples/categoryblog/hakyll.hs @@ -26,7 +26,7 @@ main = hakyll $ do renderPostList "posts.html" "All posts" renderablePosts -- Render post list per category - mapM_ (\(category, posts) -> renderPostList (categoryToURL category) ("Posts about " ++ category) posts) + mapM_ (\(category, posts) -> renderPostList (categoryToUrl category) ("Posts about " ++ category) posts) (toList categoryMap) -- Render index, including recent posts. @@ -51,12 +51,12 @@ main = hakyll $ do where postManipulation :: ContextManipulation postManipulation = renderDate "date" "%B %e, %Y" "Date unknown" - categoryToURL category = "$root/categories/" ++ removeSpaces category ++ ".html" + categoryToUrl category = "$root/categories/" ++ removeSpaces category ++ ".html" categoryList :: TagMap -> String categoryList = uncurry categoryListItem <=< toList - categoryListItem category posts = "
  • " ++ link category (categoryToURL category) + categoryListItem category posts = "
  • " ++ link category (categoryToUrl category) ++ " - " ++ show (length posts) ++ " items.
  • " renderPostList url title posts = do diff --git a/examples/hakyll/tutorial2.markdown b/examples/hakyll/tutorial2.markdown index aa4bc9e..eccc721 100644 --- a/examples/hakyll/tutorial2.markdown +++ b/examples/hakyll/tutorial2.markdown @@ -80,7 +80,7 @@ Combining two `Renderable`s, but setting a different `url` is quite common, so there is another function that helps us here: ~~~~~{.haskell} -combineWithURL :: (Renderable a, Renderable b) +combineWithUrl :: (Renderable a, Renderable b) => FilePath -> a -> b -> CombinedRenderable a b ~~~~~ diff --git a/examples/hakyll/tutorial5.markdown b/examples/hakyll/tutorial5.markdown index 8ccb3bd..739d311 100644 --- a/examples/hakyll/tutorial5.markdown +++ b/examples/hakyll/tutorial5.markdown @@ -130,7 +130,7 @@ clickable. We can again solve this with a `ContextManipulation`. We have a function that produces an url for a given tag: ~~~~~{.haskell} -tagToURL tag = "$root/tags/" ++ removeSpaces tag ++ ".html" +tagToUrl tag = "$root/tags/" ++ removeSpaces tag ++ ".html" ~~~~~ `removeSpaces` is an auxiliary function from `Text.Hakyll.File`. Now, there is @@ -142,7 +142,7 @@ for a given tag - the function we just wrote. Let's extend our ~~~~~{.haskell} postManipulation :: ContextManipulation postManipulation = renderDate "date" "%B %e, %Y" "Unknown date" - . renderTagLinks tagToURL + . renderTagLinks tagToUrl ~~~~~ So, the `renderTagLinks` function replaces the `$tags` value from @@ -167,7 +167,7 @@ needs this so it can cache the tags. ~~~~~{.haskell} tagMap <- readTagMap "postTags" postPaths let renderListForTag (tag, posts) = - renderPostList (tagToURL tag) + renderPostList (tagToUrl tag) ("Posts tagged " ++ tag) mapM_ renderListForTag (toList tagMap) ~~~~~ @@ -193,7 +193,7 @@ Then, we give a minimum and a maximum font size in percent, and we get the tag cloud back. We can add this to our index: ~~~~~{.haskell} -let tagCloud = renderTagCloud tagMap tagToURL 100 200 +let tagCloud = renderTagCloud tagMap tagToUrl 100 200 index = createListingWith postManipulation "index.html" "templates/postitem.html" (take 3 renderablePosts) diff --git a/examples/hakyll/tutorial6.markdown b/examples/hakyll/tutorial6.markdown index 3ab8271..df19a64 100644 --- a/examples/hakyll/tutorial6.markdown +++ b/examples/hakyll/tutorial6.markdown @@ -65,7 +65,7 @@ a list item for one category: ~~~~~{.haskell} categoryListItem category posts = - "
  • " ++ link category (categoryToURL category) + "
  • " ++ link category (categoryToUrl category) ++ " - " ++ show (length posts) ++ " items.
  • " ~~~~~ diff --git a/examples/tagblog/hakyll.hs b/examples/tagblog/hakyll.hs index c51007f..c2f16cf 100644 --- a/examples/tagblog/hakyll.hs +++ b/examples/tagblog/hakyll.hs @@ -26,11 +26,11 @@ main = hakyll $ do renderPostList "posts.html" "All posts" renderablePosts -- Render post list per tag - mapM_ (\(tag, posts) -> renderPostList (tagToURL tag) ("Posts tagged " ++ tag) posts) + mapM_ (\(tag, posts) -> renderPostList (tagToUrl tag) ("Posts tagged " ++ tag) posts) (toList tagMap) -- Render index, including recent posts. - let tagCloud = renderTagCloud tagMap tagToURL 100 200 + let tagCloud = renderTagCloud tagMap tagToUrl 100 200 index = createListingWith postManipulation "index.html" "templates/postitem.html" (take 3 renderablePosts) @@ -51,9 +51,9 @@ main = hakyll $ do where postManipulation :: ContextManipulation postManipulation = renderDate "date" "%B %e, %Y" "Date unknown" - . renderTagLinks tagToURL + . renderTagLinks tagToUrl - tagToURL tag = "$root/tags/" ++ removeSpaces tag ++ ".html" + tagToUrl tag = "$root/tags/" ++ removeSpaces tag ++ ".html" renderPostList url title posts = do let list = createListingWith postManipulation url "templates/postitem.html" posts [("title", title)] diff --git a/hakyll.cabal b/hakyll.cabal index 73f3c86..8e34cce 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -49,6 +49,6 @@ library Text.Hakyll.Util Text.Hakyll.Tags Text.Hakyll.Internal.Cache - Text.Hakyll.Internal.CompressCSS + Text.Hakyll.Internal.CompressCss Text.Hakyll.Internal.Render Text.Hakyll.Internal.Template diff --git a/src/Text/Hakyll/File.hs b/src/Text/Hakyll/File.hs index 4e7c10f..a7ed7b3 100644 --- a/src/Text/Hakyll/File.hs +++ b/src/Text/Hakyll/File.hs @@ -3,7 +3,7 @@ module Text.Hakyll.File ( toDestination , toCache - , toURL + , toUrl , toRoot , removeSpaces , makeDirectories @@ -46,8 +46,8 @@ toCache path = do dir <- askHakyll cacheDirectory return $ dir removeLeadingSeparator path -- | Get the url for a given page. -toURL :: FilePath -> FilePath -toURL path = if takeExtension path `elem` [ ".markdown" +toUrl :: FilePath -> FilePath +toUrl path = if takeExtension path `elem` [ ".markdown" , ".md" , ".mdn" , ".mdwn" diff --git a/src/Text/Hakyll/Internal/CompressCSS.hs b/src/Text/Hakyll/Internal/CompressCss.hs similarity index 90% rename from src/Text/Hakyll/Internal/CompressCSS.hs rename to src/Text/Hakyll/Internal/CompressCss.hs index 7d52bef..4b19984 100644 --- a/src/Text/Hakyll/Internal/CompressCSS.hs +++ b/src/Text/Hakyll/Internal/CompressCss.hs @@ -1,7 +1,7 @@ -- | Module used for CSS compression. The compression is currently in a simple -- state, but would typically reduce the number of bytes by about 25%. -module Text.Hakyll.Internal.CompressCSS - ( compressCSS +module Text.Hakyll.Internal.CompressCss + ( compressCss ) where import Data.List (isPrefixOf) @@ -9,8 +9,8 @@ import Data.List (isPrefixOf) import Text.Hakyll.Regex (substituteRegex) -- | Compress CSS to speed up your site. -compressCSS :: String -> String -compressCSS = compressSeparators +compressCss :: String -> String +compressCss = compressSeparators . stripComments . compressWhitespace diff --git a/src/Text/Hakyll/Internal/Render.hs b/src/Text/Hakyll/Internal/Render.hs index a3d2d9b..167c58a 100644 --- a/src/Text/Hakyll/Internal/Render.hs +++ b/src/Text/Hakyll/Internal/Render.hs @@ -65,4 +65,4 @@ writePage page = do liftIO $ writeFile destination $ finalSubstitute (fromString $ getBody page) context where - url = getURL page + url = getUrl page diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs index 39bb682..d557665 100644 --- a/src/Text/Hakyll/Page.hs +++ b/src/Text/Hakyll/Page.hs @@ -43,8 +43,8 @@ getValue str (Page page) = fromMaybe [] $ M.lookup str page -- | Get the URL for a certain page. This should always be defined. If -- not, it will error. -getPageURL :: Page -> String -getPageURL (Page page) = fromMaybe (error "No page url") $ M.lookup "url" page +getPageUrl :: Page -> String +getPageUrl (Page page) = fromMaybe (error "No page url") $ M.lookup "url" page -- | Get the original page path. getPagePath :: Page -> String @@ -134,7 +134,7 @@ readPageFromFile path = do return page where - url = toURL path + url = toUrl path category = let dirs = splitDirectories $ takeDirectory path in [("category", last dirs) | not (null dirs)] @@ -153,7 +153,7 @@ readPage path = do -- Make pages renderable. instance Renderable Page where getDependencies = (:[]) . getPagePath - getURL = getPageURL + getUrl = getPageUrl toContext (Page page) = return page -- Make pages serializable. diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs index 0802330..e11879d 100644 --- a/src/Text/Hakyll/Render.hs +++ b/src/Text/Hakyll/Render.hs @@ -22,7 +22,7 @@ import Text.Hakyll.Page import Text.Hakyll.Renderable import Text.Hakyll.File import Text.Hakyll.Internal.Template (readTemplate) -import Text.Hakyll.Internal.CompressCSS +import Text.Hakyll.Internal.CompressCss import Text.Hakyll.Internal.Render -- | Execute an IO action only when the cache is invalid. @@ -101,7 +101,7 @@ renderChain = renderChainWith id renderChainWith :: Renderable a => ContextManipulation -> [FilePath] -> a -> Hakyll () renderChainWith manipulation templatePaths renderable = - depends (getURL renderable) dependencies render' + depends (getUrl renderable) dependencies render' where dependencies = getDependencies renderable ++ templatePaths render' = do @@ -126,4 +126,4 @@ css source = do destination <- toDestination source where css' destination = do contents <- liftIO $ readFile source makeDirectories destination - liftIO $ writeFile destination (compressCSS contents) + liftIO $ writeFile destination (compressCss contents) diff --git a/src/Text/Hakyll/Renderable.hs b/src/Text/Hakyll/Renderable.hs index bb4f71f..2fdeacd 100644 --- a/src/Text/Hakyll/Renderable.hs +++ b/src/Text/Hakyll/Renderable.hs @@ -1,5 +1,5 @@ module Text.Hakyll.Renderable - ( Renderable(toContext, getDependencies, getURL) + ( Renderable(toContext, getDependencies, getUrl) ) where import Text.Hakyll.Hakyll (Hakyll) @@ -15,4 +15,4 @@ class Renderable a where getDependencies :: a -> [FilePath] -- | Get the destination for the renderable. - getURL :: a -> FilePath + getUrl :: a -> FilePath diff --git a/src/Text/Hakyll/Renderables.hs b/src/Text/Hakyll/Renderables.hs index c6954b8..6f5bcfe 100644 --- a/src/Text/Hakyll/Renderables.hs +++ b/src/Text/Hakyll/Renderables.hs @@ -7,7 +7,7 @@ module Text.Hakyll.Renderables , createPagePath , CombinedRenderable , combine - , combineWithURL + , combineWithUrl ) where import qualified Data.Map as M @@ -25,7 +25,7 @@ import Text.Hakyll.Render -- | A custom page. data CustomPage = CustomPage - { customPageURL :: String, + { customPageUrl :: String, customPageDependencies :: [FilePath], customPageContext :: [(String, Either String (Hakyll String))] } @@ -85,11 +85,11 @@ createListingWith manipulation url template renderables additional = instance Renderable CustomPage where getDependencies = customPageDependencies - getURL = customPageURL + getUrl = customPageUrl toContext page = do values <- mapM (either return id . snd) (customPageContext page) let pairs = zip (map fst $ customPageContext page) values - return $ M.fromList $ ("url", customPageURL page) : pairs + return $ M.fromList $ ("url", customPageUrl page) : pairs -- | PagePath is a class that wraps a FilePath. This is used to render Pages -- without reading them first through use of caching. @@ -102,7 +102,7 @@ createPagePath = PagePath -- We can render filepaths instance Renderable PagePath where getDependencies (PagePath path) = return path - getURL (PagePath path) = toURL path + getUrl (PagePath path) = toUrl path toContext (PagePath path) = readPage path >>= toContext -- We can serialize filepaths @@ -112,7 +112,7 @@ instance Binary PagePath where -- | A combination of two other renderables. data CombinedRenderable a b = CombinedRenderable a b - | CombinedRenderableWithURL FilePath a b + | CombinedRenderableWithUrl FilePath a b -- | Combine two renderables. The url will always be taken from the first -- @Renderable@. Also, if a `$key` is present in both renderables, the @@ -125,12 +125,12 @@ combine = CombinedRenderable -- | Combine two renderables and set a custom URL. This behaves like @combine@, -- except that for the @url@ field, the given URL is always chosen. -combineWithURL :: (Renderable a, Renderable b) +combineWithUrl :: (Renderable a, Renderable b) => FilePath -> a -> b -> CombinedRenderable a b -combineWithURL = CombinedRenderableWithURL +combineWithUrl = CombinedRenderableWithUrl -- Render combinations. instance (Renderable a, Renderable b) @@ -139,18 +139,18 @@ instance (Renderable a, Renderable b) -- Add the dependencies. getDependencies (CombinedRenderable a b) = getDependencies a ++ getDependencies b - getDependencies (CombinedRenderableWithURL _ a b) = + getDependencies (CombinedRenderableWithUrl _ a b) = getDependencies a ++ getDependencies b -- Take the url from the first renderable, or the specified URL. - getURL (CombinedRenderable a _) = getURL a - getURL (CombinedRenderableWithURL url _ _) = url + getUrl (CombinedRenderable a _) = getUrl a + getUrl (CombinedRenderableWithUrl url _ _) = url -- Take a union of the contexts. toContext (CombinedRenderable a b) = do c1 <- toContext a c2 <- toContext b return $ c1 `M.union` c2 - toContext (CombinedRenderableWithURL url a b) = do + toContext (CombinedRenderableWithUrl url a b) = do c <- toContext (CombinedRenderable a b) return $ M.singleton "url" url `M.union` c diff --git a/src/Text/Hakyll/Util.hs b/src/Text/Hakyll/Util.hs index 358c60e..d900d6e 100644 --- a/src/Text/Hakyll/Util.hs +++ b/src/Text/Hakyll/Util.hs @@ -1,7 +1,7 @@ -- | Miscellaneous text manipulation functions. module Text.Hakyll.Util ( trim - , stripHTML + , stripHtml , link ) where @@ -14,11 +14,11 @@ trim = reverse . trim' . reverse . trim' trim' = dropWhile isSpace -- | Strip html tags from the given string. -stripHTML :: String -> String -stripHTML [] = [] -stripHTML str = let (beforeTag, rest) = break (== '<') str +stripHtml :: String -> String +stripHtml [] = [] +stripHtml str = let (beforeTag, rest) = break (== '<') str (_, afterTag) = break (== '>') rest - in beforeTag ++ stripHTML (tail' afterTag) + in beforeTag ++ stripHtml (tail' afterTag) where -- We need a failsafe tail function. tail' [] = []