From edeba47f52392f207570239946d1c62bf9b4648b Mon Sep 17 00:00:00 2001 From: Julien Moutinho Date: Sat, 12 Nov 2022 13:55:31 +0100 Subject: [PATCH 1/1] init --- .chglog/CHANGELOG.tpl.md | 37 ++ .chglog/config.yml | 37 ++ .envrc | 1 + .gitignore | 21 + .hlint.yaml | 28 ++ .reuse/dep5 | 13 + 0001-mvc-updates-fix-L.pretraverseM.patch | 25 + ChangeLog.md | 3 + LICENSES/AGPL-3.0-or-later.txt | 235 +++++++++ LICENSES/CC0-1.0.txt | 121 +++++ Makefile | 110 +++++ cabal.project | 1 + flake.lock | 121 +++++ flake.nix | 66 +++ fourmolu.yaml | 8 + literate-web.cabal | 240 ++++++++++ src/Literate/Web.hs | 11 + src/Literate/Web/Semantics/Compiler.hs | 446 ++++++++++++++++++ src/Literate/Web/Semantics/Server.hs | 274 +++++++++++ src/Literate/Web/Syntaxes.hs | 202 ++++++++ src/Literate/Web/Types/MIME.hs | 221 +++++++++ src/Literate/Web/Types/URL.hs | 55 +++ tests/Examples/Ex01.hs | 20 + tests/Examples/Ex02.hs | 27 ++ tests/Examples/Ex03.hs | 88 ++++ tests/Examples/Ex04.hs | 102 ++++ tests/Goldens.hs | 123 +++++ .../Site001/Model01/Expected/about/me.txt | 1 + .../Site001/Model01/Expected/index.txt | 1 + .../Compiler/Site001/Model01/Got/about/me.txt | 1 + .../Compiler/Site001/Model01/Got/index.txt | 1 + .../Site003/Model01/Expected/feed.txt | 1 + .../Site003/Model01/Expected/filter/all.txt | 1 + .../Site003/Model01/Expected/filter/en.txt | 1 + .../Site003/Model01/Expected/filter/fr.txt | 1 + .../Site003/Model01/Expected/static.txt | 1 + .../Compiler/Site003/Model01/Got/feed.txt | 1 + .../Site003/Model01/Got/filter/all.txt | 1 + .../Site003/Model01/Got/filter/en.txt | 1 + .../Site003/Model01/Got/filter/fr.txt | 1 + .../Compiler/Site003/Model01/Got/static.txt | 1 + .../Site003/Model02/Expected/feed.txt | 1 + .../Site003/Model02/Expected/filter/all.txt | 1 + .../Model02/Expected/filter/all/cat1.txt | 1 + .../Model02/Expected/filter/all/cat2.txt | 1 + .../Model02/Expected/filter/all/cat3.txt | 1 + .../Site003/Model02/Expected/filter/en.txt | 1 + .../Model02/Expected/filter/en/cat1.txt | 1 + .../Model02/Expected/filter/en/cat2.txt | 1 + .../Model02/Expected/filter/en/cat3.txt | 1 + .../Site003/Model02/Expected/filter/fr.txt | 1 + .../Model02/Expected/filter/fr/cat1.txt | 1 + .../Model02/Expected/filter/fr/cat2.txt | 1 + .../Model02/Expected/filter/fr/cat3.txt | 1 + .../Site003/Model02/Expected/static.txt | 1 + .../Compiler/Site003/Model02/Got/feed.txt | 1 + .../Site003/Model02/Got/filter/all.txt | 1 + .../Site003/Model02/Got/filter/all/cat1.txt | 1 + .../Site003/Model02/Got/filter/all/cat2.txt | 1 + .../Site003/Model02/Got/filter/all/cat3.txt | 1 + .../Site003/Model02/Got/filter/en.txt | 1 + .../Site003/Model02/Got/filter/en/cat1.txt | 1 + .../Site003/Model02/Got/filter/en/cat2.txt | 1 + .../Site003/Model02/Got/filter/en/cat3.txt | 1 + .../Site003/Model02/Got/filter/fr.txt | 1 + .../Site003/Model02/Got/filter/fr/cat1.txt | 1 + .../Site003/Model02/Got/filter/fr/cat2.txt | 1 + .../Site003/Model02/Got/filter/fr/cat3.txt | 1 + .../Compiler/Site003/Model02/Got/static.txt | 1 + .../Site004/Model01/Expected/lorem.txt | 1 + .../Site004/Model01/Expected/page/page1.txt | 1 + .../Site004/Model01/Expected/post/post1.txt | 1 + .../Site004/Model01/Expected/post/post2.txt | 1 + .../Compiler/Site004/Model01/Got/lorem.txt | 1 + .../Site004/Model01/Got/page/page1.txt | 1 + .../Site004/Model01/Got/post/post1.txt | 1 + .../Site004/Model01/Got/post/post2.txt | 1 + .../Site005/Model01/Expected/ex03/feed.txt | 1 + .../Model01/Expected/ex03/filter/all.txt | 1 + .../Model01/Expected/ex03/filter/en.txt | 1 + .../Model01/Expected/ex03/filter/fr.txt | 1 + .../Site005/Model01/Expected/ex03/static.txt | 1 + .../Site005/Model01/Expected/ex04/lorem.txt | 1 + .../Model01/Expected/ex04/page/page1.txt | 1 + .../Model01/Expected/ex04/post/post1.txt | 1 + .../Model01/Expected/ex04/post/post2.txt | 1 + .../Site005/Model01/Got/ex03/feed.txt | 1 + .../Site005/Model01/Got/ex03/filter/all.txt | 1 + .../Site005/Model01/Got/ex03/filter/en.txt | 1 + .../Site005/Model01/Got/ex03/filter/fr.txt | 1 + .../Site005/Model01/Got/ex03/static.txt | 1 + .../Site005/Model01/Got/ex04/lorem.txt | 1 + .../Site005/Model01/Got/ex04/page/page1.txt | 1 + .../Site005/Model01/Got/ex04/post/post1.txt | 1 + .../Site005/Model01/Got/ex04/post/post2.txt | 1 + .../Site005/Model02/Expected/ex03/feed.txt | 1 + .../Model02/Expected/ex03/filter/all.txt | 1 + .../Model02/Expected/ex03/filter/all/cat1.txt | 1 + .../Model02/Expected/ex03/filter/all/cat2.txt | 1 + .../Model02/Expected/ex03/filter/all/cat3.txt | 1 + .../Model02/Expected/ex03/filter/en.txt | 1 + .../Model02/Expected/ex03/filter/en/cat1.txt | 1 + .../Model02/Expected/ex03/filter/en/cat2.txt | 1 + .../Model02/Expected/ex03/filter/en/cat3.txt | 1 + .../Model02/Expected/ex03/filter/fr.txt | 1 + .../Model02/Expected/ex03/filter/fr/cat1.txt | 1 + .../Model02/Expected/ex03/filter/fr/cat2.txt | 1 + .../Model02/Expected/ex03/filter/fr/cat3.txt | 1 + .../Site005/Model02/Expected/ex03/static.txt | 1 + .../Site005/Model02/Expected/ex04/lorem.txt | 1 + .../Model02/Expected/ex04/page/page1.txt | 1 + .../Model02/Expected/ex04/post/post1.txt | 1 + .../Model02/Expected/ex04/post/post2.txt | 1 + .../Site005/Model02/Got/ex03/feed.txt | 1 + .../Site005/Model02/Got/ex03/filter/all.txt | 1 + .../Model02/Got/ex03/filter/all/cat1.txt | 1 + .../Model02/Got/ex03/filter/all/cat2.txt | 1 + .../Model02/Got/ex03/filter/all/cat3.txt | 1 + .../Site005/Model02/Got/ex03/filter/en.txt | 1 + .../Model02/Got/ex03/filter/en/cat1.txt | 1 + .../Model02/Got/ex03/filter/en/cat2.txt | 1 + .../Model02/Got/ex03/filter/en/cat3.txt | 1 + .../Site005/Model02/Got/ex03/filter/fr.txt | 1 + .../Model02/Got/ex03/filter/fr/cat1.txt | 1 + .../Model02/Got/ex03/filter/fr/cat2.txt | 1 + .../Model02/Got/ex03/filter/fr/cat3.txt | 1 + .../Site005/Model02/Got/ex03/static.txt | 1 + .../Site005/Model02/Got/ex04/lorem.txt | 1 + .../Site005/Model02/Got/ex04/page/page1.txt | 1 + .../Site005/Model02/Got/ex04/post/post1.txt | 1 + .../Site005/Model02/Got/ex04/post/post2.txt | 1 + tests/HUnits.hs | 174 +++++++ tests/Main.hs | 18 + tests/Utils.hs | 47 ++ 134 files changed, 2979 insertions(+) create mode 100755 .chglog/CHANGELOG.tpl.md create mode 100755 .chglog/config.yml create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 .hlint.yaml create mode 100644 .reuse/dep5 create mode 100644 0001-mvc-updates-fix-L.pretraverseM.patch create mode 100644 ChangeLog.md create mode 100644 LICENSES/AGPL-3.0-or-later.txt create mode 100644 LICENSES/CC0-1.0.txt create mode 100644 Makefile create mode 100644 cabal.project create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 fourmolu.yaml create mode 100644 literate-web.cabal create mode 100644 src/Literate/Web.hs create mode 100644 src/Literate/Web/Semantics/Compiler.hs create mode 100644 src/Literate/Web/Semantics/Server.hs create mode 100644 src/Literate/Web/Syntaxes.hs create mode 100644 src/Literate/Web/Types/MIME.hs create mode 100644 src/Literate/Web/Types/URL.hs create mode 100644 tests/Examples/Ex01.hs create mode 100644 tests/Examples/Ex02.hs create mode 100644 tests/Examples/Ex03.hs create mode 100644 tests/Examples/Ex04.hs create mode 100644 tests/Goldens.hs create mode 100644 tests/Goldens/Compiler/Site001/Model01/Expected/about/me.txt create mode 100644 tests/Goldens/Compiler/Site001/Model01/Expected/index.txt create mode 100644 tests/Goldens/Compiler/Site001/Model01/Got/about/me.txt create mode 100644 tests/Goldens/Compiler/Site001/Model01/Got/index.txt create mode 100644 tests/Goldens/Compiler/Site003/Model01/Expected/feed.txt create mode 100644 tests/Goldens/Compiler/Site003/Model01/Expected/filter/all.txt create mode 100644 tests/Goldens/Compiler/Site003/Model01/Expected/filter/en.txt create mode 100644 tests/Goldens/Compiler/Site003/Model01/Expected/filter/fr.txt create mode 100644 tests/Goldens/Compiler/Site003/Model01/Expected/static.txt create mode 100644 tests/Goldens/Compiler/Site003/Model01/Got/feed.txt create mode 100644 tests/Goldens/Compiler/Site003/Model01/Got/filter/all.txt create mode 100644 tests/Goldens/Compiler/Site003/Model01/Got/filter/en.txt create mode 100644 tests/Goldens/Compiler/Site003/Model01/Got/filter/fr.txt create mode 100644 tests/Goldens/Compiler/Site003/Model01/Got/static.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/feed.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/filter/all.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/filter/all/cat1.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/filter/all/cat2.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/filter/all/cat3.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/filter/en.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/filter/en/cat1.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/filter/en/cat2.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/filter/en/cat3.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr/cat1.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr/cat2.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr/cat3.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Expected/static.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/feed.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/filter/all.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/filter/all/cat1.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/filter/all/cat2.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/filter/all/cat3.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/filter/en.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/filter/en/cat1.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/filter/en/cat2.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/filter/en/cat3.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/filter/fr.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/filter/fr/cat1.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/filter/fr/cat2.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/filter/fr/cat3.txt create mode 100644 tests/Goldens/Compiler/Site003/Model02/Got/static.txt create mode 100644 tests/Goldens/Compiler/Site004/Model01/Expected/lorem.txt create mode 100644 tests/Goldens/Compiler/Site004/Model01/Expected/page/page1.txt create mode 100644 tests/Goldens/Compiler/Site004/Model01/Expected/post/post1.txt create mode 100644 tests/Goldens/Compiler/Site004/Model01/Expected/post/post2.txt create mode 100644 tests/Goldens/Compiler/Site004/Model01/Got/lorem.txt create mode 100644 tests/Goldens/Compiler/Site004/Model01/Got/page/page1.txt create mode 100644 tests/Goldens/Compiler/Site004/Model01/Got/post/post1.txt create mode 100644 tests/Goldens/Compiler/Site004/Model01/Got/post/post2.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Expected/ex03/feed.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Expected/ex03/filter/all.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Expected/ex03/filter/en.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Expected/ex03/filter/fr.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Expected/ex03/static.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Expected/ex04/lorem.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Expected/ex04/page/page1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Expected/ex04/post/post1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Expected/ex04/post/post2.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Got/ex03/feed.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Got/ex03/filter/all.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Got/ex03/filter/en.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Got/ex03/filter/fr.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Got/ex03/static.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Got/ex04/lorem.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Got/ex04/page/page1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Got/ex04/post/post1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model01/Got/ex04/post/post2.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/feed.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all/cat1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all/cat2.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all/cat3.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en/cat1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en/cat2.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en/cat3.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr/cat1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr/cat2.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr/cat3.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex03/static.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex04/lorem.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex04/page/page1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex04/post/post1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Expected/ex04/post/post2.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/feed.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all/cat1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all/cat2.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all/cat3.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en/cat1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en/cat2.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en/cat3.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr/cat1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr/cat2.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr/cat3.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex03/static.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex04/lorem.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex04/page/page1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex04/post/post1.txt create mode 100644 tests/Goldens/Compiler/Site005/Model02/Got/ex04/post/post2.txt create mode 100644 tests/HUnits.hs create mode 100644 tests/Main.hs create mode 100644 tests/Utils.hs diff --git a/.chglog/CHANGELOG.tpl.md b/.chglog/CHANGELOG.tpl.md new file mode 100755 index 0000000..07711aa --- /dev/null +++ b/.chglog/CHANGELOG.tpl.md @@ -0,0 +1,37 @@ +{{ range .Versions }} +## {{ .Tag.Name }} ({{ datetime "2006-01-02" .Tag.Date }}) + +{{ range .CommitGroups -}} +### {{ .Title }} + +{{ range .Commits -}} +* {{ upperFirst .Type }}{{ if .Subject }} {{ .Subject }}{{ end }}. +{{ end }} +{{ end -}} + +{{- if .RevertCommits -}} +### Reverts + +{{ range .RevertCommits -}} +* {{ .Revert.Header }} +{{ end }} +{{ end -}} + +{{- if .MergeCommits -}} +### Merges + +{{ range .MergeCommits -}} +* {{ .Header }} +{{ end }} +{{ end -}} + +{{- if .NoteGroups -}} +{{ range .NoteGroups -}} +### {{ .Title }} + +{{ range .Notes }} +{{ .Body }} +{{ end }} +{{ end -}} +{{ end -}} +{{ end -}} diff --git a/.chglog/config.yml b/.chglog/config.yml new file mode 100755 index 0000000..2e25049 --- /dev/null +++ b/.chglog/config.yml @@ -0,0 +1,37 @@ +style: none +template: CHANGELOG.tpl.md +info: + title: ChangeLog + repository_url: "https://git.sourcephile.fr/haskell/literate-web" +options: + sort: "date" + + commits: + sort_by: Type + + commit_groups: + group_by: Scope + sort_by: Custom + title_order: + - iface + - doc + - impl + - tests + - build + title_maps: + build: Build + doc: Documentation + iface: Interface + impl: Implementation + tests: Tests + + header: + pattern: "^([\\w\\$\\.\\-\\*\\s]*)\\:\\s(\\w*)\\s*(.*)$" + pattern_maps: + - Scope + - Type + - Subject + + notes: + keywords: + - BREAKING CHANGE diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f00fe6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +*.actual.* +*.eventlog +*.eventlog.html +*.eventlog.json +*.hi +*.hp +*.o +*.orig +*.prof +*.root +*~ +.direnv/ +.ghc.environment.* +.shake +.stack-work/ +/.direnv +/.pre-commit-config.yaml +dist-newstyle/ +dump-core/ +hlint.html +result* diff --git a/.hlint.yaml b/.hlint.yaml new file mode 100644 index 0000000..f95c6ca --- /dev/null +++ b/.hlint.yaml @@ -0,0 +1,28 @@ +- extensions: + - name: Haskell2010 + - name: NoCPP + - name: TypeApplications + +- ignore: {name: Move brackets to avoid $} +- ignore: {name: Reduce duplication} +- ignore: {name: Redundant $} +- ignore: {name: Redundant bracket} +- ignore: {name: Redundant do} +- ignore: {name: Redundant lambda} +- ignore: {name: Use camelCase} +- ignore: {name: Use const} +- ignore: {name: Use fmap} +- ignore: {name: Use if} +- ignore: {name: Use import/export shortcut} +- ignore: {name: Use intercalate} +- ignore: {name: Use list literal pattern} +- ignore: {name: Use list literal} +- ignore: {name: Use newtype instead of data} +- ignore: {name: Use null} +- ignore: {name: Use span} +- ignore: {name: Use unless} +- ignore: {name: Use ++} + +# BEGIN: generated hints +- fixity: "infixr 4 " +# END: generated hints diff --git a/.reuse/dep5 b/.reuse/dep5 new file mode 100644 index 0000000..4db55a9 --- /dev/null +++ b/.reuse/dep5 @@ -0,0 +1,13 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: literate-web +Upstream-Contact: Julien Moutinho +Source: https://git.sourcephile.fr/haskell/literate-web + +Files: *.lock cabal.project* *.cabal *.md .chglog/* .envrc + .gitignore .gitmodules .git-blame-ignore-revs *.yaml +Copyright: Julien Moutinho +License: CC0-1.0 + +Files: src/* tests/* Makefile *.nix +Copyright: Julien Moutinho +License: AGPL-3.0-or-later diff --git a/0001-mvc-updates-fix-L.pretraverseM.patch b/0001-mvc-updates-fix-L.pretraverseM.patch new file mode 100644 index 0000000..ad96b88 --- /dev/null +++ b/0001-mvc-updates-fix-L.pretraverseM.patch @@ -0,0 +1,25 @@ +From 1027bf229dc9077c98217ebd632837421d09e98c Mon Sep 17 00:00:00 2001 +From: Julien Moutinho +Date: Sat, 24 Jun 2023 02:35:56 +0200 +Subject: [PATCH] fix L.pretraverseM + +--- + src/MVC/Updates.hs | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/MVC/Updates.hs b/src/MVC/Updates.hs +index 7ad6071..e8ce0fd 100644 +--- a/src/MVC/Updates.hs ++++ b/src/MVC/Updates.hs +@@ -161,7 +161,7 @@ instance Applicative Updatable where + where + f (controllerL, foldL) (controllerR, foldR) = (controllerT, foldT) + where +- foldT = L.pretraverseM _Left foldL <*> L.pretraverseM _Right foldR ++ foldT = L.handlesM _Left foldL <*> L.handlesM _Right foldR + + controllerT = fmap Left controllerL <> fmap Right controllerR + +-- +2.38.4 + diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 0000000..fb85049 --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,3 @@ +## literate-web-0.0.0 (2022-11-12) + +* Initial (pre-alpha) version, released on an unsuspecting world. diff --git a/LICENSES/AGPL-3.0-or-later.txt b/LICENSES/AGPL-3.0-or-later.txt new file mode 100644 index 0000000..0c97efd --- /dev/null +++ b/LICENSES/AGPL-3.0-or-later.txt @@ -0,0 +1,235 @@ +GNU AFFERO GENERAL PUBLIC LICENSE +Version 3, 19 November 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + + Preamble + +The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software. + +A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public. + +The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version. + +An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license. + +The precise terms and conditions for copying, distribution and modification follow. + + TERMS AND CONDITIONS + +0. Definitions. + +"This License" refers to version 3 of the GNU Affero General Public License. + +"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. + +To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. + +A "covered work" means either the unmodified Program or a work based on the Program. + +To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. + +1. Source Code. +The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. + +A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those +subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +2. Basic Permissions. +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +3. Protecting Users' Legal Rights From Anti-Circumvention Law. +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. + +4. Conveying Verbatim Copies. +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. + +5. Conveying Modified Source Versions. +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". + + c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. + +6. Conveying Non-Source Forms. +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + + a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. + + d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. + +7. Additional Terms. +"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or authors of the material; or + + e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. + +All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. + +8. Termination. + +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. + +9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. + +10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. + +11. Patents. + +A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". + +A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. + +12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. + +13. Remote Network Interaction; Use with the GNU General Public License. + +Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph. + +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License. + +14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. + +15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements. + +You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see . diff --git a/LICENSES/CC0-1.0.txt b/LICENSES/CC0-1.0.txt new file mode 100644 index 0000000..0e259d4 --- /dev/null +++ b/LICENSES/CC0-1.0.txt @@ -0,0 +1,121 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1b16ba6 --- /dev/null +++ b/Makefile @@ -0,0 +1,110 @@ +cabal := $(wildcard *.cabal) +package := $(notdir ./$(cabal:.cabal=)) +version := $(shell sed -ne 's/^version: *\(.*\)/\1/p' $(cabal)) +project := $(patsubst %.cabal,%,$(cabal)) +cabal_builddir ?= dist-newstyle + +override REPL_OPTIONS += -ignore-dot-ghci +override TEST_OPTIONS += --color=always +override GHCID_OPTIONS += --no-height-limit --reverse-errors --color=always --warnings --restart $(cabal) + +all: build +build: + cabal build $(CABAL_BUILD_FLAGS) +clean c: + cabal clean +repl: + cabal repl $(CABAL_REPL_FLAGS) $(project) +ghcid: + ghcid $(GHCID_OPTIONS) --command 'cabal repl -fno-code $(CABAL_REPL_FLAGS) $(project) $(addprefix --repl-options ,$(REPL_OPTIONS))' + +.PHONY: tests +t tests: + cabal test $(CABAL_TEST_FLAGS) \ + --test-show-details always --test-options "$(TEST_OPTIONS)" +tests/prof-time: $(project)-tests.eventlog.json +tests/prof-heap: $(project)-tests.eventlog.html +.PHONY: $(project)-test.eventlog +$(project)-test.eventlog $(project)-test.prof: + cabal test $(CABAL_TEST_FLAGS) \ + --test-show-details always --test-options "$(TEST_OPTIONS) +RTS $(RTS_OPTIONS)" \ + --enable-profiling $(addprefix --ghc-options ,$(GHC_PROF_OPTIONS)) || true +t/repl tests/repl: + cabal repl $(CABAL_REPL_FLAGS) $(CABAL_TEST_FLAGS) --enable-tests $(project)-tests +t/ghcid tests/ghcid: + ghcid $(GHCID_OPTIONS) --command 'cabal repl $(CABAL_REPL_FLAGS) $(CABAL_TEST_FLAGS) $(project):tests' --test ":main $(TEST_OPTIONS)" + +.PHONY: benchmarks/time +bt benchmarks/time: + cabal bench $(CABAL_BENCH_FLAGS) time \ + --benchmark-options "$(BENCHMARKS_TIME_OPTIONS)" +.PHONY: benchmarks/weigh +bw benchmarks/weigh: + cabal bench $(CABAL_BENCH_FLAGS) weigh \ + --benchmark-options "$(BENCHMARKS_WEIGH_OPTIONS)" +benchmarks/weigh/ghcid: + ghcid $(GHCID_OPTIONS) --target=relactive --run=':! ghcid $(GHCID_OPTIONS) --target=weigh --run' + +executables/async/ghcid: + ghcid $(GHCID_OPTIONS) --target=relactive --run=':! ghcid $(GHCID_OPTIONS) --target=async --run' +executables/fsnotify/ghcid: + ghcid $(GHCID_OPTIONS) --target=relactive --run=':! ghcid $(GHCID_OPTIONS) --target=fsnotify --run' + + +%/accept: TEST_OPTIONS += --accept +%/accept: % + +%/cover: CABAL_TEST_FLAGS += --enable-coverage +%/cover: % + +%.eventlog.html: RTS_OPTIONS += -hy -l-au +%.eventlog.html: %.eventlog + eventlog2html $< +%.eventlog.json: RTS_OPTIONS += -p -l-au +%.eventlog.json: %.eventlog + hs-speedscope $< + +doc: + cabal haddock --haddock-css ocean --haddock-hyperlink-source + +.PHONY: ChangeLog.md +ChangeLog.md: + ! git tag --merged | grep -Fqx $(package)-$(version) + git diff --exit-code + git tag -f $(package)-$(version) + git-chglog --output $@.new --tag-filter-pattern '$(package)-.*' $(package)-$(version) + touch $@ + cat $@ >>$@.new + mv -f $@.new $@ + git tag -d $(package)-$(version) + git add '$@' + git commit -m 'doc: update `$@`' +tag: build ChangeLog.md + git tag -s -m $(package)-$(version) $(package)-$(version) + +tar: + git diff --exit-code + reuse lint + cabal sdist + cabal haddock --haddock-for-hackage --enable-doc +upload: LANG=C +upload: tar + git tag --merged | grep -Fqx $(package)-$(version) + git push --follow-tags $(GIT_PUSH_FLAGS) + cabal upload $(CABAL_UPLOAD_FLAGS) "$(cabal_builddir)"/sdist/$(package)-$(version).tar.gz + cabal upload $(CABAL_UPLOAD_FLAGS) --documentation "$(cabal_builddir)"/$(package)-$(version)-docs.tar.gz +%/publish: CABAL_UPLOAD_FLAGS+=--publish +%/publish: % + +publish: upload/publish + +.PHONY: .hlint.yaml +.hlint.yaml: $(shell find src -name '*.hs' -not -name 'HLint.hs') + sed -i -e '/^# BEGIN: generated hints/,/^# END: generated hints/d' $@ + echo >>$@ '# BEGIN: generated hints' + hlint --find . | grep -- '- fixity:' | sort -u >>$@ + echo >>$@ '# END: generated hints' +lint: .hlint.yaml + if hlint --quiet --report=hlint.html -XNoCPP $(HLINT_FLAGS) .; \ + then rm -f hlint.html; \ + else sensible-browser ./hlint.html & fi diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000..dc68224 --- /dev/null +++ b/cabal.project @@ -0,0 +1 @@ +packages:. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..539ed95 --- /dev/null +++ b/flake.lock @@ -0,0 +1,121 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1667077288, + "narHash": "sha256-bdC8sFNDpT0HK74u9fUkpbf1MEzVYJ+ka7NXCdgBoaA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "6ee9ebb6b1ee695d2cacc4faa053a7b9baa76817", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1667077288, + "narHash": "sha256-bdC8sFNDpT0HK74u9fUkpbf1MEzVYJ+ka7NXCdgBoaA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "6ee9ebb6b1ee695d2cacc4faa053a7b9baa76817", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1686237827, + "narHash": "sha256-fAZB+Zkcmc+qlauiFnIH9+2qgwM0NO/ru5pWEw3tDow=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "81ed90058a851eb73be835c770e062c6938c8a9e", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1667992213, + "narHash": "sha256-8Ens8ozllvlaFMCZBxg6S7oUyynYx2v7yleC5M0jJsE=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "ebcbfe09d2bd6d15f68de3a0ebb1e4dcb5cd324b", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "pre-commit-hooks_2": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "symantic-base", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1667992213, + "narHash": "sha256-8Ens8ozllvlaFMCZBxg6S7oUyynYx2v7yleC5M0jJsE=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "ebcbfe09d2bd6d15f68de3a0ebb1e4dcb5cd324b", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks", + "symantic-base": "symantic-base" + } + }, + "symantic-base": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "pre-commit-hooks": "pre-commit-hooks_2" + }, + "locked": { + "lastModified": 1670713703, + "narHash": "sha256-9U71SGSWzdFbrvCyo6IbNI8bhoM4Guz9nCGIqKJ7ttQ=", + "ref": "refs/heads/main", + "rev": "6ce5a7f09fd4bc5bc7df3fd4bf797e8f1803cd88", + "revCount": 81, + "type": "git", + "url": "git://git.sourcephile.fr/haskell/symantic-base" + }, + "original": { + "type": "git", + "url": "git://git.sourcephile.fr/haskell/symantic-base" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7616819 --- /dev/null +++ b/flake.nix @@ -0,0 +1,66 @@ +{ + inputs = { + nixpkgs.url = "flake:nixpkgs"; + #nixpkgs.url = "github:NixOS/nixpkgs/cdead16a444a3e5de7bc9b0af8e198b11bb01804"; + pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs"; + symantic-base.url = "git://git.sourcephile.fr/haskell/symantic-base"; + symantic-base.inputs.nixpkgs.follows = "nixpkgs"; + }; + outputs = inputs: + let + pkg = "literate-web"; + lib = inputs.nixpkgs.lib; + forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec { + inherit system; + pkgs = inputs.nixpkgs.legacyPackages.${system}; + haskellPackages = pkgs.haskellPackages.extend (with pkgs.haskell.lib; hfinal: hsuper: { + ${pkg} = doBenchmark (buildFromSdist (hfinal.callCabal2nix pkg ./. { })); + symantic-base = buildFromSdist (hfinal.callCabal2nix "symantic-base" inputs.symantic-base { }); + #url-slug = buildFromSdist (hfinal.callCabal2nix "url-slug" inputs.url-slug { }); + doctest = dontCheck (doJailbreak (unmarkBroken hsuper.doctest)); + hspec-contrib = dontCheck (doJailbreak (unmarkBroken hsuper.hspec-contrib)); + #relude = dontCheck (doJailbreak (unmarkBroken hsuper.relude)); + scotty = dontCheck (doJailbreak (unmarkBroken hsuper.scotty)); + }); + }); + in + rec { + # nix -L build + defaultPackage = forAllSystems ({ haskellPackages, ... }: haskellPackages.${pkg}); + # nix -L develop or direnv allow + devShell = forAllSystems ({ pkgs, haskellPackages, system, ... }: + haskellPackages.shellFor { + packages = ps: [ ps.${pkg} ]; + nativeBuildInputs = [ + haskellPackages.cabal-install + haskellPackages.ghcid + haskellPackages.haskell-language-server + haskellPackages.hlint + #haskellPackages.stan + pkgs.git-chglog + pkgs.reuse + ]; + withHoogle = false; + doBenchmark = true; + inherit (checks.${system}.pre-commit-check) shellHook; + }); + # nix flake check + checks = forAllSystems (args: with args; { + pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run { + src = ./.; + #settings.ormolu.cabalDefaultExtensions = true; + settings.ormolu.defaultExtensions = [ + "ImportQualifiedPost" + "TypeApplications" + ]; + hooks = { + hlint.enable = true; + nixpkgs-fmt.enable = true; + fourmolu.enable = true; + cabal-fmt.enable = true; + }; + }; + }); + }; +} diff --git a/fourmolu.yaml b/fourmolu.yaml new file mode 100644 index 0000000..1fc42af --- /dev/null +++ b/fourmolu.yaml @@ -0,0 +1,8 @@ +comma-style: leading +diff-friendly-import-export: true +haddock-style: single-line +indent-wheres: true +indentation: 2 +newlines-between-decls: 1 +record-brace-space: false +respectful: true diff --git a/literate-web.cabal b/literate-web.cabal new file mode 100644 index 0000000..26af39d --- /dev/null +++ b/literate-web.cabal @@ -0,0 +1,240 @@ +cabal-version: 3.0 +name: literate-web +maintainer: mailto:literate-web@sourcephile.fr +bug-reports: https://mails.sourcephile.fr/inbox/literate-web +homepage: https://git.sourcephile.fr/literate-web.git +author: Julien Moutinho +copyright: Julien Moutinho +license: AGPL-3.0-or-later +license-file: LICENSES/AGPL-3.0-or-later.txt + +-- PVP: +-+------- breaking API changes +-- | | +----- non-breaking API additions +-- | | | +--- code changes with no API change +version: 0.0.0.20221117 +stability: experimental +category: Web +synopsis: Haskell-website compiler +description: + Exploring the design space of compile-time website generator + by using a domain-specific language (DSL) + embedded into the Haskell language. + . + Alternatives: + . + * + +build-type: Simple +tested-with: GHC ==9.2.4 +extra-doc-files: ChangeLog.md +extra-source-files: + .envrc + cabal.project + flake.lock + flake.nix + +extra-tmp-files: + +source-repository head + type: git + location: git://git.sourcephile.fr/haskell/literate-web.git + +common boilerplate + default-language: Haskell2010 + default-extensions: + NoImplicitPrelude + BlockArguments + DataKinds + DefaultSignatures + DeriveDataTypeable + DeriveGeneric + DerivingVia + FlexibleContexts + FlexibleInstances + GADTs + ImportQualifiedPost + LambdaCase + MultiParamTypeClasses + NamedFieldPuns + NumericUnderscores + OverloadedStrings + RecordWildCards + ScopedTypeVariables + TupleSections + TypeApplications + TypeFamilies + TypeOperators + + ghc-options: + -Wall -Wincomplete-record-updates -Wincomplete-uni-patterns + -Wmonomorphism-restriction -Wpartial-fields + -fprint-potential-instances + +-- -dshow-passes +-- -ddump-to-file +-- -ddump-simpl +-- -dsuppress-coercions +-- -dsuppress-module-prefixes +-- -dsuppress-type-applications +-- -O0 +-- -fmax-simplifier-iterations=0 + +common library-deps + build-depends: + , async >=2.2 + , base >=4.6 && <5 + , bytestring >=0.10 + , containers >=0.5 + , directory >=1.3 + , filepath >=1.4 + , filepattern >=0.1 + , hashable + , http-client >=0.6 + , http-media >=0.7 + , monad-classes + , peano + , reflection + , symantic-base >=0.5 + , template-haskell + , text + , transformers >=0.5 + , unicode-transforms >=0.2 + , unordered-containers + , uri-encode >=1.5 + , wai + , wai-middleware-static + , wai-websockets + , warp + , websockets >=0.12 + +library + import: boilerplate, library-deps + hs-source-dirs: src + exposed-modules: + Literate.Web + Literate.Web.Semantics.Compiler + Literate.Web.Syntaxes + Literate.Web.Types.MIME + Literate.Web.Types.URL + +library relactive + import: boilerplate, library-deps + hs-source-dirs: src + build-depends: + , async + , contravariant >=1.5 + , stm + + exposed-modules: + Control.Reactive + Control.Reactive.IORef + Control.Reactive.MVar + Control.Reactive.Relation + Control.Reactive.STRef + Control.Reactive.TVar + Control.Reactive.Value + +-- Literate.Web.Semantics.Server +-- Literate.Web.Semantics.Client +--Literate.Web.Decoder +--Literate.Web.Encoder +--Literate.Web.Generator +--Literate.Web.MIME + +--Literate.Web.Decoder +test-suite literate-web-tests + -- library-deps is only to have ghcid reloaded on changes in src + import: boilerplate, library-deps + type: exitcode-stdio-1.0 + hs-source-dirs: tests + main-is: Main.hs + other-modules: + Examples.Ex01 + Examples.Ex02 + Examples.Ex03 + Examples.Ex04 + Examples.Ex05 + Goldens + Paths_literate_web + Utils + + -- Examples.Ex02 + --HUnits + autogen-modules: Paths_literate_web + build-depends: + , base >=4.6 && <5 + , containers >=0.5 + , literate-web + , monad-classes + , relude + , symantic-base >=0.5 + , tasty >=0.11 + , tasty-golden >=2.3 + , tasty-hunit >=0.9 + , text >=1.2 + , transformers >=0.5 + +-- , relude >=1 && <2 +benchmark time + import: boilerplate, library-deps + type: exitcode-stdio-1.0 + hs-source-dirs: benchmarks/time + main-is: Main.hs + build-depends: + , base >=4.6 && <5 + , relactive + , tasty + , tasty-bench + + -- , relude >= 1 + -- Set a larger allocation area (nursery) + -- to remove some noisiness of the garbage collection. + ghc-options: -with-rtsopts=-A32m + +benchmark weigh + import: boilerplate, library-deps + type: exitcode-stdio-1.0 + hs-source-dirs: benchmarks/weigh src + build-depends: + , async + , contravariant >=1.5 + , stm + + main-is: Main.hs + build-depends: + , base >=4.6 && <5 + , relude >=1 + , weigh + +--, relactive +executable async + import: boilerplate, library-deps + hs-source-dirs: executables/async + main-is: Main.hs + build-depends: + , async + , base >=4.6 && <5 + , relactive + , relude + , symantic-base + , tasty + , tasty-bench + +-- , relude >= 1 + +executable fsnotify + import: boilerplate, library-deps + hs-source-dirs: executables/fsnotify + main-is: Main.hs + build-depends: + , async + , base >=4.6 && <5 + , directory + , filepath + , fsnotify + , relactive + , relude >=1 + , symantic-base + , tasty + , tasty-bench + , time diff --git a/src/Literate/Web.hs b/src/Literate/Web.hs new file mode 100644 index 0000000..f3ca207 --- /dev/null +++ b/src/Literate/Web.hs @@ -0,0 +1,11 @@ +module Literate.Web ( + module Literate.Web.Semantics.Compiler, + module Literate.Web.Syntaxes, + module Literate.Web.Types.MIME, + module Literate.Web.Types.URL, +) where + +import Literate.Web.Semantics.Compiler +import Literate.Web.Syntaxes +import Literate.Web.Types.MIME +import Literate.Web.Types.URL diff --git a/src/Literate/Web/Semantics/Compiler.hs b/src/Literate/Web/Semantics/Compiler.hs new file mode 100644 index 0000000..6658d64 --- /dev/null +++ b/src/Literate/Web/Semantics/Compiler.hs @@ -0,0 +1,446 @@ +-- For Output +{-# LANGUAGE DeriveFunctor #-} + +module Literate.Web.Semantics.Compiler where + +import Control.Applicative (Applicative (..)) +import Control.Monad (Monad (..), forM, forM_, join, sequence, (>=>)) +import Control.Monad.Classes qualified as MC +import Control.Monad.Trans.Class qualified as MT +import Control.Monad.Trans.Reader qualified as MT +import Data.Bool +import Data.ByteString.Lazy qualified as BSL +import Data.Either (Either (..)) +import Data.Eq (Eq (..)) +import Data.Foldable (toList) +import Data.Function (const, id, ($), (.)) +import Data.Functor (Functor (..), (<$>)) +import Data.Kind (Constraint, Type) +import Data.List qualified as List +import Data.Maybe (Maybe (..)) +import Data.Ord (Ord (..)) +import Data.Proxy (Proxy (..)) +import Data.Semigroup (Semigroup (..)) +import Data.String (fromString) +import Data.Text (Text) +import Data.Text qualified as Text +import Data.Tuple (curry) +import GHC.Generics (Generic) +import GHC.Stack (HasCallStack) +import Literate.Web.Syntaxes +import Literate.Web.Types.MIME +import Literate.Web.Types.URL +import Symantic qualified as Sym +import System.Directory qualified as Sys +import System.FilePath qualified as Sys +import System.FilePattern.Directory qualified as Sys +import System.IO qualified as Sys +import Text.Show (Show (..)) +import Type.Reflection ((:~:) (..)) + +-- * Type 'Compiler' +newtype Compiler m a = Compiler {unCompiler :: m [Output a]} + deriving (Functor) + +compile :: + MC.MonadExec Sys.IO m => + CompilerEnv -> + Sym.ToFer (Compiler m) a -> + Sym.ToF a (m BSL.ByteString) -> + m () +compile CompilerEnv{..} router content = do + outputs <- unCompiler $ Sym.tuplesOfFunctions router content + MC.exec @Sys.IO $ Sys.removePathForcibly compilerEnvDest + forM_ outputs $ \Output{..} -> do + let destPath = + ( List.intercalate "." $ + encodePath outputPath : + ( if List.null outputExts + then ["txt"] + else Text.unpack . encodePathSegment <$> outputExts + ) + ) + -- hPutStrLn stderr $ "mkdir: " <> show (Sys.takeDirectory destPath) + MC.exec @Sys.IO $ + Sys.createDirectoryIfMissing True $ + compilerEnvDest Sys. Sys.takeDirectory destPath + -- hPutStrLn stderr $ "write: " <> show destPath + bsl <- outputData + MC.exec @Sys.IO $ + BSL.writeFile (compilerEnvDest Sys. destPath) $ + bsl + +manifest :: + forall m a. + Monad m => + Sym.ToFer (Compiler m) a -> + Sym.ToF a (m BSL.ByteString) -> + m [Sys.FilePath] +manifest router content = do + outputs <- unCompiler $ Sym.tuplesOfFunctions router content + forM outputs $ \(Output{..} :: Output (m BSL.ByteString)) -> do + let destPath = + ( List.intercalate "." $ + encodePath outputPath : + ( if List.null outputExts + then ["txt"] + else Text.unpack . encodePathSegment <$> outputExts + ) + ) + return destPath + +instance Applicative m => Applicative (Compiler m) where + pure = Compiler . pure . pure . pure + liftA2 f (Compiler a) (Compiler b) = Compiler (liftA2 (liftA2 (liftA2 f)) a b) +instance Monad m => Monad (Compiler m) where + return = pure + Compiler mloa >>= a2mlob = + Compiler $ do + mloa >>= \loa -> + (join <$>) $ + forM loa $ \oa -> do + lob <- unCompiler $ a2mlob $ outputData oa + forM lob $ \ob -> + return + ob + { outputPath = outputPath oa <> outputPath ob + , outputExts = outputExts oa <> outputExts ob + } +instance Applicative m => Sym.ProductFunctor (Compiler m) where + (<.>) = liftA2 (,) + (<.) = liftA2 const + (.>) = liftA2 (const id) +instance Applicative m => Sym.AlternativeFunctor (Compiler m) where + Compiler a <|> Compiler b = Compiler (liftA2 (<>) a b) +instance Applicative m => Sym.SumFunctor (Compiler m) where + a <+> b = Left <$> a Sym.<|> Right <$> b +instance Applicative m => Sym.Optionable (Compiler m) where + optional ma = pure Nothing Sym.<|> (Just <$> ma) +instance Applicative m => PathSegmentable (Compiler m) where + pathSegment s = Compiler $ pure [Output{outputPath = [s], outputExts = [], outputData = ()}] +instance + ( Show a + , Monad m + , n ~ m + , MimeTypes ts (MimeEncodable a) + ) => + Responsable a ts n (m BSL.ByteString) (Sym.ToFer (Compiler m)) + where + response = + Sym.ToFer + { tuplesOfFunctions = \(Refl, Response ma) -> + Compiler $ do + a <- ma + pure $ + ( \(mt, MimeType (Proxy :: Proxy t)) -> + Output + { outputPath = [] + , outputExts = [decodePathSegment (fileExtension @t)] + , outputData = pure $ mimeEncode @_ @t a + } + ) + <$> toList (mimeTypesMap @ts @(MimeEncodable a)) + , eithersOfTuples = Compiler $ pure [] + } + +-- ** Type 'CompilerEnv' +data CompilerEnv = CompilerEnv + { compilerEnvDest :: Sys.FilePath + , -- , compilerEnvSource :: Sys.FilePath + compilerEnvIndex :: Sys.FilePath + --, compilerEnvModel :: model + -- , compilerEnvPath :: [PathSegment] + } + deriving (Show) + +-- ** Type 'Output' +data Output a = Output + { outputPath :: [PathSegment] + , outputExts :: [PathSegment] + , outputData :: a + -- , outputType :: MimeType (MimeEncodable a) + } + deriving (Functor, Show) +instance Applicative Output where + pure a = + Output + { outputPath = [] + , outputExts = [] + , outputData = a + -- , outputType = mediaType @PlainText + } + oa2b <*> oa = + Output + { outputPath = outputPath oa2b <> outputPath oa + , outputExts = outputExts oa2b <> outputExts oa + , outputData = outputData oa2b (outputData oa) + -- , outputType = outputType f <> outputType x + } + +-- -- pathSegments _ss = Compiler $ +-- -- MT.ReaderT $ \s -> +-- -- -- TODO: assert Set.member s ss +-- -- lift $ +-- -- MT.modify' $ \st -> +-- -- st{compilerStatePath = compilerStatePath st Text.unpack (encodePathSegment s)} +-- +-- {- +-- instance +-- TypeError ( +-- 'Text "The instance (Capturable a Compiler)" +-- ':$$: 'Text "is disabled when compiling to a static Web site." +-- ':$$: 'Text "You can use (whenInterpreter @Compiler siteNotUsingCapturable siteUsingCapturable)" +-- ':$$: 'Text "to replace calls to any method of Capturable." +-- ) => Capturable a Compiler where +-- capturePathSegment = undefined +-- instance +-- TypeError ( +-- 'Text "The instance (Capturable a (Reader model Compiler))" +-- ':$$: 'Text "is disabled when compiling to a static Web site." +-- ':$$: 'Text "You can use (whenInterpreter @(Reader model Compiler) siteNotUsingCapturable siteUsingCapturable)" +-- ':$$: 'Text "to replace calls to any method of Capturable." +-- ) => Capturable a (Reader model Compiler) where +-- capturePathSegment = undefined +-- -} +-- +-- -- choosePathSegments _s = Compiler $ MT.ReaderT $ \s -> return $ Endo (List.reverse s <>) +-- {- +-- instance Capturable Compiler where +-- type CapturableConstraint Compiler = +-- capturePathSegment _n = Compiler $ MT.ReaderT $ \s -> +-- lift $ MT.modify' $ \st -> +-- st{compilerStatePath = compilerStatePath st Text.unpack (encodePathSegment s)} +-- -} +-- {- +-- instance Copyable Compiler where +-- copy path = Compiler $ +-- lift $ +-- MT.ReaderT $ \env -> do +-- lift $ do +-- doesPathExist (compilerEnvSource env path) >>= \case +-- True -> do +-- Sys.hPutStrLn Sys.stderr $ +-- "staticCopy: " +-- <> show +-- ( (compilerEnvSource env path) +-- , (compilerEnvDest env path) +-- ) +-- copyDirRecursively +-- path +-- (compilerEnvSource env path) +-- (compilerEnvDest env) +-- False -> do +-- Sys.hPutStrLn Sys.stderr $ "error: path does not exist: " <> (compilerEnvSource env path) +-- instance Encodable fmt a => Contentable fmt a Compiler where +-- content = Compiler $ +-- MT.ReaderT $ \a -> MT.ReaderT $ \env -> do +-- st <- MT.get +-- let destPath = compilerEnvDest env compilerStatePath st +-- lift $ do +-- -- Sys.hPutStrLn Sys.stderr $ "mkdir: " <> show (Sys.takeDirectory destPath) +-- createDirectoryIfMissing True (Sys.takeDirectory destPath) +-- -- Sys.hPutStrLn Sys.stderr $ "write: " <> show destPath +-- BSL.writeFile destPath $ encode @fmt a +-- -} +-- --instance Endable Compiler where +-- -- end = Compiler $ return $ Endo id +-- +-- --pathSegments _cs = Compiler $ MT.ReaderT $ \s -> return $ Endo (s :) +-- -- instance Fileable Compiler where +-- -- type FileableConstraint Compiler = Typeable +-- -- static = Compiler $ MT.ReaderT $ \_a -> +-- -- return $ Endo (\x -> x) +-- +-- {- +-- -- * The 'Compiler' interpreter +-- +-- -- | Create files according to the given model of type 'a'. +-- newtype Compiler a = Compiler +-- { unCompiler :: [Comp a] +-- } +-- deriving (Show, Functor) +-- +-- instance Applicative Compiler where +-- pure = Compiler . pure . pure +-- Compiler f <*> Compiler x = Compiler $ (<*>) <$> f <*> x +-- +-- -- instance Monad Compiler where +-- -- return = pure +-- -- Compiler x >>= f = Compiler (x >>=) +-- +-- compile :: Show a => Renderable a => Compiler a -> CompilerEnv -> Sys.IO () +-- compile compiler conf@CompilerEnv{..} = do +-- createDirectoryIfMissing True compilerEnvDest +-- let router = unCompiler compiler +-- when (null router) $ +-- error "no router, nothing to compile" +-- -- Sys.hPutStrLn Sys.stderr $ "conf: " <> show conf +-- -- forM_ router $ \comp -> do +-- -- Sys.hPutStrLn Sys.stderr $ "route: " <> show comp +-- forM_ router $ \Comp{..} -> do +-- -- Sys.hPutStrLn Sys.stderr $ "route: " <> show comp +-- let routePath = pathOfPathSegments compPathSegments +-- in case render compData of +-- Left staticPath -> +-- doesPathExist (compilerEnvSource staticPath) >>= \case +-- True -> do +-- -- TODO: In current branch, we don't expect this to be a directory. +-- -- Although the user may pass it, but review before merge. +-- Sys.hPutStrLn Sys.stderr $ +-- "staticCopy: " +-- <> show +-- ( (compilerEnvSource staticPath) +-- , (compilerEnvDest staticPath) +-- ) +-- copyDirRecursively +-- staticPath +-- (compilerEnvSource staticPath) +-- (compilerEnvDest) +-- False -> do +-- Sys.hPutStrLn Sys.stderr $ "error: path does not exist: " <> (compilerEnvSource staticPath) +-- -- log LevelWarn $ toText $ "? " <> staticPath <> " (missing)" +-- Right bs -> do +-- let destPath = compilerEnvDest routePath +-- {- +-- maybe (routePath compilerEnvIndex) +-- (routePath Sys.FilePath.<.>) +-- (compType comp) +-- -} +-- -- Sys.hPutStrLn Sys.stderr $ "mkdir: " <> show (Sys.takeDirectory destPath) +-- createDirectoryIfMissing True (Sys.takeDirectory destPath) +-- -- Sys.hPutStrLn Sys.stderr $ "write: " <> show destPath +-- BSL.writeFile destPath bs +-- +-- -- ** Class 'Renderable' +-- class Renderable a where +-- render :: a -> Either Sys.FilePath BSL.ByteString +-- instance Renderable () where +-- render () = +-- --Left $ pathOfPathSegments compPathSegments +-- Right BSL.empty +-- +-- -- ** Type 'Comp' +-- data Comp a = Comp +-- { compPathSegments :: [PathSegment] -- TODO: Endo? Seq? +-- , compData :: a +-- -- , compType :: MimeType (MimeEncodable a) +-- } +-- deriving instance Eq a => Eq (Comp a) +-- deriving instance Ord a => Ord (Comp a) +-- deriving instance Show a => Show (Comp a) +-- deriving instance Functor Comp +-- instance Applicative Comp where +-- pure compData = +-- Comp +-- { compPathSegments = [] +-- , compData +-- -- , compType = mediaType @PlainText +-- } +-- f <*> x = +-- Comp +-- { compPathSegments = compPathSegments f <> compPathSegments x +-- , compData = compData f (compData x) +-- -- , compType = compType f <> compType x +-- } +-- +-- instance IsoFunctor Compiler where +-- (<%>) Iso{..} = (a2b <$>) +-- instance ProductFunctor Compiler where +-- (<.>) = liftA2 (,) +-- (<.) = (<*) +-- (.>) = (*>) +-- instance SumFunctor Compiler where +-- x <+> y = +-- Compiler $ +-- (<>) +-- ((Left <$>) <$> unCompiler x) +-- ((Right <$>) <$> unCompiler y) +-- instance Optionable Compiler where +-- optional x = +-- Compiler $ +-- Comp { compPathSegments = [] +-- , compData = Nothing +-- -- , compType = Nothing +-- } : +-- ((Just <$>) <$> unCompiler x) +-- instance PathSegmentable Compiler where +-- pathSegment s = Compiler +-- [ +-- Comp +-- { compPathSegments = [s] +-- , compData = () +-- -- , compType = PlainText +-- } +-- ] +-- pathSegments ss = +-- Compiler $ +-- [ Comp{ compPathSegments = [s] +-- , compData = s +-- -- , compType = Nothing +-- } +-- | s <- toList ss +-- ] +-- instance ContentTypeable PlainText () Compiler where +-- contentType = +-- Compiler +-- [ Comp +-- { compPathSegments = [] +-- , compData = () +-- --, compType = mediaType @PlainText +-- } +-- ] +-- +-- -- instance Repeatable Compiler where +-- -- many0 (Compiler x) = +-- -- Compiler $ +-- -- ((\Comp{} -> Comp [] []) <$> x) +-- -- <> ((\(Comp s a) -> Comp s [a]) <$> x) +-- -- <> ((\(Comp s a) -> Comp (s <> s) [a, a]) <$> x) +-- -- many1 (Compiler x) = +-- -- Compiler $ +-- -- ((\(Comp s a) -> Comp s [a]) <$> x) +-- -- <> ((\(Comp s a) -> Comp (s <> s) [a, a]) <$> x) +-- -- instance Endable Compiler where +-- -- end = Compiler [Comp [] ()] +-- -- instance Capturable Compiler where +-- -- capturePathSegment n = Compiler $ [Comp [n] n] +-- -- instance Constantable c Compiler where +-- -- constant = pure +-- -} +-- +copyDirRecursively :: + ( --MonadIO m, + --MonadUnliftIO m, + --MonadLoggerIO m, + HasCallStack + ) => + -- | Source file path relative to CWD + Sys.FilePath -> + -- | Absolute path to source file to copy. + Sys.FilePath -> + -- | Directory *under* which the source file/dir will be copied + Sys.FilePath -> + Sys.IO () +copyDirRecursively srcRel srcAbs destParent = do + Sys.doesFileExist srcAbs >>= \case + True -> do + Sys.hPutStrLn Sys.stderr $ "copyDirRecursively: " <> show ("srcAbs is a file", srcAbs) + copyFileCreatingParents srcAbs (destParent Sys. srcRel) + False -> + Sys.doesDirectoryExist srcAbs >>= \case + False -> do + Sys.hPutStrLn Sys.stderr $ "copyDirRecursively: " <> show ("srcAbs is neither a file nor directory", srcAbs) + return () + -- throw $ StaticAssetMissing srcAbs + True -> do + Sys.hPutStrLn Sys.stderr $ "copyDirRecursively: " <> show ("srcAbs is a directory", srcAbs) + Sys.createDirectoryIfMissing True (destParent Sys. srcRel) + fs <- Sys.getDirectoryFiles srcAbs ["**"] + forM_ fs $ \fp -> do + let a = srcAbs Sys. fp + b = destParent Sys. srcRel Sys. fp + copyFileCreatingParents a b + where + copyFileCreatingParents a b = do + Sys.createDirectoryIfMissing True (Sys.takeDirectory b) + Sys.copyFile a b diff --git a/src/Literate/Web/Semantics/Server.hs b/src/Literate/Web/Semantics/Server.hs new file mode 100644 index 0000000..d19d3a4 --- /dev/null +++ b/src/Literate/Web/Semantics/Server.hs @@ -0,0 +1,274 @@ +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE UndecidableInstances #-} +{-# OPTIONS_GHC -Wno-orphans #-} + +module Literate.Web.Semantics.Server where + +import Control.Applicative (Applicative (..)) +import Control.Monad (Monad (..)) +import Control.Monad.Trans.Class qualified as MT +import Control.Monad.Trans.Except qualified as MT +import Control.Monad.Trans.Reader qualified as MT +import Control.Monad.Trans.State qualified as MT +import Data.Bifunctor (first) +import Data.Bool +import Data.ByteString.Lazy qualified as BSL +import Data.Either (Either (..)) +import Data.Eq (Eq (..)) +import Data.Foldable (null) +import Data.Function (($), (.)) +import Data.Functor (Functor, (<$>)) +import Data.List qualified as List +import Data.Maybe (Maybe (..)) +import Data.Ord (Ord) +import Data.Semigroup (Semigroup (..)) +import Data.Set (Set) +import Data.Set qualified as Set +import Data.Text qualified as Text +import Data.Text.Encoding qualified as Text +import Data.Text.Encoding.Error qualified as Text + +-- import Data.Text.Lazy qualified as TextL +-- import Data.Text.Lazy.Encoding qualified as TextL +import Symantic.Syntaxes (Iso (..), IsoFunctor ((<%>)), Optionable (..), ProductFunctor (..), SumFunctor ((<+>))) +import System.IO (IO) +import Text.Show (Show (..)) + +-- import Network.Wai qualified as Wai + +-- import Prelude (undefined) + +import Literate.Web.Syntaxes +import Literate.Web.Types.MIME +import Literate.Web.Types.URL + +-- * The 'Server' interpreter + +-- | A very very basic parser. +newtype Server model err a = Server + { unServer :: + MT.ReaderT + (ServerEnv model) + ( MT.StateT + ServerState + (MT.ExceptT (ServerError err) IO) + ) + a + } + deriving (Functor, Applicative, Monad) + +data ServerEnv model = ServerEnv + { serverEnvRequest :: Request + , serverEnvModel :: model + } + +-- ** Type 'Request' +data Request = Request + { requestPathSegments :: [PathSegment] + , requestBody :: BSL.ByteString + } + +{- +data Servers err a = Servers + { serversPath :: [PathSegment] -> a + , serversMethod :: [PathSegment] -> Bool + --, serversBasicAuth :: + , serversAccept :: Bool + , serversContentType :: Bool + , serversQuery :: Bool + , serversHeader :: Bool + , serversBody :: BSL.ByteString -> a + } +-} + +data ServerState = ServerState + { serverStatePathSegments :: [PathSegment] + } + +decode :: Server err a -> Request -> IO (Either (ServerError err) a) +decode (Server dec) req = + MT.runExceptT (MT.runStateT (MT.runReaderT dec req) st) >>= \case + Left err -> return $ Left err + Right (a, ServerState{..}) + | null serverStatePathSegments -> return $ Right a + | otherwise -> return $ Left $ ServerErrorPathLeftover serverStatePathSegments + where + st = + ServerState + { serverStatePathSegments = requestPathSegments req + } + +data ServerError err + = -- 1st checks, 404 error + ServerErrorPathMismatch + { expectedPathSegments :: Set PathSegment + , gotPathSegment :: PathSegment + } + | ServerErrorPathMissing + | ServerErrorPathLeftover [PathSegment] + | -- 2nd check, 405 error + ServerErrorMethod + | -- 3rd check, 401 or 403 error + ServerErrorBasicAuth + | -- 4th check, 406 error + ServerErrorAccept + | -- 5th check, 415 error + ServerErrorContentType + | -- 6th check, 400 error + ServerErrorQuery + | -- 7th check, 400 error + ServerErrorHeader + | -- 8th check, 400 error + ServerErrorUnicode Text.UnicodeException + | -- 9th check, custom + ServerErrorParser err + deriving (Eq, Show) +deriving instance Ord Text.UnicodeException + +instance IsoFunctor (Server err) where + (<%>) Iso{..} = (a2b <$>) +instance ProductFunctor (Server err) where + (<.>) = liftA2 (,) + (<.) = (<*) + (.>) = (*>) +instance SumFunctor (Server err) where + Server x <+> Server y = Server $ + MT.ReaderT $ \env -> MT.StateT $ \st -> do + MT.lift (MT.runExceptT (MT.runStateT (MT.runReaderT x env) st)) >>= \case + Right (a, st') -> return (Left a, st') + Left _err -> + -- TODO: better error merging + MT.lift (MT.runExceptT (MT.runStateT (MT.runReaderT y env) st)) >>= \case + Right (b, st') -> return (Right b, st') + Left err -> MT.throwE err + +-- instance Endable (Server err) where +-- end = Server do +-- MT.lift (MT.gets serverStatePathSegments) >>= \case +-- [] -> return () +-- lo -> MT.lift $ MT.lift $ MT.throwE $ ServerErrorPathLeftover lo +instance Repeatable (Server err) where + many0 (Server x) = Server (MT.ReaderT (MT.StateT . go)) + where + go env st = do + MT.lift (MT.runExceptT (MT.runStateT (MT.runReaderT x env) st)) >>= \case + Left _err -> return ([], st) -- always backtrack + Right (a, st') -> first (a :) <$> go env st' + many1 x = (:) <$> x <*> many0 x +instance Optionable (Server err) where + optional (Server x) = Server $ + MT.ReaderT $ \env -> MT.StateT $ \st -> do + MT.lift (MT.runExceptT (MT.runStateT (MT.runReaderT x env) st)) >>= \case + Left{} -> return (Nothing, st) + Right (a, st') -> return (Just a, st') +instance PathSegmentable (Server err) where + pathSegment expectedPathSegment = Server $ do + ps <- MT.lift (MT.gets serverStatePathSegments) + case ps of + [] -> MT.lift $ MT.lift $ MT.throwE ServerErrorPathMissing + gotPathSegment : nextPathSegments + | expectedPathSegment /= gotPathSegment -> + MT.lift $ MT.lift $ MT.throwE ServerErrorPathMismatch{expectedPathSegments = Set.singleton expectedPathSegment, ..} + | otherwise -> + MT.local (\req -> req{requestPathSegments = requestPathSegments req <> [gotPathSegment]}) $ + MT.lift $ + MT.modify' $ + \st -> st{serverStatePathSegments = nextPathSegments} + +-- choosePathSegment expectedPathSegments = Server $ do +-- ps <- MT.lift (MT.gets serverStatePathSegments) +-- case ps of +-- [] -> MT.lift $ MT.lift $ MT.throwE ServerErrorPathMissing +-- gotPathSegment : nextPathSegments +-- | gotPathSegment `Set.notMember` expectedPathSegments -> +-- MT.lift $ MT.lift $ MT.throwE ServerErrorPathMismatch{expectedPathSegments, ..} +-- | otherwise -> do +-- MT.local (\req -> req{requestPathSegments = requestPathSegments req <> [gotPathSegment]}) $ +-- MT.lift $ MT.modify' $ \st -> st{serverStatePathSegments = nextPathSegments} +-- return gotPathSegment +{- +instance ContentTypeable PlainText BSL.ByteString (Server err) where + contentType = Server do + Request{..} <- MT.ask + return requestBody +instance ContentTypeable PlainText Text.Text (Server err) where + contentType = Server do + Request{..} <- MT.ask + case Text.decodeUtf8' (BSL.toStrict requestBody) of + Right a -> return a + Left err -> MT.lift $ MT.lift $ MT.throwE $ ServerErrorUnicode err +-} + +-- choosePathSegments = undefined +-- choosePathSegments expectedPathSegments = Server $ do +-- ps <- MT.lift MT.get +-- case ps of +-- [] -> MT.lift $ MT.lift $ MT.throwE ServerErrorPathMissing +-- gotPathSegment : nextPathSegments +-- | gotPathSegment `Set.member` expectedPathSegments -> +-- MT.lift $ MT.lift $ MT.throwE $ ServerErrorPathMismatch{expectedPathSegments, ..} +-- | otherwise -> do +-- MT.local (<> [gotPathSegment]) $ +-- MT.lift $ MT.put nextPathSegments +-- return gotPathSegment +instance Capturable PathSegment (Server err) where + capturePathSegment _name = Server $ do + ps <- MT.lift (MT.gets serverStatePathSegments) + case ps of + [] -> MT.lift $ MT.lift $ MT.throwE ServerErrorPathMissing + gotPathSegment : nextPathSegments -> + MT.local (\req -> req{requestPathSegments = requestPathSegments req <> [gotPathSegment]}) do + MT.lift $ MT.modify' $ \st -> st{serverStatePathSegments = nextPathSegments} + return gotPathSegment + +-- choosePathSegment expectedPathSegments = Server $ do +-- ps <- MT.lift MT.get +-- case ps of +-- [] -> MT.lift $ MT.lift $ MT.throwE ServerErrorPathMissing +-- gotPathSegment : nextPathSegments +-- | gotPathSegment `Set.member` expectedPathSegments -> +-- MT.lift $ MT.lift $ MT.throwE $ ServerErrorPathMismatch{..} +-- | otherwise -> do +-- MT.local (<> [gotPathSegment]) $ +-- MT.lift $ MT.put nextPathSegments +-- return gotPathSegment +{- +instance Selectable (Server err) where + select ra a2bs = do + a <- ra + case Map.lookup a a2bs of + Nothing -> + Server $ MT.lift $ MT.lift $ MT.throwE + ServerErrorPathMissing -- FIXME + where + go a [] = Server $ + MT.lift $ MT.lift $ MT.throwE + ServerErrorPathMissing -- FIXME + go a ((ca, x):xs) = Server $ + MT.ReaderT $ \env -> MT.StateT $ \st -> do + MT.lift (MT.runExceptT (MT.runStateT (MT.runReaderT (unServer x) env) st)) >>= \case + Right r -> return r + Left _err -> + MT.runStateT (MT.runReaderT (unServer (choose ra xs)) env) st +-} +instance Fileable (Server err) where + type FileableConstraint (Server err) = Parsable err + static = Server do + return () + dynamic = Server do + Request{..} <- MT.ask + content <- + MT.lift $ + MT.lift $ + MT.lift $ + BSL.readFile $ + List.intercalate "/" $ + Text.unpack . encodePathSegment <$> requestPathSegments + case parse content of + Right a -> return a + Left err -> MT.lift $ MT.lift $ MT.throwE $ ServerErrorParser err + +-- * Class 'Parsable' +class Parsable err a where + parse :: BSL.ByteString -> Either err a diff --git a/src/Literate/Web/Syntaxes.hs b/src/Literate/Web/Syntaxes.hs new file mode 100644 index 0000000..7d8caa5 --- /dev/null +++ b/src/Literate/Web/Syntaxes.hs @@ -0,0 +1,202 @@ +{-# LANGUAGE AllowAmbiguousTypes #-} +-- For IfSemantic +{-# LANGUAGE ConstraintKinds #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE UndecidableInstances #-} +{-# OPTIONS_GHC -Wno-orphans #-} + +module Literate.Web.Syntaxes ( + module Literate.Web.Syntaxes, + ProductFunctor (..), + SumFunctor (..), + Repeatable (..), + Optionable (..), + Dataable (..), + Inferable (..), + IsoFunctor (..), + dataType, + pattern (:!:), +) where + +import Control.Applicative (Applicative) +import Control.Monad (Monad) +import Control.Monad.Classes qualified as MC +import Control.Monad.Trans.Class as MT +import Data.Either (Either) +import Data.Bool (Bool (..)) +import Data.ByteString.Lazy qualified as BSL +import Data.Function ((.)) +import Data.Functor as Functor +import Data.Kind (Constraint, Type) +import Data.Typeable (Typeable) +import Literate.Web.Types.URL +import Symantic.Semantics (Reader (..)) +import Symantic.Semantics.ToFer ( + ToFer (..), + ) +import Symantic.Syntaxes ( + Dataable (..), + Endpoint, + Inferable (..), + IsToF, + IsoFunctor (..), + Optionable (..), + ProductFunctor (..), + Repeatable (..), + SumFunctor (..), + dataType, + pattern (:!:), + ) +import Symantic.Syntaxes.Data (Data, SomeData (..)) +import Symantic.Syntaxes.Derive +import System.FilePath (FilePath) + +--deriving instance PathSegmentable sem => PathSegmentable (Reflector r sem) +--deriving instance Endable sem => Endable (Reflector r sem) +--deriving instance Capturable sem => Capturable (Reflector r sem) + +-- * Class 'PathSegmentable' + +-- | Syntax (final algebra) for expressing URL paths. +class PathSegmentable sem where + -- choosePathSegments :: Set [PathSegment] -> sem [PathSegment] + -- default choosePathSegments :: FromDerived PathSegmentable sem => Set [PathSegment] -> sem [PathSegment] + -- choosePathSegments = liftDerived . choosePathSegments + -- pathSegment :: PathSegment -> sem a -> sem a + + pathSegment :: PathSegment -> sem () + default pathSegment :: FromDerived PathSegmentable sem => PathSegment -> sem () + -- default pathSegment :: IsoFunctor sem => PathSegment -> sem () + -- pathSegment s = Iso (const ()) (const s) <%> pathSegments (Set.singleton s) + pathSegment = liftDerived . pathSegment + +instance (PathSegmentable sem, Functor sem) => PathSegmentable (ToFer sem) where + pathSegment s = + ToFer + { tuplesOfFunctions = (Functor.<$ eot) + , eithersOfTuples = eot + } + where + eot = pathSegment s + +-- pathSegments :: Set PathSegment -> sem PathSegment +-- default pathSegments :: FromDerived PathSegmentable sem => Set PathSegment -> sem PathSegment +-- pathSegments = liftDerived . pathSegments + +-- default pathSegments :: IsoFunctor sem => Set PathSegment -> sem PathSegment +-- pathSegments s = Iso List.head pure <%> choosePathSegments (Set.mapMonotonic pure s) + +instance (PathSegmentable sem, IsoFunctor sem) => PathSegmentable (Reader r sem) + +-- | Pattern-matchable encoding (initial algebra) of 'PathSegmentable'. +data instance Data PathSegmentable sem a where + PathSegment :: PathSegment -> Data PathSegmentable sem () + +-- PathSegments :: Set PathSegment -> Data PathSegmentable sem PathSegment + +-- ChoosePathSegments :: Set [PathSegment] -> Data PathSegmentable sem [PathSegment] + +-- | Initial to final algebra. +instance PathSegmentable sem => Derivable (Data PathSegmentable sem) where + derive = \case + PathSegment x -> pathSegment x + +-- PathSegments x -> pathSegments x + +-- ChoosePathSegments x -> choosePathSegments x + +-- | Final to initial algebra. +instance PathSegmentable sem => PathSegmentable (SomeData sem) where + pathSegment = SomeData . PathSegment + +-- pathSegments = SomeData . PathSegments + +--choosePathSegments = SomeData . ChoosePathSegments + +-- | Convenient alias for an @index.html@ page. +index :: PathSegmentable sem => sem () +index = pathSegment "index.html" + +-- | Convenient alias for prefixing with a 'pathSegment'. +() :: + ProductFunctor sem => + PathSegmentable sem => + PathSegment -> + sem a -> + sem a +() n = (pathSegment n .>) + +infixr 4 + +-- * Class 'Copyable' +class Copyable sem where + copy :: FilePath -> sem () + +-- * Class 'Encodable' +class Encodable fmt a where + encode :: a -> BSL.ByteString + +-- * Class 'Capturable' +class Capturable a sem where + type Captured a sem :: Type + type Captured a sem = a + capturePathSegment :: PathSegment -> sem (Captured a sem) + default capturePathSegment :: + Captured a (Derived sem) ~ Captured a sem => + FromDerived (Capturable a) sem => + PathSegment -> + sem (Captured a sem) + capturePathSegment = liftDerived . capturePathSegment @a + +-- | The @('IsToF' a ~ 'False)@ constraint +-- disables capturing tuples or functions. +instance + ( Capturable a sem + , IsToF (Captured a sem) ~ 'False + , Functor sem + ) => Capturable a (ToFer sem) where + type Captured a (ToFer sem) = Captured a sem + capturePathSegment _n = + ToFer + { tuplesOfFunctions = \next -> next <$> capturePathSegment @a _n + , eithersOfTuples = capturePathSegment @a _n + } + +-- | @('CapturedExtra' a extra)@ is useful to add @(extra)@ data +-- to a 'Captured' value, eg. when using the 'Compiler' semantic, +-- to add the content of a page whose name was captured +-- directly available when iterating all the pages, +-- hence avoiding to lookup that content as would be done +-- when using the 'Server' semantic. +newtype CapturedExtra a extra = CapturedExtra (Either (a, extra) a) + +--instance Capturable sem => Capturable (Reader r sem) +data instance Data (Capturable a) sem r where + CapturePathSegment :: + Capturable a sem => + PathSegment -> + Data (Capturable a) sem (Captured a sem) +instance Capturable a sem => Derivable (Data (Capturable a) sem) where + derive = \case + CapturePathSegment n -> capturePathSegment @a n +instance (Capturable a sem, Typeable a) => Capturable a (SomeData sem) where + type Captured a (SomeData sem) = Captured a sem + capturePathSegment = SomeData . CapturePathSegment @a + +-- * Class 'Fileable' +class Fileable sem where + type FileableConstraint sem :: Type -> Constraint + static :: sem () + dynamic :: FileableConstraint sem a => sem a + +-- * Class 'Responsable' +class Responsable a ts m result sem where + response :: sem (Endpoint result (Response ts m a)) + +-- ** Type 'Response' +newtype Response (ts :: [Type]) m a = Response {unResponse :: m a} + deriving (Functor, Applicative, Monad) +type instance MC.CanDo (Response ts m) eff = 'False +instance MT.MonadTrans (Response ts) where lift = Response diff --git a/src/Literate/Web/Types/MIME.hs b/src/Literate/Web/Types/MIME.hs new file mode 100644 index 0000000..562c1e5 --- /dev/null +++ b/src/Literate/Web/Types/MIME.hs @@ -0,0 +1,221 @@ +{-# LANGUAGE AllowAmbiguousTypes #-} +{-# LANGUAGE ConstraintKinds #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE OverloadedStrings #-} + +module Literate.Web.Types.MIME where + +import Control.Arrow (left) +import Data.Bool +import Data.ByteString qualified as BS +import Data.ByteString.Lazy qualified as BSL +import Data.ByteString.Lazy.Char8 qualified as BLC +import Data.Either (Either (..)) +import Data.Eq (Eq (..)) +import Data.Foldable (toList) +import Data.Function (id, ($), (.)) +import Data.Functor ((<$>)) +import Data.Int (Int) +import Data.Kind (Constraint, Type) +import Data.List.NonEmpty (NonEmpty (..)) +import Data.Maybe (Maybe (..), isJust) +import Data.Proxy (Proxy (..)) +import Data.Semigroup (Semigroup (..)) +import Data.String (String) +import Data.Text qualified as T +import Data.Text.Encoding qualified as T +import Data.Text.Lazy qualified as TL +import Data.Text.Lazy.Encoding qualified as TL +import Data.Tuple (fst, snd) +import Data.Typeable (Typeable, eqT) +import Network.HTTP.Media qualified as Media +import Text.Read (readMaybe) +import Text.Show (Show (..)) + +--import qualified Web.FormUrlEncoded as Web + +-- * Class 'FileExtension' +class FileExtension fmt where + fileExtension :: T.Text + +-- * Class 'MediaTypeFor' +class (Typeable fmt, FileExtension fmt) => MediaTypeFor fmt where + mediaTypeFor :: Proxy fmt -> MediaType + mediaTypesFor :: Proxy fmt -> NonEmpty MediaType + mediaTypesFor fmt = mediaTypeFor fmt :| [] +instance MediaTypeFor () where + mediaTypeFor _t = mimeAny +instance FileExtension () where + fileExtension = "" + +-- ** Type 'MediaType' +type MediaType = Media.MediaType +mediaType :: forall fmt. MediaTypeFor fmt => MediaType +mediaType = mediaTypeFor (Proxy @fmt) +{-# INLINE mediaType #-} + +-- ** Type 'MediaTypes' +type MediaTypes = NonEmpty MediaType +mediaTypes :: forall ts c. MimeTypes ts c => MediaTypes +mediaTypes = fst <$> mimeTypesMap @ts @c +{-# INLINE mediaTypes #-} + +charsetUTF8 :: MediaType -> MediaType +charsetUTF8 = (Media./: ("charset", "utf-8")) + +mimeAny :: MediaType +mimeAny = "*/*" + +-- ** Type 'JSON' +data JSON deriving (Typeable) +instance MediaTypeFor JSON where + mediaTypeFor _t = charsetUTF8 $ "application" Media.// "json" + mediaTypesFor fmt = mediaTypeFor fmt :| ["application" Media.// "json"] +instance FileExtension JSON where + fileExtension = "json" + +-- ** Type 'HTML' +data HTML deriving (Typeable) +instance MediaTypeFor HTML where + mediaTypeFor _t = charsetUTF8 $ "text" Media.// "html" + mediaTypesFor fmt = mediaTypeFor fmt :| ["text" Media.// "html"] +instance FileExtension HTML where + fileExtension = "html" + +-- ** Type 'FormUrlEncoded' +data FormUrlEncoded deriving (Typeable) +instance MediaTypeFor FormUrlEncoded where + mediaTypeFor _t = "application" Media.// "x-www-form-urlencoded" +instance FileExtension FormUrlEncoded where + fileExtension = "url" + +-- ** Type 'OctetStream' +data OctetStream deriving (Typeable) +instance MediaTypeFor OctetStream where + mediaTypeFor _t = "application" Media.// "octet-stream" +instance FileExtension OctetStream where + fileExtension = "bin" + +-- ** Type 'PlainText' +data PlainText deriving (Typeable) +instance MediaTypeFor PlainText where + mediaTypeFor _t = charsetUTF8 $ "text" Media.// "plain" +instance FileExtension PlainText where + fileExtension = "txt" + +-- * Type 'MimeType' + +-- | Existentially wraps a type-level type 'fmt' +-- with a proof it respects 'Constraint' 'c'. +-- Usually 'c' is 'MimeEncodable' or 'MimeDecodable'. +data MimeType c where + MimeType :: (c fmt, MediaTypeFor fmt) => Proxy fmt -> MimeType c + +instance Eq (MimeType c) where + MimeType (_ :: Proxy x) == MimeType (_ :: Proxy y) = isJust (eqT @x @y) + +mimeType :: forall fmt c. MediaTypeFor fmt => c fmt => MimeType c +mimeType = MimeType (Proxy @fmt) +{-# INLINE mimeType #-} +mimeTypes :: forall ts c. MimeTypes ts c => NonEmpty (MimeType c) +mimeTypes = snd <$> mimeTypesMap @ts @c +{-# INLINE mimeTypes #-} + +-- * Class 'MimeTypes' + +-- | Implicitely generate 'MediaType's and 'MimeType's +-- from a type-level list of types. +class MimeTypes (ts :: [Type]) (c :: Type -> Constraint) where + mimeTypesMap :: NonEmpty (MediaType, MimeType c) + +instance (MediaTypeFor fmt, c fmt) => MimeTypes '[fmt] c where + mimeTypesMap = (,MimeType @c @fmt Proxy) <$> mediaTypesFor (Proxy @fmt) +instance (MediaTypeFor fmt, MimeTypes (t1 ': ts) c, c fmt) => MimeTypes (fmt ': t1 ': ts) c where + mimeTypesMap = + ( (,MimeType @c @fmt Proxy) + <$> mediaTypesFor (Proxy @fmt) + ) + <> mimeTypesMap @(t1 ': ts) @c + +matchAccept :: + forall ts c. + MimeTypes ts c => + BS.ByteString -> + Maybe (MimeType c) +matchAccept = Media.mapAccept (toList $ mimeTypesMap @ts @c) + +matchContent :: + forall ts c. + MimeTypes ts c => + BS.ByteString -> + Maybe (MimeType c) +matchContent = Media.mapContent (toList $ mimeTypesMap @ts @c) + +-- * Type 'MimeEncodable' +class MediaTypeFor fmt => MimeEncodable a fmt where + mimeEncode :: MimeEncoder a +instance MimeEncodable () PlainText where + mimeEncode () = BLC.pack "" + +-- | @BSL.fromStrict . T.encodeUtf8@ +instance MimeEncodable String PlainText where + mimeEncode = BLC.pack + +instance MimeEncodable T.Text PlainText where + mimeEncode = BSL.fromStrict . T.encodeUtf8 +instance MimeEncodable TL.Text PlainText where + mimeEncode = TL.encodeUtf8 +instance MimeEncodable BS.ByteString OctetStream where + mimeEncode = BSL.fromStrict +instance MimeEncodable BSL.ByteString OctetStream where + mimeEncode = id +instance MimeEncodable Int PlainText where + mimeEncode = TL.encodeUtf8 . TL.pack . show + +-- | @Web.urlEncodeAsForm@ +-- Note that the @mimeDecode @_ @fmt (mimeEncode @_ @fmt x) == Right x@ law only +-- holds if every element of x is non-null (i.e., not @("", "")@) +--instance Web.ToForm a => MimeEncodable a FormUrlEncoded where +-- mimeEncode _ = Web.urlEncodeAsForm + +-- ** Type 'MimeEncoder' + +type MimeEncoder a = a -> BSL.ByteString + +-- * Type 'MimeDecodable' +class MediaTypeFor mt => MimeDecodable a mt where + mimeDecode :: Proxy mt -> MimeDecoder a + +-- mimeDecode p = mimeUnserializeWithType p (mimeType p) + +-- ** Type 'MimeDecoder' +type MimeDecoder a = BSL.ByteString -> Either String a + +instance MimeDecodable () PlainText where + mimeDecode _ bsl + | BLC.null bsl = Right () + | otherwise = Left "not empty" +instance MimeDecodable String PlainText where + mimeDecode _ = Right . BLC.unpack +instance MimeDecodable T.Text PlainText where + mimeDecode _ = left show . T.decodeUtf8' . BSL.toStrict +instance MimeDecodable TL.Text PlainText where + mimeDecode _ = left show . TL.decodeUtf8' +instance MimeDecodable BS.ByteString OctetStream where + mimeDecode _ = Right . BSL.toStrict +instance MimeDecodable BSL.ByteString OctetStream where + mimeDecode _ = Right +instance MimeDecodable Int PlainText where + mimeDecode _mt bsl = + case readMaybe s of + Just n -> Right n + _ -> Left $ "cannot parse as Int: " <> s + where + s = TL.unpack (TL.decodeUtf8 bsl) + +-- | @Web.urlDecodeAsForm@ +-- Note that the @mimeDecode @_ @fmt (mimeEncode @_ @fmt x) == Right x@ law only +-- holds if every element of x is non-null (i.e., not @("", "")@) +--instance Web.FromForm a => MimeDecodable a FormUrlEncoded where +-- mimeDecode _ = left T.unpack . Web.urlDecodeAsForm diff --git a/src/Literate/Web/Types/URL.hs b/src/Literate/Web/Types/URL.hs new file mode 100644 index 0000000..111390c --- /dev/null +++ b/src/Literate/Web/Types/URL.hs @@ -0,0 +1,55 @@ +{-# LANGUAGE InstanceSigs #-} + +module Literate.Web.Types.URL ( + Path, + encodePath, + PathSegment (unPathSegment), + decodePathSegment, + encodePathSegment, +) where + +import Data.Data (Data) +import Data.Eq (Eq) +import Data.Function (($), (.)) +import Data.Functor ((<$>)) +import Data.List (isInfixOf) +import Data.Ord (Ord) +import Data.Semigroup (Semigroup (..)) +import Data.String (IsString (..), String) +import Data.Text (Text) +import Data.Text qualified as Text +import Data.Text.Normalize qualified as UT +import GHC.Generics (Generic) +import GHC.Stack (HasCallStack) +import Network.URI.Encode qualified as UE +import Text.Show (Show) +import Prelude (FilePath, error) + +-- * Type 'Path' +type Path = [PathSegment] + +encodePath :: [PathSegment] -> FilePath +encodePath s = + Text.unpack $ + Text.intercalate (Text.singleton '/') $ + encodePathSegment <$> s + +-- ** Type 'PathSegment' +newtype PathSegment = PathSegment {unPathSegment :: Text} + deriving (Eq, Show, Ord, Data, Generic) + +instance IsString PathSegment where + fromString :: HasCallStack => String -> PathSegment + fromString s = + if "/" `isInfixOf` s + then error ("PathSegment cannot contain a slash: " <> s) + else PathSegment (normalizeUnicode (fromString s)) + +encodePathSegment :: PathSegment -> Text +encodePathSegment = UE.encodeText . unPathSegment + +decodePathSegment :: Text -> PathSegment +decodePathSegment = fromString . UE.decode . Text.unpack + +normalizeUnicode :: Text -> Text +normalizeUnicode = UT.normalize UT.NFC diff --git a/tests/Examples/Ex01.hs b/tests/Examples/Ex01.hs new file mode 100644 index 0000000..1a47025 --- /dev/null +++ b/tests/Examples/Ex01.hs @@ -0,0 +1,20 @@ +{-# LANGUAGE NoMonomorphismRestriction #-} +{-# OPTIONS_GHC -Wno-missing-signatures #-} + +module Examples.Ex01 where + +import Control.Monad (Monad (..)) +import Data.Text (Text) +import Literate.Web +import Symantic qualified as Sym + +-- | Polymorphic expression describing the website, +-- to be instantiated to the various interpreters. +-- NoMonomorphismRestriction is used to avoid specifying manually +-- the inferred symantic classes. +router = + pathSegment "index" <.> response @Text @'[PlainText] + <+> "about" pathSegment "me" + +content = + (Sym.endpoint (return "INDEX"), return "ABOUT") diff --git a/tests/Examples/Ex02.hs b/tests/Examples/Ex02.hs new file mode 100644 index 0000000..0b6d616 --- /dev/null +++ b/tests/Examples/Ex02.hs @@ -0,0 +1,27 @@ +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE NoMonomorphismRestriction #-} +{-# OPTIONS_GHC -Wno-missing-signatures #-} + +module Examples.Ex02 where + +import Literate.Web hiding (index) +import Relude + +-- | A convenient data-type to avoid using Eithers-of-Tuples or Tuples-of-Functions. +data Route + = Index + | About + deriving (Eq, Show, Generic) + +-- | Using Generic, 'dataType' derives +-- from the 'Route' algebraic data-type +-- a function transforming Eithers-of-Tuples into a 'Route'. +router = + dataType @Route $ + pathSegment "index" + <+> "about" + pathSegment "me" + +content = \case + Index -> return "INDEX" + About -> return "ABOUT" diff --git a/tests/Examples/Ex03.hs b/tests/Examples/Ex03.hs new file mode 100644 index 0000000..cd2047a --- /dev/null +++ b/tests/Examples/Ex03.hs @@ -0,0 +1,88 @@ +{-# LANGUAGE DeriveGeneric #-} +-- For Inferable +{-# LANGUAGE UndecidableInstances #-} +{-# LANGUAGE NoMonomorphismRestriction #-} +{-# OPTIONS_GHC -Wno-missing-signatures #-} + +module Examples.Ex03 where + +import Control.Monad (Monad (..)) +import Control.Monad.Classes qualified as MC +import Data.Eq (Eq) +import Data.Function (($), (.)) +import Data.Maybe (Maybe (..), maybe) +import Data.Ord (Ord) +import Data.Set (Set) +import Data.Set qualified as Set +import Data.String (IsString (..)) +import GHC.Generics (Generic) +import Text.Show (Show (..)) + +import Literate.Web + +-- | 'dataType' can be used at any point where +-- the Tuples-of-Functions are no longer wanted. +router = + pathSegment "static" + <+> pathSegment "feed" + <+> "filter" (dataType @(Maybe Lang) $ pathSegment "all" <+> infer) <.> optional (capturePathSegment @Tag "tag") + +-- content :: +-- Monad m => +-- Sym.ToF +-- (Either () (Either () (Maybe Lang, Maybe Tag))) +-- (m BSL.ByteString) +content = + contentStatic + :!: contentFeed + :!: contentFilter + where + contentStatic = return "STATIC" + contentFeed = return "FEED" + contentFilter filterLang filterTag = + return $ + fromString $ + case filterLang of + Nothing -> maybe "ALL-LANG-ALL-TAGS" show filterTag + Just lang -> case filterTag of + Nothing -> show lang + Just tag -> show (lang, tag) + +-- * Type 'Lang' +data Lang + = LangEn + | LangFr + deriving (Eq, Show, Generic) + +routeLang = dataType @Lang $ pathSegment "en" <+> pathSegment "fr" + +-- | Using 'Inferable' has the downside of requiring +-- to explicit manually the symantices required. +instance (SumFunctor sem, PathSegmentable sem, Dataable sem) => Inferable Lang sem where + infer = routeLang + +-- * Type 'Tag' +newtype Tag = Tag {unTag :: PathSegment} deriving (Eq, Ord, Show) +instance IsString Tag where + fromString = Tag . fromString + +-- | Capturing a 'Tag' makes no sense when compiling a static site. +-- Hence the 'Compiler' semantic for 'Capturable' +-- requires a readable 'Model' somewhere in the monad stack +-- in order to generate all 'Tag's folders. +instance MC.MonadReader Model m => Capturable Tag (Compiler m) where + capturePathSegment _n = + Compiler do + model <- MC.ask + return + [ Output{outputPath = [unTag tag], outputExts = [], outputData = tag} + | tag <- Set.toList (modelTags model) + ] + +-- * Type 'Model' +data Model = Model + { modelTags :: Set Tag + } + +model1 = Model{modelTags = Set.fromList []} +model2 = Model{modelTags = Set.fromList ["cat1", "cat2", "cat3"]} diff --git a/tests/Examples/Ex04.hs b/tests/Examples/Ex04.hs new file mode 100644 index 0000000..f2e1cb4 --- /dev/null +++ b/tests/Examples/Ex04.hs @@ -0,0 +1,102 @@ +{-# LANGUAGE UndecidableInstances #-} +{-# LANGUAGE NoMonomorphismRestriction #-} +{-# OPTIONS_GHC -Wno-missing-signatures #-} + +module Examples.Ex04 where + +import Control.Monad.Classes qualified as MC +import Data.Map.Strict as Map +import Literate.Web +import Relude +import Symantic qualified as Sym + +router = + "post" capturePathSegment @PostName "post" <.> response @Post @'[PlainText] + <+> "page" capturePathSegment @PageName "page" <.> response @Page @'[PlainText] + <+> pathSegment "lorem" + +-- content :: +-- ( PostName -> (a :~: a, Post) +-- , PageName -> (a :~: a, Page) ) +-- content :: +-- MC.MonadReader Model m => +-- endpoint ~ m Text => +-- Sym.ToF +-- (Either (PostName, Sym.Endpoint endpoint (m Post)) +-- (PageName, Sym.Endpoint endpoint (m Page))) +-- endpoint +content = contentPost :!: contentPage :!: contentOther + where + contentPost n = Sym.endpoint do + Model{..} <- MC.ask + return $ modelPosts Map.! n + contentPage = Sym.endpoint . \case + CapturedExtra (Left (_n, p)) -> do + return p + CapturedExtra (Right n) -> do + Model{..} <- MC.ask + return $ modelPages Map.! n + contentOther = return "ipsum" + +instance MimeEncodable Post PlainText where + mimeEncode (Post t) = mimeEncode @_ @PlainText t +instance MimeEncodable Page PlainText where + mimeEncode (Page t) = mimeEncode @_ @PlainText t + +instance MC.MonadReader Model m => Capturable PostName (Compiler m) where + capturePathSegment _n = + Compiler do + model <- MC.ask + return + [ Output{outputPath = [unPostName name], outputExts = [], outputData = name} + | name <- Map.keys (modelPosts model) + ] +instance MC.MonadReader Model m => Capturable PageName (Compiler m) where + -- Keep the 'Page' to avoid looking it up in 'contentPage'. + type Captured PageName (Compiler m) = CapturedExtra PageName Page + capturePathSegment _n = + Compiler do + model <- MC.ask + return + [ Output + { outputPath = [unPageName name] + , outputExts = [] + , outputData = CapturedExtra (Left (name, page)) + } + | (name, page) <- Map.toList (modelPages model) + ] + +-- * Type 'Model' +data Model = Model + { modelPosts :: Map PostName Post + , modelPages :: Map PageName Page + } +model1 = + Model + { modelPosts = + Map.fromList + [ (PostName "post1", Post "post-model-1") + , (PostName "post2", Post "post-model-2") + ] + , modelPages = + Map.fromList + [ (PageName "page1", Page "page-model-1") + , (PageName "page2", Page "page-model-2") + ] + } + +-- ** Type 'PostName' +data PostName = PostName {unPostName :: PathSegment} + deriving (Show, Eq, Ord) + +-- ** Type 'PageName' +data PageName = PageName {unPageName :: PathSegment} + deriving (Show, Eq, Ord) + +-- ** Type 'Post' +data Post = Post {unPost :: Text} + deriving (Show) + +-- ** Type 'Page' +data Page = Page {unPage :: Text} + deriving (Show) diff --git a/tests/Goldens.hs b/tests/Goldens.hs new file mode 100644 index 0000000..501a729 --- /dev/null +++ b/tests/Goldens.hs @@ -0,0 +1,123 @@ +{-# LANGUAGE AllowAmbiguousTypes #-} +-- For Golden +{-# LANGUAGE ExistentialQuantification #-} +{-# LANGUAGE ImportQualifiedPost #-} +{-# LANGUAGE PartialTypeSignatures #-} +-- For Golden +{-# LANGUAGE RankNTypes #-} +{-# OPTIONS_GHC -Wno-orphans #-} + +module Goldens where + +import Control.Monad.Classes qualified as MC +import Control.Monad.Trans.Reader as MT +import Data.ByteString.Lazy qualified as BSL +import Data.Functor.Identity (Identity (..)) +import Data.Text qualified as Text +import Relude +import Symantic qualified as Sym +import System.FilePath qualified as Sys +import System.IO.Unsafe (unsafePerformIO) +import Test.Tasty +import Test.Tasty.Golden +import Text.Printf (printf) + +import Examples.Ex01 qualified as Ex01 +import Examples.Ex02 qualified as Ex02 +import Examples.Ex03 qualified as Ex03 +import Examples.Ex04 qualified as Ex04 +import Examples.Ex05 qualified as Ex05 +import Literate.Web +import Paths_literate_web +import Utils + +test :: TestTree +test = + testGroup + "Goldens" + [ testGroup + "Compiler" + [ testGroup + (printf "Site%03d" siteNum) + [ withResource + (goldenCompiler CompilerEnv{..}) + (\_ -> return ()) + $ \compilerIO -> + testGroup + (printf "Model%02d" modelNum) + [ goldenVsFileDiff + (printf "/%s" destPath) + goldenDiff + (getGoldenDir (printf "Compiler/Site%03d/Model%02d/Expected/%s" siteNum modelNum destPath)) + (compilerEnvDest Sys. destPath) + compilerIO + | destPath <- goldenManifest + ] + | (modelNum, Golden{..}) <- ol goldenModels + , let compilerEnvDest = getGoldenDir (printf "Compiler/Site%03d/Model%02d/Got/" siteNum modelNum) + , let compilerEnvIndex :: FilePath = "index.html" + -- , let compilerEnvSource = getGoldenDir (printf "Compiler/Site%03d/Model%02d/Source/" siteNum modelNum) + ] + | (siteNum, goldenModels) <- ol goldens + ] + ] + +getGoldenDir :: FilePath -> FilePath +getGoldenDir p = unsafePerformIO $ getDataFileName $ "tests/Goldens/" <> p + +goldenDiff :: FilePath -> FilePath -> [String] +goldenDiff ref new = ["diff", "-u", "-w", "-B", ref, new] + +data Golden = Golden + { goldenCompiler :: CompilerEnv -> IO () + , goldenManifest :: [Sys.FilePath] + } +goldens :: [[Golden]] +goldens = + {- [ Golden @() index [()] + , Golden @() + ("foo" index) + [()] + , Golden @(Either () ()) + ("root" ("foo" index <+> "bar" index)) + [()] + , Golden @(Either () (), Either () ()) + ( "root" + ("a" literalSlug "b" <+> "c" literalSlug "d") + <.> ("A" literalSlug "B" <+> "C" literalSlug "D") + <. index + ) + [()] + -} + [ + [ Golden + { goldenCompiler = \env -> compile env Ex01.router Ex01.content + , goldenManifest = runIdentity $ manifest Ex01.router Ex01.content + } + ] + , + [ Golden + { goldenCompiler = \env -> compile env Ex02.router Ex02.content + , goldenManifest = runIdentity $ manifest Ex02.router Ex02.content + } + ] + , [ Golden + { goldenCompiler = \env -> MT.runReaderT (compile env Ex03.router Ex03.content) model + , goldenManifest = runReader (manifest Ex03.router Ex03.content) model + } + | model <- [Ex03.model1, Ex03.model2] + ] + , [ Golden + { goldenCompiler = \env -> MT.runReaderT (compile env Ex04.router Ex04.content) model + , goldenManifest = runReader (manifest Ex04.router Ex04.content) model + } + | model <- [Ex04.model1] + ] + , [ Golden + { goldenCompiler = \env -> MT.runReaderT (MT.runReaderT (compile env Ex05.router Ex05.content) model03) model04 + , goldenManifest = MT.runReader (MT.runReaderT (manifest Ex05.router Ex05.content) model03) model04 + } + | model03 <- [Ex03.model1, Ex03.model2] + , model04 <- [Ex04.model1] + ] + ] diff --git a/tests/Goldens/Compiler/Site001/Model01/Expected/about/me.txt b/tests/Goldens/Compiler/Site001/Model01/Expected/about/me.txt new file mode 100644 index 0000000..6bf2957 --- /dev/null +++ b/tests/Goldens/Compiler/Site001/Model01/Expected/about/me.txt @@ -0,0 +1 @@ +ABOUT \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site001/Model01/Expected/index.txt b/tests/Goldens/Compiler/Site001/Model01/Expected/index.txt new file mode 100644 index 0000000..bf25fee --- /dev/null +++ b/tests/Goldens/Compiler/Site001/Model01/Expected/index.txt @@ -0,0 +1 @@ +INDEX \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site001/Model01/Got/about/me.txt b/tests/Goldens/Compiler/Site001/Model01/Got/about/me.txt new file mode 100644 index 0000000..6bf2957 --- /dev/null +++ b/tests/Goldens/Compiler/Site001/Model01/Got/about/me.txt @@ -0,0 +1 @@ +ABOUT \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site001/Model01/Got/index.txt b/tests/Goldens/Compiler/Site001/Model01/Got/index.txt new file mode 100644 index 0000000..bf25fee --- /dev/null +++ b/tests/Goldens/Compiler/Site001/Model01/Got/index.txt @@ -0,0 +1 @@ +INDEX \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model01/Expected/feed.txt b/tests/Goldens/Compiler/Site003/Model01/Expected/feed.txt new file mode 100644 index 0000000..95a67fb --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model01/Expected/feed.txt @@ -0,0 +1 @@ +FEED \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model01/Expected/filter/all.txt b/tests/Goldens/Compiler/Site003/Model01/Expected/filter/all.txt new file mode 100644 index 0000000..3f09dff --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model01/Expected/filter/all.txt @@ -0,0 +1 @@ +ALL-LANG-ALL-TAGS \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model01/Expected/filter/en.txt b/tests/Goldens/Compiler/Site003/Model01/Expected/filter/en.txt new file mode 100644 index 0000000..2297258 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model01/Expected/filter/en.txt @@ -0,0 +1 @@ +LangEn \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model01/Expected/filter/fr.txt b/tests/Goldens/Compiler/Site003/Model01/Expected/filter/fr.txt new file mode 100644 index 0000000..919dd92 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model01/Expected/filter/fr.txt @@ -0,0 +1 @@ +LangFr \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model01/Expected/static.txt b/tests/Goldens/Compiler/Site003/Model01/Expected/static.txt new file mode 100644 index 0000000..fb07e1a --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model01/Expected/static.txt @@ -0,0 +1 @@ +STATIC \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model01/Got/feed.txt b/tests/Goldens/Compiler/Site003/Model01/Got/feed.txt new file mode 100644 index 0000000..95a67fb --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model01/Got/feed.txt @@ -0,0 +1 @@ +FEED \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model01/Got/filter/all.txt b/tests/Goldens/Compiler/Site003/Model01/Got/filter/all.txt new file mode 100644 index 0000000..3f09dff --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model01/Got/filter/all.txt @@ -0,0 +1 @@ +ALL-LANG-ALL-TAGS \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model01/Got/filter/en.txt b/tests/Goldens/Compiler/Site003/Model01/Got/filter/en.txt new file mode 100644 index 0000000..2297258 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model01/Got/filter/en.txt @@ -0,0 +1 @@ +LangEn \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model01/Got/filter/fr.txt b/tests/Goldens/Compiler/Site003/Model01/Got/filter/fr.txt new file mode 100644 index 0000000..919dd92 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model01/Got/filter/fr.txt @@ -0,0 +1 @@ +LangFr \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model01/Got/static.txt b/tests/Goldens/Compiler/Site003/Model01/Got/static.txt new file mode 100644 index 0000000..fb07e1a --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model01/Got/static.txt @@ -0,0 +1 @@ +STATIC \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/feed.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/feed.txt new file mode 100644 index 0000000..95a67fb --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/feed.txt @@ -0,0 +1 @@ +FEED \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/filter/all.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/all.txt new file mode 100644 index 0000000..3f09dff --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/all.txt @@ -0,0 +1 @@ +ALL-LANG-ALL-TAGS \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/filter/all/cat1.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/all/cat1.txt new file mode 100644 index 0000000..6fc5407 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/all/cat1.txt @@ -0,0 +1 @@ +Tag {unTag = PathSegment {unPathSegment = "cat1"}} \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/filter/all/cat2.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/all/cat2.txt new file mode 100644 index 0000000..1fa8566 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/all/cat2.txt @@ -0,0 +1 @@ +Tag {unTag = PathSegment {unPathSegment = "cat2"}} \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/filter/all/cat3.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/all/cat3.txt new file mode 100644 index 0000000..5112494 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/all/cat3.txt @@ -0,0 +1 @@ +Tag {unTag = PathSegment {unPathSegment = "cat3"}} \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/filter/en.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/en.txt new file mode 100644 index 0000000..2297258 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/en.txt @@ -0,0 +1 @@ +LangEn \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/filter/en/cat1.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/en/cat1.txt new file mode 100644 index 0000000..3d82e51 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/en/cat1.txt @@ -0,0 +1 @@ +(LangEn,Tag {unTag = PathSegment {unPathSegment = "cat1"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/filter/en/cat2.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/en/cat2.txt new file mode 100644 index 0000000..7ad6dd8 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/en/cat2.txt @@ -0,0 +1 @@ +(LangEn,Tag {unTag = PathSegment {unPathSegment = "cat2"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/filter/en/cat3.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/en/cat3.txt new file mode 100644 index 0000000..6210d5b --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/en/cat3.txt @@ -0,0 +1 @@ +(LangEn,Tag {unTag = PathSegment {unPathSegment = "cat3"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr.txt new file mode 100644 index 0000000..919dd92 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr.txt @@ -0,0 +1 @@ +LangFr \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr/cat1.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr/cat1.txt new file mode 100644 index 0000000..5879407 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr/cat1.txt @@ -0,0 +1 @@ +(LangFr,Tag {unTag = PathSegment {unPathSegment = "cat1"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr/cat2.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr/cat2.txt new file mode 100644 index 0000000..cb1a09f --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr/cat2.txt @@ -0,0 +1 @@ +(LangFr,Tag {unTag = PathSegment {unPathSegment = "cat2"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr/cat3.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr/cat3.txt new file mode 100644 index 0000000..0e13c76 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/filter/fr/cat3.txt @@ -0,0 +1 @@ +(LangFr,Tag {unTag = PathSegment {unPathSegment = "cat3"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Expected/static.txt b/tests/Goldens/Compiler/Site003/Model02/Expected/static.txt new file mode 100644 index 0000000..fb07e1a --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Expected/static.txt @@ -0,0 +1 @@ +STATIC \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/feed.txt b/tests/Goldens/Compiler/Site003/Model02/Got/feed.txt new file mode 100644 index 0000000..95a67fb --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/feed.txt @@ -0,0 +1 @@ +FEED \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/filter/all.txt b/tests/Goldens/Compiler/Site003/Model02/Got/filter/all.txt new file mode 100644 index 0000000..3f09dff --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/filter/all.txt @@ -0,0 +1 @@ +ALL-LANG-ALL-TAGS \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/filter/all/cat1.txt b/tests/Goldens/Compiler/Site003/Model02/Got/filter/all/cat1.txt new file mode 100644 index 0000000..6fc5407 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/filter/all/cat1.txt @@ -0,0 +1 @@ +Tag {unTag = PathSegment {unPathSegment = "cat1"}} \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/filter/all/cat2.txt b/tests/Goldens/Compiler/Site003/Model02/Got/filter/all/cat2.txt new file mode 100644 index 0000000..1fa8566 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/filter/all/cat2.txt @@ -0,0 +1 @@ +Tag {unTag = PathSegment {unPathSegment = "cat2"}} \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/filter/all/cat3.txt b/tests/Goldens/Compiler/Site003/Model02/Got/filter/all/cat3.txt new file mode 100644 index 0000000..5112494 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/filter/all/cat3.txt @@ -0,0 +1 @@ +Tag {unTag = PathSegment {unPathSegment = "cat3"}} \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/filter/en.txt b/tests/Goldens/Compiler/Site003/Model02/Got/filter/en.txt new file mode 100644 index 0000000..2297258 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/filter/en.txt @@ -0,0 +1 @@ +LangEn \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/filter/en/cat1.txt b/tests/Goldens/Compiler/Site003/Model02/Got/filter/en/cat1.txt new file mode 100644 index 0000000..3d82e51 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/filter/en/cat1.txt @@ -0,0 +1 @@ +(LangEn,Tag {unTag = PathSegment {unPathSegment = "cat1"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/filter/en/cat2.txt b/tests/Goldens/Compiler/Site003/Model02/Got/filter/en/cat2.txt new file mode 100644 index 0000000..7ad6dd8 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/filter/en/cat2.txt @@ -0,0 +1 @@ +(LangEn,Tag {unTag = PathSegment {unPathSegment = "cat2"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/filter/en/cat3.txt b/tests/Goldens/Compiler/Site003/Model02/Got/filter/en/cat3.txt new file mode 100644 index 0000000..6210d5b --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/filter/en/cat3.txt @@ -0,0 +1 @@ +(LangEn,Tag {unTag = PathSegment {unPathSegment = "cat3"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/filter/fr.txt b/tests/Goldens/Compiler/Site003/Model02/Got/filter/fr.txt new file mode 100644 index 0000000..919dd92 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/filter/fr.txt @@ -0,0 +1 @@ +LangFr \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/filter/fr/cat1.txt b/tests/Goldens/Compiler/Site003/Model02/Got/filter/fr/cat1.txt new file mode 100644 index 0000000..5879407 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/filter/fr/cat1.txt @@ -0,0 +1 @@ +(LangFr,Tag {unTag = PathSegment {unPathSegment = "cat1"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/filter/fr/cat2.txt b/tests/Goldens/Compiler/Site003/Model02/Got/filter/fr/cat2.txt new file mode 100644 index 0000000..cb1a09f --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/filter/fr/cat2.txt @@ -0,0 +1 @@ +(LangFr,Tag {unTag = PathSegment {unPathSegment = "cat2"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/filter/fr/cat3.txt b/tests/Goldens/Compiler/Site003/Model02/Got/filter/fr/cat3.txt new file mode 100644 index 0000000..0e13c76 --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/filter/fr/cat3.txt @@ -0,0 +1 @@ +(LangFr,Tag {unTag = PathSegment {unPathSegment = "cat3"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site003/Model02/Got/static.txt b/tests/Goldens/Compiler/Site003/Model02/Got/static.txt new file mode 100644 index 0000000..fb07e1a --- /dev/null +++ b/tests/Goldens/Compiler/Site003/Model02/Got/static.txt @@ -0,0 +1 @@ +STATIC \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site004/Model01/Expected/lorem.txt b/tests/Goldens/Compiler/Site004/Model01/Expected/lorem.txt new file mode 100644 index 0000000..c8ccfe5 --- /dev/null +++ b/tests/Goldens/Compiler/Site004/Model01/Expected/lorem.txt @@ -0,0 +1 @@ +ipsum \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site004/Model01/Expected/page/page1.txt b/tests/Goldens/Compiler/Site004/Model01/Expected/page/page1.txt new file mode 100644 index 0000000..1c4b61b --- /dev/null +++ b/tests/Goldens/Compiler/Site004/Model01/Expected/page/page1.txt @@ -0,0 +1 @@ +page-model-1 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site004/Model01/Expected/post/post1.txt b/tests/Goldens/Compiler/Site004/Model01/Expected/post/post1.txt new file mode 100644 index 0000000..6d9be0b --- /dev/null +++ b/tests/Goldens/Compiler/Site004/Model01/Expected/post/post1.txt @@ -0,0 +1 @@ +post-model-1 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site004/Model01/Expected/post/post2.txt b/tests/Goldens/Compiler/Site004/Model01/Expected/post/post2.txt new file mode 100644 index 0000000..6a436d4 --- /dev/null +++ b/tests/Goldens/Compiler/Site004/Model01/Expected/post/post2.txt @@ -0,0 +1 @@ +post-model-2 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site004/Model01/Got/lorem.txt b/tests/Goldens/Compiler/Site004/Model01/Got/lorem.txt new file mode 100644 index 0000000..c8ccfe5 --- /dev/null +++ b/tests/Goldens/Compiler/Site004/Model01/Got/lorem.txt @@ -0,0 +1 @@ +ipsum \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site004/Model01/Got/page/page1.txt b/tests/Goldens/Compiler/Site004/Model01/Got/page/page1.txt new file mode 100644 index 0000000..1c4b61b --- /dev/null +++ b/tests/Goldens/Compiler/Site004/Model01/Got/page/page1.txt @@ -0,0 +1 @@ +page-model-1 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site004/Model01/Got/post/post1.txt b/tests/Goldens/Compiler/Site004/Model01/Got/post/post1.txt new file mode 100644 index 0000000..6d9be0b --- /dev/null +++ b/tests/Goldens/Compiler/Site004/Model01/Got/post/post1.txt @@ -0,0 +1 @@ +post-model-1 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site004/Model01/Got/post/post2.txt b/tests/Goldens/Compiler/Site004/Model01/Got/post/post2.txt new file mode 100644 index 0000000..6a436d4 --- /dev/null +++ b/tests/Goldens/Compiler/Site004/Model01/Got/post/post2.txt @@ -0,0 +1 @@ +post-model-2 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/feed.txt b/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/feed.txt new file mode 100644 index 0000000..95a67fb --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/feed.txt @@ -0,0 +1 @@ +FEED \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/filter/all.txt b/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/filter/all.txt new file mode 100644 index 0000000..3f09dff --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/filter/all.txt @@ -0,0 +1 @@ +ALL-LANG-ALL-TAGS \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/filter/en.txt b/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/filter/en.txt new file mode 100644 index 0000000..2297258 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/filter/en.txt @@ -0,0 +1 @@ +LangEn \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/filter/fr.txt b/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/filter/fr.txt new file mode 100644 index 0000000..919dd92 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/filter/fr.txt @@ -0,0 +1 @@ +LangFr \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/static.txt b/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/static.txt new file mode 100644 index 0000000..fb07e1a --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Expected/ex03/static.txt @@ -0,0 +1 @@ +STATIC \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Expected/ex04/lorem.txt b/tests/Goldens/Compiler/Site005/Model01/Expected/ex04/lorem.txt new file mode 100644 index 0000000..c8ccfe5 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Expected/ex04/lorem.txt @@ -0,0 +1 @@ +ipsum \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Expected/ex04/page/page1.txt b/tests/Goldens/Compiler/Site005/Model01/Expected/ex04/page/page1.txt new file mode 100644 index 0000000..1c4b61b --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Expected/ex04/page/page1.txt @@ -0,0 +1 @@ +page-model-1 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Expected/ex04/post/post1.txt b/tests/Goldens/Compiler/Site005/Model01/Expected/ex04/post/post1.txt new file mode 100644 index 0000000..6d9be0b --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Expected/ex04/post/post1.txt @@ -0,0 +1 @@ +post-model-1 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Expected/ex04/post/post2.txt b/tests/Goldens/Compiler/Site005/Model01/Expected/ex04/post/post2.txt new file mode 100644 index 0000000..6a436d4 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Expected/ex04/post/post2.txt @@ -0,0 +1 @@ +post-model-2 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Got/ex03/feed.txt b/tests/Goldens/Compiler/Site005/Model01/Got/ex03/feed.txt new file mode 100644 index 0000000..95a67fb --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Got/ex03/feed.txt @@ -0,0 +1 @@ +FEED \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Got/ex03/filter/all.txt b/tests/Goldens/Compiler/Site005/Model01/Got/ex03/filter/all.txt new file mode 100644 index 0000000..3f09dff --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Got/ex03/filter/all.txt @@ -0,0 +1 @@ +ALL-LANG-ALL-TAGS \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Got/ex03/filter/en.txt b/tests/Goldens/Compiler/Site005/Model01/Got/ex03/filter/en.txt new file mode 100644 index 0000000..2297258 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Got/ex03/filter/en.txt @@ -0,0 +1 @@ +LangEn \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Got/ex03/filter/fr.txt b/tests/Goldens/Compiler/Site005/Model01/Got/ex03/filter/fr.txt new file mode 100644 index 0000000..919dd92 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Got/ex03/filter/fr.txt @@ -0,0 +1 @@ +LangFr \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Got/ex03/static.txt b/tests/Goldens/Compiler/Site005/Model01/Got/ex03/static.txt new file mode 100644 index 0000000..fb07e1a --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Got/ex03/static.txt @@ -0,0 +1 @@ +STATIC \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Got/ex04/lorem.txt b/tests/Goldens/Compiler/Site005/Model01/Got/ex04/lorem.txt new file mode 100644 index 0000000..c8ccfe5 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Got/ex04/lorem.txt @@ -0,0 +1 @@ +ipsum \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Got/ex04/page/page1.txt b/tests/Goldens/Compiler/Site005/Model01/Got/ex04/page/page1.txt new file mode 100644 index 0000000..1c4b61b --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Got/ex04/page/page1.txt @@ -0,0 +1 @@ +page-model-1 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Got/ex04/post/post1.txt b/tests/Goldens/Compiler/Site005/Model01/Got/ex04/post/post1.txt new file mode 100644 index 0000000..6d9be0b --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Got/ex04/post/post1.txt @@ -0,0 +1 @@ +post-model-1 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model01/Got/ex04/post/post2.txt b/tests/Goldens/Compiler/Site005/Model01/Got/ex04/post/post2.txt new file mode 100644 index 0000000..6a436d4 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model01/Got/ex04/post/post2.txt @@ -0,0 +1 @@ +post-model-2 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/feed.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/feed.txt new file mode 100644 index 0000000..95a67fb --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/feed.txt @@ -0,0 +1 @@ +FEED \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all.txt new file mode 100644 index 0000000..3f09dff --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all.txt @@ -0,0 +1 @@ +ALL-LANG-ALL-TAGS \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all/cat1.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all/cat1.txt new file mode 100644 index 0000000..6fc5407 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all/cat1.txt @@ -0,0 +1 @@ +Tag {unTag = PathSegment {unPathSegment = "cat1"}} \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all/cat2.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all/cat2.txt new file mode 100644 index 0000000..1fa8566 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all/cat2.txt @@ -0,0 +1 @@ +Tag {unTag = PathSegment {unPathSegment = "cat2"}} \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all/cat3.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all/cat3.txt new file mode 100644 index 0000000..5112494 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/all/cat3.txt @@ -0,0 +1 @@ +Tag {unTag = PathSegment {unPathSegment = "cat3"}} \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en.txt new file mode 100644 index 0000000..2297258 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en.txt @@ -0,0 +1 @@ +LangEn \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en/cat1.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en/cat1.txt new file mode 100644 index 0000000..3d82e51 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en/cat1.txt @@ -0,0 +1 @@ +(LangEn,Tag {unTag = PathSegment {unPathSegment = "cat1"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en/cat2.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en/cat2.txt new file mode 100644 index 0000000..7ad6dd8 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en/cat2.txt @@ -0,0 +1 @@ +(LangEn,Tag {unTag = PathSegment {unPathSegment = "cat2"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en/cat3.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en/cat3.txt new file mode 100644 index 0000000..6210d5b --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/en/cat3.txt @@ -0,0 +1 @@ +(LangEn,Tag {unTag = PathSegment {unPathSegment = "cat3"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr.txt new file mode 100644 index 0000000..919dd92 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr.txt @@ -0,0 +1 @@ +LangFr \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr/cat1.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr/cat1.txt new file mode 100644 index 0000000..5879407 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr/cat1.txt @@ -0,0 +1 @@ +(LangFr,Tag {unTag = PathSegment {unPathSegment = "cat1"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr/cat2.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr/cat2.txt new file mode 100644 index 0000000..cb1a09f --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr/cat2.txt @@ -0,0 +1 @@ +(LangFr,Tag {unTag = PathSegment {unPathSegment = "cat2"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr/cat3.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr/cat3.txt new file mode 100644 index 0000000..0e13c76 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/filter/fr/cat3.txt @@ -0,0 +1 @@ +(LangFr,Tag {unTag = PathSegment {unPathSegment = "cat3"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/static.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/static.txt new file mode 100644 index 0000000..fb07e1a --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex03/static.txt @@ -0,0 +1 @@ +STATIC \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex04/lorem.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex04/lorem.txt new file mode 100644 index 0000000..c8ccfe5 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex04/lorem.txt @@ -0,0 +1 @@ +ipsum \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex04/page/page1.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex04/page/page1.txt new file mode 100644 index 0000000..1c4b61b --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex04/page/page1.txt @@ -0,0 +1 @@ +page-model-1 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex04/post/post1.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex04/post/post1.txt new file mode 100644 index 0000000..6d9be0b --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex04/post/post1.txt @@ -0,0 +1 @@ +post-model-1 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Expected/ex04/post/post2.txt b/tests/Goldens/Compiler/Site005/Model02/Expected/ex04/post/post2.txt new file mode 100644 index 0000000..6a436d4 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Expected/ex04/post/post2.txt @@ -0,0 +1 @@ +post-model-2 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/feed.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/feed.txt new file mode 100644 index 0000000..95a67fb --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/feed.txt @@ -0,0 +1 @@ +FEED \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all.txt new file mode 100644 index 0000000..3f09dff --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all.txt @@ -0,0 +1 @@ +ALL-LANG-ALL-TAGS \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all/cat1.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all/cat1.txt new file mode 100644 index 0000000..6fc5407 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all/cat1.txt @@ -0,0 +1 @@ +Tag {unTag = PathSegment {unPathSegment = "cat1"}} \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all/cat2.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all/cat2.txt new file mode 100644 index 0000000..1fa8566 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all/cat2.txt @@ -0,0 +1 @@ +Tag {unTag = PathSegment {unPathSegment = "cat2"}} \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all/cat3.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all/cat3.txt new file mode 100644 index 0000000..5112494 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/all/cat3.txt @@ -0,0 +1 @@ +Tag {unTag = PathSegment {unPathSegment = "cat3"}} \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en.txt new file mode 100644 index 0000000..2297258 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en.txt @@ -0,0 +1 @@ +LangEn \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en/cat1.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en/cat1.txt new file mode 100644 index 0000000..3d82e51 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en/cat1.txt @@ -0,0 +1 @@ +(LangEn,Tag {unTag = PathSegment {unPathSegment = "cat1"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en/cat2.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en/cat2.txt new file mode 100644 index 0000000..7ad6dd8 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en/cat2.txt @@ -0,0 +1 @@ +(LangEn,Tag {unTag = PathSegment {unPathSegment = "cat2"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en/cat3.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en/cat3.txt new file mode 100644 index 0000000..6210d5b --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/en/cat3.txt @@ -0,0 +1 @@ +(LangEn,Tag {unTag = PathSegment {unPathSegment = "cat3"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr.txt new file mode 100644 index 0000000..919dd92 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr.txt @@ -0,0 +1 @@ +LangFr \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr/cat1.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr/cat1.txt new file mode 100644 index 0000000..5879407 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr/cat1.txt @@ -0,0 +1 @@ +(LangFr,Tag {unTag = PathSegment {unPathSegment = "cat1"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr/cat2.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr/cat2.txt new file mode 100644 index 0000000..cb1a09f --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr/cat2.txt @@ -0,0 +1 @@ +(LangFr,Tag {unTag = PathSegment {unPathSegment = "cat2"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr/cat3.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr/cat3.txt new file mode 100644 index 0000000..0e13c76 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/filter/fr/cat3.txt @@ -0,0 +1 @@ +(LangFr,Tag {unTag = PathSegment {unPathSegment = "cat3"}}) \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex03/static.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/static.txt new file mode 100644 index 0000000..fb07e1a --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex03/static.txt @@ -0,0 +1 @@ +STATIC \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex04/lorem.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex04/lorem.txt new file mode 100644 index 0000000..c8ccfe5 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex04/lorem.txt @@ -0,0 +1 @@ +ipsum \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex04/page/page1.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex04/page/page1.txt new file mode 100644 index 0000000..1c4b61b --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex04/page/page1.txt @@ -0,0 +1 @@ +page-model-1 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex04/post/post1.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex04/post/post1.txt new file mode 100644 index 0000000..6d9be0b --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex04/post/post1.txt @@ -0,0 +1 @@ +post-model-1 \ No newline at end of file diff --git a/tests/Goldens/Compiler/Site005/Model02/Got/ex04/post/post2.txt b/tests/Goldens/Compiler/Site005/Model02/Got/ex04/post/post2.txt new file mode 100644 index 0000000..6a436d4 --- /dev/null +++ b/tests/Goldens/Compiler/Site005/Model02/Got/ex04/post/post2.txt @@ -0,0 +1 @@ +post-model-2 \ No newline at end of file diff --git a/tests/HUnits.hs b/tests/HUnits.hs new file mode 100644 index 0000000..17fe7eb --- /dev/null +++ b/tests/HUnits.hs @@ -0,0 +1,174 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RankNTypes #-} + +module HUnits where + +import Relude +import Symantic qualified as Sym +import Test.Tasty +import Test.Tasty.HUnit + +import Examples.Ex01 qualified as Ex01 +import Examples.Ex02 qualified as Ex02 +import Literate.Web +import Text.Printf (printf) +import Utils + +test :: TestTree +test = + testGroup + "HUnits" + [ testGroup + "Generator" + [ testGenerator + "Ex01" + Ex01.site + [ + ( () + , + [ Gen ["index.html"] $ Ex01.Index + , Gen ["about.html"] $ Ex01.About + -- , Gen ["user", "contact.html"] $ Ex01.Contact "user" + -- , Gen ["post"] $ Ex01.Post [] + -- , Gen ["post", "dir"] $ Ex01.Post ["dir"] + -- , Gen ["post", "dir", "dir"] $ Ex01.Post ["dir", "dir"] + ] + ) + ] + , testGenerator + "Ex02" + Ex02.site + [ + ( Ex02.model0 + , [Gen{genSlugs = ["static"], genValue = Ex02.SiteStatic}, Gen{genSlugs = ["feed"], genValue = Ex02.SiteFeeds}, Gen{genSlugs = ["filter", "all"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Nothing, filterTag = Nothing})}, Gen{genSlugs = ["filter", "all", "tag0"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Nothing, filterTag = Just (Ex02.Tag{unTag = "tag0"})})}, Gen{genSlugs = ["filter", "all", "tag1"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Nothing, filterTag = Just (Ex02.Tag{unTag = "tag1"})})}, Gen{genSlugs = ["filter", "fr"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Just Ex02.LangEn, filterTag = Nothing})}, Gen{genSlugs = ["filter", "fr", "tag0"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Just Ex02.LangEn, filterTag = Just (Ex02.Tag{unTag = "tag0"})})}, Gen{genSlugs = ["filter", "fr", "tag1"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Just Ex02.LangEn, filterTag = Just (Ex02.Tag{unTag = "tag1"})})}, Gen{genSlugs = ["filter", "en"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Just Ex02.LangFr, filterTag = Nothing})}, Gen{genSlugs = ["filter", "en", "tag0"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Just Ex02.LangFr, filterTag = Just (Ex02.Tag{unTag = "tag0"})})}, Gen{genSlugs = ["filter", "en", "tag1"], genValue = Ex02.SiteFilter (Ex02.Filter{filterLang = Just Ex02.LangFr, filterTag = Just (Ex02.Tag{unTag = "tag1"})})}] + ) + ] + ] + , testGroup + "CoderIsomorphism" + [ testCoderIsomorphism "Ex01" Ex01.site () + , testCoderIsomorphism "Ex02" Ex02.site Ex02.model0 + ] + , testGroup + "Encoder" + [ testEncoder + "Ex01" + Ex01.site + [ + ( () + , + [ Gen ["index.html"] $ Ex01.Index + , Gen ["about.html"] $ Ex01.About + -- , Gen ["user", "contact.html"] $ Ex01.Contact "user" + -- , Gen ["post", "a", "b"] $ Ex01.Post ["a", "b"] + ] + ) + ] + ] + , testGroup + "Decoder" + [ testDecoder + "Ex01" + Ex01.site + [ + ( () + , + [ Gen ["index.html"] $ Ex01.Index + , Gen ["about.html"] $ Ex01.About + -- , Gen ["user", "contact.html"] $ Ex01.Contact "user" + -- , Gen ["post", "a", "b"] $ Ex01.Post ["a", "b"] + ] + ) + ] + , testDecoder + "Ex02" + Ex02.site + [ + ( Ex02.model0 + , + [ {- Gen ["static"] $ Ex02.SiteStatic + , -} Gen + ["filter", "all", "tag0"] + $ Ex02.SiteFilter + Ex02.Filter + { Ex02.filterLang = Nothing + , Ex02.filterTag = Just (Ex02.Tag "tag0") + } + ] + ) + ] + ] + ] + +testGenerator :: + Eq a => + Show a => + String -> + Sym.Reader model Generator a -> + [(model, [Gen a])] -> + TestTree +testGenerator tn site models = + testGroup + tn + [ testCase (printf "Model%02d" modelNum) do + generate (Sym.unReader site model) @?= expectedGens + | (modelNum, (model, expectedGens)) <- ol models + ] + +testCoderIsomorphism :: + Eq a => + Show a => + String -> + (forall repr. Testable model repr => Sym.Reader model repr a) -> + model -> + TestTree +testCoderIsomorphism tn site model = + testGroup tn $ + [ testGroup (printf "Request%d" urlNum) $ + [ ( testCase "decode . encode" do + decode @() decoder Request{requestSlugs = encode encoder genValue, requestBody = ""} + >>= (@?= Right genValue) + ) + , ( testCase "encode . decode" do + dec <- decode @() decoder Request{requestSlugs = genSlugs, requestBody = ""} + encode encoder <$> dec @?= Right genSlugs + ) + ] + | (urlNum, Gen{..}) <- ol $ generate (Sym.unReader site model) + ] + where + decoder = Sym.unReader site model + encoder = Sym.unReader site model + +testDecoder :: + Eq a => + Show a => + String -> + Sym.Reader model (Decoder ()) a -> + [(model, [Gen a])] -> + TestTree +testDecoder tn site models = + testGroup + tn + [ testGroup + (printf "Model%d" modelNum) + [ testCase (printf "Gen%d" genNum) do + decode (Sym.unReader site model) Request{requestSlugs = genSlugs, requestBody = ""} + >>= (@?= Right genValue) + | (genNum, Gen{..}) <- ol expectedGens + ] + | (modelNum, (model, expectedGens)) <- ol models + ] + +testEncoder :: String -> Sym.Reader model Encoder a -> [(model, [Gen a])] -> TestTree +testEncoder tn site models = + testGroup + tn + [ testGroup + (printf "Model%d" modelNum) + [ testCase (printf "Gen%d" genNum) do + encode (Sym.unReader site model) genValue @?= genSlugs + | (genNum, Gen{..}) <- ol expectedGens + ] + | (modelNum, (model, expectedGens)) <- ol models + ] diff --git a/tests/Main.hs b/tests/Main.hs new file mode 100644 index 0000000..bd09636 --- /dev/null +++ b/tests/Main.hs @@ -0,0 +1,18 @@ +module Main where + +import Data.Function (($)) +import System.IO (IO) +import Test.Tasty + +import Goldens qualified + +-- import HUnits qualified + +main :: IO () +main = do + defaultMain $ + testGroup + "Web" + [ {- HUnits.test + , -} Goldens.test + ] diff --git a/tests/Utils.hs b/tests/Utils.hs new file mode 100644 index 0000000..ffd5a93 --- /dev/null +++ b/tests/Utils.hs @@ -0,0 +1,47 @@ +{-# LANGUAGE UndecidableInstances #-} + +module Utils where + +import Relude + +-- import Symantic qualified as Sym + +-- import Examples.Ex02 qualified as Ex02 + +-- import Literate.Web + +{- +-- | Gather symantics used by the tests +-- to instantiate multiple interpreters +-- on the same quantified 'repr'. +class + ( Sym.Inferable Ex02.Tag (Sym.Reader Ex02.Model repr) + , Sym.IsoFunctor repr + , Sym.Optionable repr + , Sym.ProductFunctor repr + , -- , Sym.Repeatable repr + Sym.SumFunctor repr + , -- , Endable repr + Slugable repr + -- , Capturable repr + -- , Fileable repr + ) => + Testable model repr + +instance + ( Sym.Inferable Ex02.Tag (Sym.Reader Ex02.Model repr) + , Sym.IsoFunctor repr + , Sym.Optionable repr + , Sym.ProductFunctor repr + , -- , Sym.Repeatable repr + Sym.SumFunctor repr + , --, Endable repr + Slugable repr + -- , Capturable repr + -- , Fileable repr + ) => + Testable model repr +-} + +ol :: [a] -> [(Int, a)] +ol = zip [1 ..] -- 2.44.1