diff options
Diffstat (limited to 'compiler/src/Resource.hs')
-rw-r--r-- | compiler/src/Resource.hs | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/compiler/src/Resource.hs b/compiler/src/Resource.hs index 04e315a..60b783e 100644 --- a/compiler/src/Resource.hs +++ b/compiler/src/Resource.hs | |||
@@ -22,10 +22,13 @@ | |||
22 | module Resource | 22 | module Resource |
23 | ( ResourceTree(..) | 23 | ( ResourceTree(..) |
24 | , buildResourceTree | 24 | , buildResourceTree |
25 | , flattenResourceTree | ||
26 | , outputDiff | ||
25 | ) where | 27 | ) where |
26 | 28 | ||
27 | 29 | ||
28 | import Data.Function ((&)) | 30 | import Data.Function ((&)) |
31 | import Data.List ((\\)) | ||
29 | import Files | 32 | import Files |
30 | import Input | 33 | import Input |
31 | 34 | ||
@@ -34,25 +37,47 @@ import Input | |||
34 | data ResourceTree = | 37 | data ResourceTree = |
35 | ItemResource | 38 | ItemResource |
36 | { sidecar :: Sidecar | 39 | { sidecar :: Sidecar |
37 | , path :: Path | 40 | , resPath :: Path |
38 | , itemThumbnailPath :: Path } | 41 | , itemThumbnailPath :: Path } |
39 | | DirResource | 42 | | DirResource |
40 | { items :: [ResourceTree] | 43 | { items :: [ResourceTree] |
41 | , path :: Path | 44 | , resPath :: Path |
42 | , dirThumbnailPath :: Maybe Path } | 45 | , dirThumbnailPath :: Maybe Path } |
43 | deriving Show | 46 | deriving Show |
44 | 47 | ||
45 | 48 | ||
46 | -- TODO: actually generate compilation strategies | 49 | -- TODO: actually generate compilation strategies |
47 | buildResourceTree :: InputTree -> ResourceTree | 50 | buildResourceTree :: InputTree -> ResourceTree |
48 | buildResourceTree = resNode | 51 | buildResourceTree = resNode |
49 | where | 52 | where |
50 | resNode (InputFile path sidecar) = | 53 | resNode (InputFile path sidecar) = |
51 | ItemResource sidecar (itemsDir /> path) (thumbnailsDir /> path) | 54 | ItemResource |
55 | { sidecar = sidecar | ||
56 | , resPath = itemsDir /> path | ||
57 | , itemThumbnailPath = thumbnailsDir /> path } | ||
52 | 58 | ||
53 | resNode (InputDir path thumbnailPath items) = | 59 | resNode (InputDir path thumbnailPath items) = |
54 | map resNode items | 60 | map resNode items |
55 | & \dirItems -> DirResource dirItems (itemsDir /> path) Nothing | 61 | & \dirItems -> DirResource |
62 | { items = dirItems | ||
63 | , resPath = itemsDir /> path | ||
64 | , dirThumbnailPath = fmap ((/>) thumbnailsDir) thumbnailPath } | ||
56 | 65 | ||
57 | itemsDir = "items" | 66 | itemsDir = "items" |
58 | thumbnailsDir = "thumbnails" | 67 | thumbnailsDir = "thumbnails" |
68 | |||
69 | |||
70 | flattenResourceTree :: ResourceTree -> [ResourceTree] | ||
71 | flattenResourceTree item@ItemResource{} = [item] | ||
72 | flattenResourceTree dir@(DirResource items _ _) = | ||
73 | dir:(concatMap flattenResourceTree items) | ||
74 | |||
75 | |||
76 | outputDiff :: ResourceTree -> FSNode -> [Path] | ||
77 | outputDiff resources ref = (fsPaths ref) \\ (resPaths resources) | ||
78 | where | ||
79 | resPaths :: ResourceTree -> [Path] | ||
80 | resPaths = map resPath . flattenResourceTree | ||
81 | |||
82 | fsPaths :: FSNode -> [Path] | ||
83 | fsPaths = map nodePath . tail . flattenDir | ||