From 42bacee41a68e9e1eaddcec0702ead71a0a1b3e6 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sun, 24 Jan 2010 16:40:09 +0100 Subject: [PATCH] Module cleanup. --- hakyll.cabal | 18 ++++++++--------- src/Text/Hakyll/{ => Internal}/CompressCSS.hs | 2 +- .../Internal.hs => Internal/Render.hs} | 12 ++--------- src/Text/Hakyll/{ => Internal}/Template.hs | 20 +++++++++++++++---- src/Text/Hakyll/Render.hs | 6 +++--- src/Text/Hakyll/Tags.hs | 3 +-- 6 files changed, 32 insertions(+), 29 deletions(-) rename src/Text/Hakyll/{ => Internal}/CompressCSS.hs (96%) rename src/Text/Hakyll/{Render/Internal.hs => Internal/Render.hs} (87%) rename src/Text/Hakyll/{ => Internal}/Template.hs (81%) diff --git a/hakyll.cabal b/hakyll.cabal index 617e4bd..d458000 100644 --- a/hakyll.cabal +++ b/hakyll.cabal @@ -35,19 +35,19 @@ library old-locale >= 1, time >= 1, binary >= 0.5 - exposed-modules: Text.Hakyll + exposed-modules: Network.Hakyll.SimpleServer + Text.Hakyll + Text.Hakyll.Context + Text.Hakyll.File Text.Hakyll.Hakyll + Text.Hakyll.Regex Text.Hakyll.Render Text.Hakyll.Renderable Text.Hakyll.Renderables - Text.Hakyll.CompressCSS - Text.Hakyll.File Text.Hakyll.Page Text.Hakyll.Util Text.Hakyll.Tags - Text.Hakyll.Context - Text.Hakyll.Regex - Text.Hakyll.Template - Network.Hakyll.SimpleServer - other-modules: Text.Hakyll.Render.Internal - Text.Hakyll.Internal.Cache + other-modules: Text.Hakyll.Internal.Cache + Text.Hakyll.Internal.CompressCSS + Text.Hakyll.Internal.Render + Text.Hakyll.Internal.Template diff --git a/src/Text/Hakyll/CompressCSS.hs b/src/Text/Hakyll/Internal/CompressCSS.hs similarity index 96% rename from src/Text/Hakyll/CompressCSS.hs rename to src/Text/Hakyll/Internal/CompressCSS.hs index 0836f69..7d52bef 100644 --- a/src/Text/Hakyll/CompressCSS.hs +++ b/src/Text/Hakyll/Internal/CompressCSS.hs @@ -1,6 +1,6 @@ -- | 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.CompressCSS +module Text.Hakyll.Internal.CompressCSS ( compressCSS ) where diff --git a/src/Text/Hakyll/Render/Internal.hs b/src/Text/Hakyll/Internal/Render.hs similarity index 87% rename from src/Text/Hakyll/Render/Internal.hs rename to src/Text/Hakyll/Internal/Render.hs index 3ebc67f..a3d2d9b 100644 --- a/src/Text/Hakyll/Render/Internal.hs +++ b/src/Text/Hakyll/Internal/Render.hs @@ -1,5 +1,5 @@ -- | Internal module do some low-level rendering. -module Text.Hakyll.Render.Internal +module Text.Hakyll.Internal.Render ( substitute , regularSubstitute , finalSubstitute @@ -14,20 +14,12 @@ import Control.Monad.Reader (liftIO) import Data.List (foldl') import Data.Maybe (fromMaybe) -import Text.Hakyll.Template (Template, substitute, fromString) import Text.Hakyll.Context (Context, ContextManipulation) import Text.Hakyll.Renderable import Text.Hakyll.Page import Text.Hakyll.File import Text.Hakyll.Hakyll - --- | "substitute" for use during a chain. -regularSubstitute :: Template -> Context -> String -regularSubstitute = substitute "$$" - --- | "substitute" for the end of a chain (just before writing). -finalSubstitute :: Template -> Context -> String -finalSubstitute = substitute "$" +import Text.Hakyll.Internal.Template -- | A pure render function. pureRenderWith :: ContextManipulation -- ^ Manipulation to apply on the context. diff --git a/src/Text/Hakyll/Template.hs b/src/Text/Hakyll/Internal/Template.hs similarity index 81% rename from src/Text/Hakyll/Template.hs rename to src/Text/Hakyll/Internal/Template.hs index 9ba30fb..41d279c 100644 --- a/src/Text/Hakyll/Template.hs +++ b/src/Text/Hakyll/Internal/Template.hs @@ -1,8 +1,10 @@ -module Text.Hakyll.Template +module Text.Hakyll.Internal.Template ( Template , fromString , readTemplate , substitute + , regularSubstitute + , finalSubstitute ) where import qualified Data.Map as M @@ -46,9 +48,9 @@ readTemplate path = do where fileName = "templates" path --- | Substitutes @$identifiers@ in the given string by values from the given --- "Context". When a key is not found, it is left as it is. You can here --- specify the characters used to replace escaped dollars (@$$@). +-- | Substitutes @$identifiers@ in the given "Template" by values from the given +-- "Context". When a key is not found, it is left as it is. You can specify +-- the characters used to replace escaped dollars (@$$@) here. substitute :: String -> Template -> Context -> String substitute escaper (Chunk chunk template) context = chunk ++ substitute escaper template context @@ -59,6 +61,16 @@ substitute escaper (Identifier key template) context = substitute escaper (EscapeCharacter template) context = escaper ++ substitute escaper template context substitute _ End _ = [] + +-- | "substitute" for use during a chain. This will leave escaped characters as +-- they are. +regularSubstitute :: Template -> Context -> String +regularSubstitute = substitute "$$" + +-- | "substitute" for the end of a chain (just before writing). This renders +-- escaped characters. +finalSubstitute :: Template -> Context -> String +finalSubstitute = substitute "$" instance Binary Template where put (Chunk string template) = put (0 :: Word8) >> put string >> put template diff --git a/src/Text/Hakyll/Render.hs b/src/Text/Hakyll/Render.hs index 9484859..3329994 100644 --- a/src/Text/Hakyll/Render.hs +++ b/src/Text/Hakyll/Render.hs @@ -16,14 +16,14 @@ import Control.Monad (unless) import Control.Monad.Reader (liftIO) import System.Directory (copyFile) -import Text.Hakyll.Template (readTemplate) import Text.Hakyll.Hakyll (Hakyll) import Text.Hakyll.Context (ContextManipulation) import Text.Hakyll.Page import Text.Hakyll.Renderable import Text.Hakyll.File -import Text.Hakyll.CompressCSS -import Text.Hakyll.Render.Internal +import Text.Hakyll.Internal.Template (readTemplate) +import Text.Hakyll.Internal.CompressCSS +import Text.Hakyll.Internal.Render -- | Execute an IO action only when the cache is invalid. depends :: FilePath -- ^ File to be rendered or created. diff --git a/src/Text/Hakyll/Tags.hs b/src/Text/Hakyll/Tags.hs index 77f52fe..d36a866 100644 --- a/src/Text/Hakyll/Tags.hs +++ b/src/Text/Hakyll/Tags.hs @@ -29,12 +29,11 @@ import System.FilePath (()) import Text.Hakyll.Hakyll (Hakyll) import Text.Hakyll.Context (ContextManipulation, changeValue) -import Text.Hakyll.Render.Internal (finalSubstitute) import Text.Hakyll.Regex -import Text.Hakyll.Template import Text.Hakyll.Util import Text.Hakyll.Page import Text.Hakyll.Internal.Cache +import Text.Hakyll.Internal.Template -- | Read a tag map. This creates a map from tags to page paths. --