diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/.gitignore | 3 | ||||
-rw-r--r-- | compiler/Setup.hs | 2 | ||||
-rw-r--r-- | compiler/app/Main.hs | 91 | ||||
-rw-r--r-- | compiler/data/.gitignore | 1 | ||||
-rw-r--r-- | compiler/data/readme.md | 1 | ||||
-rw-r--r-- | compiler/package.yaml | 76 | ||||
-rw-r--r-- | compiler/readme.md | 20 | ||||
-rw-r--r-- | compiler/src/Compiler.hs | 131 | ||||
-rw-r--r-- | compiler/src/Config.hs | 60 | ||||
-rw-r--r-- | compiler/src/Files.hs | 183 | ||||
-rw-r--r-- | compiler/src/Input.hs | 126 | ||||
-rw-r--r-- | compiler/src/Processors.hs | 201 | ||||
-rw-r--r-- | compiler/src/Resource.hs | 198 | ||||
-rw-r--r-- | compiler/stack.yaml | 66 | ||||
-rw-r--r-- | compiler/stack.yaml.lock | 12 | ||||
-rw-r--r-- | compiler/test/Spec.hs | 2 | ||||
-rw-r--r-- | compiler/win_build.cmd | 4 | ||||
-rw-r--r-- | compiler/win_compile_example.cmd | 10 |
18 files changed, 1187 insertions, 0 deletions
diff --git a/compiler/.gitignore b/compiler/.gitignore new file mode 100644 index 0000000..778e7ef --- /dev/null +++ b/compiler/.gitignore | |||
@@ -0,0 +1,3 @@ | |||
1 | .stack-work/ | ||
2 | ldgallery-compiler.cabal | ||
3 | *~ \ No newline at end of file | ||
diff --git a/compiler/Setup.hs b/compiler/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/compiler/Setup.hs | |||
@@ -0,0 +1,2 @@ | |||
1 | import Distribution.Simple | ||
2 | main = defaultMain | ||
diff --git a/compiler/app/Main.hs b/compiler/app/Main.hs new file mode 100644 index 0000000..1a42abf --- /dev/null +++ b/compiler/app/Main.hs | |||
@@ -0,0 +1,91 @@ | |||
1 | -- ldgallery - A static generator which turns a collection of tagged | ||
2 | -- pictures into a searchable web gallery. | ||
3 | -- | ||
4 | -- Copyright (C) 2019-2020 Pacien TRAN-GIRARD | ||
5 | -- | ||
6 | -- This program is free software: you can redistribute it and/or modify | ||
7 | -- it under the terms of the GNU Affero General Public License as | ||
8 | -- published by the Free Software Foundation, either version 3 of the | ||
9 | -- License, or (at your option) any later version. | ||
10 | -- | ||
11 | -- This program is distributed in the hope that it will be useful, | ||
12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | -- GNU Affero General Public License for more details. | ||
15 | -- | ||
16 | -- You should have received a copy of the GNU Affero General Public License | ||
17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
18 | |||
19 | module Main where | ||
20 | |||
21 | import Paths_ldgallery_compiler (version, getDataFileName) | ||
22 | import Data.Version (showVersion) | ||
23 | import System.FilePath ((</>)) | ||
24 | import System.Console.CmdArgs | ||
25 | |||
26 | import Compiler | ||
27 | import Files (readDirectory, copyTo) | ||
28 | |||
29 | |||
30 | data Options = Options | ||
31 | { inputDir :: String | ||
32 | , outputDir :: String | ||
33 | , rebuilAll :: Bool | ||
34 | , withViewer :: Bool | ||
35 | } deriving (Show, Data, Typeable) | ||
36 | |||
37 | options :: Options | ||
38 | options = Options | ||
39 | { inputDir = "./" | ||
40 | &= typDir | ||
41 | &= name "i" | ||
42 | &= name "input-dir" | ||
43 | &= explicit | ||
44 | &= help "Gallery source directory (default=./)" | ||
45 | , outputDir = "./out" | ||
46 | &= typDir | ||
47 | &= name "o" | ||
48 | &= name "output-dir" | ||
49 | &= explicit | ||
50 | &= help "Generated gallery output path (default=./out)" | ||
51 | , rebuilAll = False | ||
52 | &= name "r" | ||
53 | &= name "rebuild-all" | ||
54 | &= explicit | ||
55 | &= help "Invalidate cache and recompile everything" | ||
56 | , withViewer = False | ||
57 | &= name "w" | ||
58 | &= name "with-viewer" | ||
59 | &= explicit | ||
60 | &= help "Include the static web viewer in the output" | ||
61 | } | ||
62 | |||
63 | &= summary ("ldgallery v" ++ (showVersion version) ++ " - a static web gallery generator with tags") | ||
64 | &= program "ldgallery" | ||
65 | &= help "Compile a gallery" | ||
66 | &= helpArg [explicit, name "h", name "help"] | ||
67 | &= versionArg [explicit, name "version"] | ||
68 | |||
69 | |||
70 | main :: IO () | ||
71 | main = | ||
72 | do | ||
73 | opts <- cmdArgs options | ||
74 | compileGallery (inputDir opts) (galleryOutputDir "gallery" opts) (rebuilAll opts) | ||
75 | if (withViewer opts) then copyViewer (outputDir opts) else noop | ||
76 | |||
77 | where | ||
78 | galleryOutputDir :: FilePath -> Options -> FilePath | ||
79 | galleryOutputDir gallerySubdir opts = | ||
80 | if withViewer opts then outputBase </> gallerySubdir else outputBase | ||
81 | where outputBase = outputDir opts | ||
82 | |||
83 | copyViewer :: FilePath -> IO () | ||
84 | copyViewer target = | ||
85 | putStrLn "Copying viewer webapp" | ||
86 | >> getDataFileName "viewer" | ||
87 | >>= readDirectory | ||
88 | >>= copyTo target | ||
89 | |||
90 | noop :: IO () | ||
91 | noop = return () | ||
diff --git a/compiler/data/.gitignore b/compiler/data/.gitignore new file mode 100644 index 0000000..dd4395c --- /dev/null +++ b/compiler/data/.gitignore | |||
@@ -0,0 +1 @@ | |||
viewer | |||
diff --git a/compiler/data/readme.md b/compiler/data/readme.md new file mode 100644 index 0000000..9aded74 --- /dev/null +++ b/compiler/data/readme.md | |||
@@ -0,0 +1 @@ | |||
Link `../../viewer/dist` to `./viewer` for full distribution. | |||
diff --git a/compiler/package.yaml b/compiler/package.yaml new file mode 100644 index 0000000..043985d --- /dev/null +++ b/compiler/package.yaml | |||
@@ -0,0 +1,76 @@ | |||
1 | name: ldgallery-compiler | ||
2 | version: 0.1.0.0 | ||
3 | github: "pacien/ldgallery" | ||
4 | license: AGPL-3 | ||
5 | author: "Pacien TRAN-GIRARD, Guillaume FOUET" | ||
6 | maintainer: "" | ||
7 | copyright: "2019 Pacien TRAN-GIRARD, Guillaume FOUET" | ||
8 | |||
9 | extra-source-files: | ||
10 | - readme.md | ||
11 | |||
12 | # Metadata used when publishing your package | ||
13 | synopsis: A static generator which turns a collection of tagged pictures into a searchable web gallery | ||
14 | category: Web | ||
15 | description: Please see the README on GitHub at <https://github.com/pacien/ldgallery> | ||
16 | |||
17 | dependencies: | ||
18 | - base >= 4.7 && < 5 | ||
19 | - containers | ||
20 | - filepath | ||
21 | - directory | ||
22 | - text | ||
23 | - aeson | ||
24 | - yaml | ||
25 | - cmdargs | ||
26 | - JuicyPixels | ||
27 | - JuicyPixels-extra | ||
28 | - parallel-io | ||
29 | - Glob | ||
30 | - safe | ||
31 | - time | ||
32 | |||
33 | default-extensions: | ||
34 | - DuplicateRecordFields | ||
35 | - DeriveGeneric | ||
36 | - DeriveDataTypeable | ||
37 | - DeriveAnyClass | ||
38 | - FlexibleContexts | ||
39 | - NamedFieldPuns | ||
40 | - OverloadedStrings | ||
41 | |||
42 | ghc-options: | ||
43 | - -Werror | ||
44 | - -Wall | ||
45 | - -Wcompat | ||
46 | - -Widentities | ||
47 | - -Wincomplete-uni-patterns | ||
48 | - -Wredundant-constraints | ||
49 | |||
50 | data-dir: data | ||
51 | data-files: ["**/*"] | ||
52 | |||
53 | library: | ||
54 | source-dirs: src | ||
55 | |||
56 | executables: | ||
57 | ldgallery-compiler-exe: | ||
58 | main: Main.hs | ||
59 | source-dirs: app | ||
60 | ghc-options: | ||
61 | - -threaded | ||
62 | - -rtsopts | ||
63 | - -with-rtsopts=-N | ||
64 | dependencies: | ||
65 | - ldgallery-compiler | ||
66 | |||
67 | tests: | ||
68 | ldgallery-compiler-test: | ||
69 | main: Spec.hs | ||
70 | source-dirs: test | ||
71 | ghc-options: | ||
72 | - -threaded | ||
73 | - -rtsopts | ||
74 | - -with-rtsopts=-N | ||
75 | dependencies: | ||
76 | - ldgallery-compiler | ||
diff --git a/compiler/readme.md b/compiler/readme.md new file mode 100644 index 0000000..e18b026 --- /dev/null +++ b/compiler/readme.md | |||
@@ -0,0 +1,20 @@ | |||
1 | # ldgallery-compiler | ||
2 | |||
3 | |||
4 | ## Build | ||
5 | |||
6 | Building the _ldgallery compiler_ requires the [stack] tool. | ||
7 | |||
8 | [stack]: https://haskellstack.org/ | ||
9 | |||
10 | Within the project's directory, use | ||
11 | |||
12 | * `stack setup` to setup the development environment and compiler. | ||
13 | * `stack build` to compile the project. | ||
14 | * or `stack build --fast --file-watch` to automatically compile on file change. | ||
15 | * `stack exec ldgallery-compiler-exe -- --help` to run the compiled program (and displaying its help text for instance). | ||
16 | |||
17 | |||
18 | ### Embedded viewer | ||
19 | |||
20 | In order to allow the `ldgallery` command line tool to generate a full gallery which includes the _viewer_, a compiled version of the web app must be placed under `./data/viewer`. The `--with-viewer` flag will otherwise not be functional. | ||
diff --git a/compiler/src/Compiler.hs b/compiler/src/Compiler.hs new file mode 100644 index 0000000..a347433 --- /dev/null +++ b/compiler/src/Compiler.hs | |||
@@ -0,0 +1,131 @@ | |||
1 | -- ldgallery - A static generator which turns a collection of tagged | ||
2 | -- pictures into a searchable web gallery. | ||
3 | -- | ||
4 | -- Copyright (C) 2019-2020 Pacien TRAN-GIRARD | ||
5 | -- | ||
6 | -- This program is free software: you can redistribute it and/or modify | ||
7 | -- it under the terms of the GNU Affero General Public License as | ||
8 | -- published by the Free Software Foundation, either version 3 of the | ||
9 | -- License, or (at your option) any later version. | ||
10 | -- | ||
11 | -- This program is distributed in the hope that it will be useful, | ||
12 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | -- GNU Affero General Public License for more details. | ||
15 | -- | ||
16 | -- You should have received a copy of the GNU Affero General Public License | ||
17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
18 | |||