on master help sign in
Return information in rules
commitf6f7cde03c4f28657c720cc3f7ae02a52aa3ceb4 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 24 May 2011, 14:39 (15 years ago) parent758e0be
2 files changed+23−10
src/Hakyll/Core/Identifier/Pattern.hs+6 src/Hakyll/Core/Rules.hs+17−10
src/Hakyll/Core/Identifier/Pattern.hs+6
@@ -36,6 +36,7 @@ module Hakyll.Core.Identifier.Pattern
3636 , castPattern
3737 , parseGlob
3838 , predicate
39+ , list
3940 , regex
4041 , inGroup
4142 , matches
@@ -106,6 +107,11 @@ parseGlob = Glob . parse'
106107predicate :: (Identifier a -> Bool) -> Pattern a
107108predicate = Predicate
108109
110+-- | Create a 'Pattern' from a list of 'Identifier's it should match
111+--
112+list :: [Identifier a] -> Pattern a
113+list = List
114+
109115-- | Create a 'Pattern' from a regex
110116--
111117-- Example:
src/Hakyll/Core/Rules.hs+17−10
@@ -61,10 +61,8 @@ tellCompilers :: (Binary a, Typeable a, Writable a)
6161 => [(Identifier a, Compiler () a)]
6262 -> Rules
6363tellCompilers compilers = RulesM $ do
64− -- We box the compilers so they have a more simple type, and we apply the
65− -- current group to the corresponding identifiers
66− g <- rulesGroup <$> ask
67− let compilers' = map (setGroup g . castIdentifier *** boxCompiler) compilers
64+ -- We box the compilers so they have a more simple type
65+ let compilers' = map (castIdentifier *** boxCompiler) compilers
6866 tell $ RuleSet mempty compilers' mempty
6967 where
7068 boxCompiler = (>>> arr compiledItem >>> arr CompileRule)
@@ -116,7 +114,7 @@ match pattern = RulesM . local addPredicate . unRulesM
116114-- This will put the compiler for the raw content in a separate group
117115-- (@\"raw\"@), which causes it to be compiled as well.
118116--
119−group :: String -> Rules -> Rules
117+group :: String -> RulesM a -> RulesM a
120118group g = RulesM . local setGroup' . unRulesM
121119 where
122120 setGroup' env = env { rulesGroup = Just g }
@@ -128,12 +126,13 @@ group g = RulesM . local setGroup' . unRulesM
128126-- you might want to have a look at 'create'.
129127--
130128compile :: (Binary a, Typeable a, Writable a)
131− => Compiler Resource a -> Rules
129+ => Compiler Resource a -> RulesM (Pattern a)
132130compile compiler = do
133131 ids <- resources
134132 tellCompilers $ flip map ids $ \identifier ->
135133 (identifier, constA (fromIdentifier identifier) >>> compiler)
136134 tellResources $ map fromIdentifier ids
135+ return $ list ids
137136
138137-- | Add a compilation rule
139138--
@@ -143,8 +142,12 @@ compile compiler = do
143142-- actual content itself.
144143--
145144create :: (Binary a, Typeable a, Writable a)
146− => Identifier a -> Compiler () a -> Rules
147−create identifier compiler = tellCompilers [(identifier, compiler)]
145+ => Identifier a -> Compiler () a -> RulesM (Identifier a)
146+create id' compiler = RulesM $ do
147+ group' <- rulesGroup <$> ask
148+ let id'' = setGroup group' id'
149+ unRulesM $ tellCompilers [(id'', compiler)]
150+ return id''
148151
149152-- | Add a route.
150153--
@@ -158,13 +161,17 @@ route route' = RulesM $ do
158161 group' <- rulesGroup <$> ask
159162 unRulesM $ tellRoute $ matchRoute (pattern `mappend` inGroup group') route'
160163
161−-- | Get a list of resources matching the current pattern
164+-- | Get a list of resources matching the current pattern. This will also set
165+-- the correct group to the identifiers.
162166--
163167resources :: RulesM [Identifier a]
164168resources = RulesM $ do
165169 pattern <- rulesPattern <$> ask
166170 provider <- rulesResourceProvider <$> ask
167− return $ filterMatches pattern $ map toIdentifier $ resourceList provider
171+ group' <- rulesGroup <$> ask
172+ return $ filterMatches pattern $ map (toId group') $ resourceList provider
173+ where
174+ toId g = setGroup g . toIdentifier
168175
169176-- | Apart from regular compilers, one is also able to specify metacompilers.
170177-- Metacompilers are a special class of compilers: they are compilers which