mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 06:05:31 +03:00
Add recursive glob matcher.
This commit is contained in:
parent
f7c647fb80
commit
ea75b4acc2
27
src/Glob.elm
27
src/Glob.elm
@ -1,6 +1,9 @@
|
||||
module Glob exposing (..)
|
||||
|
||||
import List.Extra
|
||||
import OptimizedDecoder
|
||||
import Pages.StaticHttp as StaticHttp
|
||||
import Secrets
|
||||
|
||||
|
||||
type Glob a
|
||||
@ -35,6 +38,19 @@ star =
|
||||
)
|
||||
|
||||
|
||||
recursiveStar : Glob String
|
||||
recursiveStar =
|
||||
Glob "**"
|
||||
(\captures ->
|
||||
case captures of
|
||||
first :: rest ->
|
||||
( first, rest )
|
||||
|
||||
[] ->
|
||||
( "ERROR", [] )
|
||||
)
|
||||
|
||||
|
||||
zeroOrMore : List String -> Glob (Maybe String)
|
||||
zeroOrMore matchers =
|
||||
Glob
|
||||
@ -136,3 +152,14 @@ oneOf ( defaultMatch, otherMatchers ) =
|
||||
[] ->
|
||||
( Tuple.second defaultMatch, [] )
|
||||
)
|
||||
|
||||
|
||||
toStaticHttp : Glob a -> StaticHttp.Request (List a)
|
||||
toStaticHttp glob =
|
||||
StaticHttp.get (Secrets.succeed <| "glob://" ++ toPattern glob)
|
||||
(OptimizedDecoder.string
|
||||
|> OptimizedDecoder.list
|
||||
|> OptimizedDecoder.list
|
||||
|> OptimizedDecoder.map
|
||||
(\appliedList -> appliedList |> List.map (\inner -> run inner glob |> .match))
|
||||
)
|
||||
|
@ -93,6 +93,18 @@ all =
|
||||
, expectedMatch = ( "before-slash", "AFTER-SLASH" )
|
||||
, expectedPattern = "*/*.txt"
|
||||
}
|
||||
, test "recursive match" <|
|
||||
\() ->
|
||||
Glob.succeed Tuple.pair
|
||||
|> Glob.keep Glob.recursiveStar
|
||||
|> Glob.drop (Glob.literal "/")
|
||||
|> Glob.keep Glob.star
|
||||
|> Glob.drop (Glob.literal ".txt")
|
||||
|> expect
|
||||
{ captures = [ "a/b/c", "d" ]
|
||||
, expectedMatch = ( "a/b/c", "d" )
|
||||
, expectedPattern = "**/*.txt"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user