aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/Compiler.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/Compiler.hs')
-rw-r--r--compiler/src/Compiler.hs37
1 files changed, 20 insertions, 17 deletions
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs
index a347433..13e9232 100644
--- a/compiler/src/Compiler.hs
+++ b/compiler/src/Compiler.hs
@@ -71,30 +71,35 @@ writeJSON outputPath object =
71 ensureParentDir JSON.encodeFile outputPath object 71 ensureParentDir JSON.encodeFile outputPath object
72 72
73 73
74galleryDirFilter :: ([Glob.Pattern], [Glob.Pattern]) -> FSNode -> Bool 74galleryDirFilter :: CompilerConfig -> FSNode -> Bool
75galleryDirFilter (inclusionPatterns, exclusionPatterns) = 75galleryDirFilter config =
76 (not . isHidden) 76 (not . isHidden)
77 &&& (matchName True $ anyPattern inclusionPatterns) 77 &&& (not . matchesFile (== galleryConf))
78 &&& (not . isConfigFile)
79 &&& (not . containsOutputGallery) 78 &&& (not . containsOutputGallery)
80 &&& (not . (matchName False $ anyPattern exclusionPatterns)) 79 &&& ((matchesDir $ anyPattern $ includedDirectories config) |||
80 (matchesFile $ anyPattern $ includedFiles config))
81 &&& (not . ((matchesDir $ anyPattern $ excludedDirectories config) |||
82 (matchesFile $ anyPattern $ excludedFiles config)))
81 83
82 where 84 where
83 (&&&) = liftM2 (&&) 85 (&&&) = liftM2 (&&)
84 (|||) = liftM2 (||) 86 (|||) = liftM2 (||)
85 87
86 matchName :: Bool -> (FileName -> Bool) -> FSNode -> Bool 88 matchesDir :: (FileName -> Bool) -> FSNode -> Bool
87 matchName matchDir _ Dir{} = matchDir 89 matchesDir cond dir@Dir{} = maybe False cond $ nodeName dir
88 matchName _ cond file@File{} = maybe False cond $ nodeName file 90 matchesDir _ File{} = False
89 91
90 anyPattern :: [Glob.Pattern] -> FileName -> Bool 92 matchesFile :: (FileName -> Bool) -> FSNode -> Bool
91 anyPattern patterns filename = any (flip Glob.match filename) patterns 93 matchesFile cond file@File{} = maybe False cond $ nodeName file
94 matchesFile _ Dir{} = False
92 95
93 isConfigFile = matchName False (== galleryConf) 96 anyPattern :: [String] -> FileName -> Bool
94 isGalleryIndex = matchName False (== indexFile) 97 anyPattern patterns filename = any (flip Glob.match filename) (map Glob.compile patterns)
95 isViewerIndex = matchName False (== viewerMainFile) 98
99 containsOutputGallery :: FSNode -> Bool
96 containsOutputGallery File{} = False 100 containsOutputGallery File{} = False
97 containsOutputGallery Dir{items} = any (isGalleryIndex ||| isViewerIndex) items 101 containsOutputGallery Dir{items} =
102 any (matchesFile (== indexFile) ||| matchesFile (== viewerMainFile)) items
98 103
99 104
100compileGallery :: FilePath -> FilePath -> Bool -> IO () 105compileGallery :: FilePath -> FilePath -> Bool -> IO ()
@@ -104,9 +109,7 @@ compileGallery inputDirPath outputDirPath rebuildAll =
104 let config = compiler fullConfig 109 let config = compiler fullConfig
105 110
106 inputDir <- readDirectory inputDirPath 111 inputDir <- readDirectory inputDirPath
107 let inclusionPatterns = map Glob.compile $ includeFiles config 112 let sourceFilter = galleryDirFilter config
108 let exclusionPatterns = map Glob.compile $ excludeFiles config
109 let sourceFilter = galleryDirFilter (inclusionPatterns, exclusionPatterns)
110 let sourceTree = filterDir sourceFilter inputDir 113 let sourceTree = filterDir sourceFilter inputDir
111 inputTree <- readInputTree sourceTree 114 inputTree <- readInputTree sourceTree
112 115