on master help sign in
Add `fromCaptureString` function
6cecbb8Jasper Van der Jeugt
src/Hakyll/Core/Identifier/Pattern.hs+21
@@ -35,6 +35,7 @@ module Hakyll.Core.Identifier.Pattern
35 , doesMatch
35 , doesMatch
36 , matches
36 , matches
37 , fromCapture
37 , fromCapture
38+ , fromCaptureString
38 , fromCaptures
39 , fromCaptures
39 ) where
40 ) where
40
41
@@ -122,9 +123,29 @@ match' (m : ms) (s : ss) = case m of
122-- | Create an identifier from a pattern by filling in the captures with a given
123-- | Create an identifier from a pattern by filling in the captures with a given
123-- string
124-- string
124--
125--
126+-- Example:
127+--
128+-- > fromCapture (parsePattern "tags/*") (parseIdentifier "foo")
129+--
130+-- Result:
131+--
132+-- > "tags/foo"
133+--
125fromCapture :: Pattern -> Identifier -> Identifier
134fromCapture :: Pattern -> Identifier -> Identifier
126fromCapture pattern = fromCaptures pattern . repeat
135fromCapture pattern = fromCaptures pattern . repeat
127
136
137+-- | Simplified version of 'fromCapture' which takes a 'String' instead of an
138+-- 'Identifier'
139+--
140+-- > fromCaptureString (parsePattern "tags/*") "foo"
141+--
142+-- Result:
143+--
144+-- > "tags/foo"
145+--
146+fromCaptureString :: Pattern -> String -> Identifier
147+fromCaptureString pattern = fromCapture pattern . parseIdentifier
148+
128-- | Create an identifier from a pattern by filling in the captures with the
149-- | Create an identifier from a pattern by filling in the captures with the
129-- given list of strings
150-- given list of strings
130--
151--