1
1
mirror of https://github.com/srid/ema.git synced 2024-11-22 04:13:06 +03:00

Start splitting ema

This commit is contained in:
Sridhar Ratnakumar 2022-11-15 14:44:18 -05:00
parent 300259132f
commit a243a24432
52 changed files with 412 additions and 107 deletions

View File

@ -1,5 +1,9 @@
# Revision history for ema
## Unreleased
- Split Ema into multiple packages:
## 0.8.2.0 (2022-08-28)
- Bug fixes

View File

@ -3,6 +3,6 @@ set -xe
exec nix develop -c ghcid \
--restart ./www \
-c "cabal repl ema -f with-examples" \
-c "cabal repl ema-examples" \
-T Ema.Example.Ex04_Multi.main \
--setup ":set args run --port=8080"

View File

@ -1,2 +1,2 @@
packages: ema.cabal
flags: +with-examples
packages:
*/*.cabal

View File

@ -0,0 +1,133 @@
cabal-version: 2.4
name: ema-examples
version: 0.9.0.0
license: AGPL-3.0-only
copyright: 2022 Sridhar Ratnakumar
maintainer: srid@srid.ca
author: Sridhar Ratnakumar
category: Web
synopsis: Static site generator library with hot reload
bug-reports: https://github.com/srid/ema/issues
homepage: https://ema.srid.ca/
description:
Ema is a next-gen Haskell library for building jamstack-style static sites.
Ema sites are change-aware; in addition to good ol static site generation,
it provides a live server supporting fast hot-reload in the browser on code
or data change.
common extensions
default-extensions:
NoStarIsType
BangPatterns
ConstraintKinds
DataKinds
DeriveDataTypeable
DeriveFoldable
DeriveFunctor
DeriveGeneric
DeriveLift
DeriveTraversable
DerivingStrategies
DerivingVia
EmptyCase
EmptyDataDecls
EmptyDataDeriving
ExistentialQuantification
ExplicitForAll
FlexibleContexts
FlexibleInstances
GADTSyntax
GeneralisedNewtypeDeriving
ImportQualifiedPost
KindSignatures
LambdaCase
MultiParamTypeClasses
MultiWayIf
NumericUnderscores
OverloadedStrings
PolyKinds
PostfixOperators
RankNTypes
ScopedTypeVariables
StandaloneDeriving
StandaloneKindSignatures
TupleSections
TypeApplications
TypeFamilies
TypeOperators
ViewPatterns
library
import: extensions
-- Modules included in this executable, other than Main.
-- other-modules:
-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
build-depends:
, aeson
, async
, base >=4.13.0.0 && <4.17.0.0.0
, blaze-html
, blaze-markup
, constraints-extras
, containers
, data-default
, dependent-sum
, dependent-sum-template
, directory
, ema
, ema-generics
, file-embed
, filepath
, filepattern
, fsnotify
, generic-optics
, generics-sop
, http-types
, lvar
, monad-logger
, monad-logger-extras
, mtl
, neat-interpolation
, optics-core
, optparse-applicative
, relude >=1.0
, sop-core
, template-haskell
, text
, time
, unliftio
, url-slug
, wai
, wai-middleware-static
, wai-websockets
, warp
, websockets
mixins:
base hiding (Prelude),
relude (Relude as Prelude, Relude.Container.One),
relude
ghc-options:
-Wall -Wincomplete-record-updates -Wincomplete-uni-patterns
-Wmissing-deriving-strategies -Wunused-foralls -Wunused-foralls
-fprint-explicit-foralls -fprint-explicit-kinds
-fprint-potential-instances
exposed-modules:
Ema.Example.Common
Ema.Example.Ex00_Hello
Ema.Example.Ex01_Basic
Ema.Example.Ex02_Clock
Ema.Example.Ex03_Store
Ema.Example.Ex04_Multi
Ema.Example.Ex05_MultiRoute
hs-source-dirs: src
default-language: Haskell2010
if impl(ghc >=8.10)
ghc-options: -Wunused-packages

View File

@ -16,7 +16,8 @@ tailwindLayout h b =
layoutWith "en" "UTF-8" (tailwind2ShimCdn >> h) $
-- The "overflow-y-scroll" makes the scrollbar visible always, so as to
-- avoid janky shifts when switching to routes with suddenly scrollable content.
H.body ! A.class_ "overflow-y-scroll" $ b
H.body ! A.class_ "overflow-y-scroll" $
b
where
-- A general layout
layoutWith :: H.AttributeValue -> H.AttributeValue -> H.Html -> H.Html -> LByteString

108
ema-extra/ema-extra.cabal Normal file
View File

@ -0,0 +1,108 @@
cabal-version: 2.4
name: ema-extra
version: 0.9.0.0
license: AGPL-3.0-only
copyright: 2022 Sridhar Ratnakumar
maintainer: srid@srid.ca
author: Sridhar Ratnakumar
category: Web
synopsis: Static site generator library with hot reload
bug-reports: https://github.com/srid/ema/issues
homepage: https://ema.srid.ca/
description:
Ema is a next-gen Haskell library for building jamstack-style static sites.
Ema sites are change-aware; in addition to good ol static site generation,
it provides a live server supporting fast hot-reload in the browser on code
or data change.
common extensions
default-extensions:
NoStarIsType
BangPatterns
ConstraintKinds
DataKinds
DeriveDataTypeable
DeriveFoldable
DeriveFunctor
DeriveGeneric
DeriveLift
DeriveTraversable
DerivingStrategies
DerivingVia
EmptyCase
EmptyDataDecls
EmptyDataDeriving
ExistentialQuantification
ExplicitForAll
FlexibleContexts
FlexibleInstances
GADTSyntax
GeneralisedNewtypeDeriving
ImportQualifiedPost
KindSignatures
LambdaCase
MultiParamTypeClasses
MultiWayIf
NumericUnderscores
OverloadedStrings
PolyKinds
PostfixOperators
RankNTypes
ScopedTypeVariables
StandaloneDeriving
StandaloneKindSignatures
TupleSections
TypeApplications
TypeFamilies
TypeOperators
ViewPatterns
library
import: extensions
-- Modules included in this executable, other than Main.
-- other-modules:
-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
build-depends:
, base >=4.13.0.0 && <4.17.0.0.0
, containers
, data-default
, dependent-sum
, ema
, ema-generics
, filepath
, generics-sop
, monad-logger
, optics-core
, pandoc
, relude >=1.0
, sop-core
, text
, time
, unionmount
, unliftio
, url-slug
mixins:
base hiding (Prelude),
relude (Relude as Prelude, Relude.Container.One),
relude
ghc-options:
-Wall -Wincomplete-record-updates -Wincomplete-uni-patterns
-Wmissing-deriving-strategies -Wunused-foralls -Wunused-foralls
-fprint-explicit-foralls -fprint-explicit-kinds
-fprint-potential-instances
exposed-modules:
Ema.Route.Lib.Extra.PandocRoute
Ema.Route.Lib.Extra.SlugRoute
Ema.Route.Lib.Extra.StaticRoute
hs-source-dirs: src
default-language: Haskell2010
if impl(ghc >=8.10)
ghc-options: -Wunused-packages

View File

@ -82,7 +82,8 @@ lookupPandocRoute model r = do
renderHtml :: HasCallStack => Pandoc.WriterOptions -> Pandoc -> Text
renderHtml writerSettings pandoc =
either (throw . PandocError_RenderError . show) id $
Pandoc.runPure $ Pandoc.writeHtml5String writerSettings pandoc
Pandoc.runPure $
Pandoc.writeHtml5String writerSettings pandoc
data Arg = Arg
{ -- Base directory

View File

@ -0,0 +1,129 @@
cabal-version: 2.4
name: ema-generics
version: 0.9.0.0
license: AGPL-3.0-only
copyright: 2022 Sridhar Ratnakumar
maintainer: srid@srid.ca
author: Sridhar Ratnakumar
category: Web
synopsis: Static site generator library with hot reload
bug-reports: https://github.com/srid/ema/issues
homepage: https://ema.srid.ca/
description:
Ema is a next-gen Haskell library for building jamstack-style static sites.
Ema sites are change-aware; in addition to good ol static site generation,
it provides a live server supporting fast hot-reload in the browser on code
or data change.
common extensions
default-extensions:
NoStarIsType
BangPatterns
ConstraintKinds
DataKinds
DeriveDataTypeable
DeriveFoldable
DeriveFunctor
DeriveGeneric
DeriveLift
DeriveTraversable
DerivingStrategies
DerivingVia
EmptyCase
EmptyDataDecls
EmptyDataDeriving
ExistentialQuantification
ExplicitForAll
FlexibleContexts
FlexibleInstances
GADTSyntax
GeneralisedNewtypeDeriving
ImportQualifiedPost
KindSignatures
LambdaCase
MultiParamTypeClasses
MultiWayIf
NumericUnderscores
OverloadedStrings
PolyKinds
PostfixOperators
RankNTypes
ScopedTypeVariables
StandaloneDeriving
StandaloneKindSignatures
TupleSections
TypeApplications
TypeFamilies
TypeOperators
ViewPatterns
library
import: extensions
-- Modules included in this executable, other than Main.
-- other-modules:
-- LANGUAGE extensions used by modules in this package.
-- other-extensions:
build-depends:
, base >=4.13.0.0 && <4.17.0.0.0
, ema
, generic-optics
, generics-sop
, optics-core
, relude >=1.0
, sop-core
, template-haskell
mixins:
base hiding (Prelude),
relude (Relude as Prelude, Relude.Container.One),
relude
ghc-options:
-Wall -Wincomplete-record-updates -Wincomplete-uni-patterns
-Wmissing-deriving-strategies -Wunused-foralls -Wunused-foralls
-fprint-explicit-foralls -fprint-explicit-kinds
-fprint-potential-instances
exposed-modules:
Ema.Route.Generic
Ema.Route.Generic.RGeneric
Ema.Route.Generic.SubModel
Ema.Route.Generic.SubRoute
Ema.Route.Generic.TH
Ema.Route.Generic.Verification
other-modules: GHC.TypeLits.Extra
if impl(ghc >=9.2)
other-modules:
Ema.Route.Generic.Example
GHC.TypeLits.Extra.Symbol
hs-source-dirs: src
default-language: Haskell2010
if impl(ghc >=8.10)
ghc-options: -Wunused-packages
test-suite test-type-errors
import: extensions
build-depends:
, base
, ema
, ema-generics
, generics-sop
, raw-strings-qq
, template-haskell
, text
, url-slug
other-modules: Deriving
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs: test/type-errors
default-language: Haskell2010
if impl(ghc >=8.10)
ghc-options: -Wunused-packages

View File

@ -37,7 +37,7 @@ Invariant: code ~ Code route
-}
type family VerifyRoutes (rcode :: [Type]) (subRoutes :: [Type]) :: Constraint where
VerifyRoutes '[] '[] = ()
-- Inconsistent lengths
-- Inconsistent lengths
VerifyRoutes '[] t =
TypeError
( 'Text "'WithSubRoutes' has extra unnecessary types: " ':$$: 'Text "" ':$$: 'Text "\t" ':<>: 'ShowType t)
@ -47,7 +47,7 @@ type family VerifyRoutes (rcode :: [Type]) (subRoutes :: [Type]) :: Constraint w
':$$: 'Text ""
':$$: ( 'Text "\t" ':<>: 'ShowType t)
)
-- Subroute rep is unit (REVIEW: this case not strictly necessary anymore; should it be removed?)
-- Subroute rep is unit (REVIEW: this case not strictly necessary anymore; should it be removed?)
VerifyRoutes (() ': rs) (() : rs') = VerifyRoutes rs rs'
VerifyRoutes (r' ': rs) (() : rs') =
TypeError

View File

@ -1,41 +1,26 @@
cabal-version: 2.4
name: ema
version: 0.8.2.0
license: AGPL-3.0-only
copyright: 2021 Sridhar Ratnakumar
maintainer: srid@srid.ca
author: Sridhar Ratnakumar
category: Web
synopsis: Static site generator library with hot reload
bug-reports: https://github.com/srid/ema/issues
homepage: https://ema.srid.ca/
cabal-version: 2.4
name: ema
version: 0.9.0.0
license: AGPL-3.0-only
copyright: 2021 Sridhar Ratnakumar
maintainer: srid@srid.ca
author: Sridhar Ratnakumar
category: Web
synopsis: Static site generator library with hot reload
bug-reports: https://github.com/srid/ema/issues
homepage: https://ema.srid.ca/
description:
Ema is a next-gen Haskell library for building jamstack-style static sites.
Ema sites are change-aware; in addition to good ol static site generation,
it provides a live server supporting fast hot-reload in the browser on code
or data change.
extra-source-files:
CHANGELOG.md
LICENSE
README.md
data-dir: www
data-dir: www
data-files:
ema-error.html
ema-indicator.html
ema-shim.js
-- This flag is enabled by default just so `bin/run` can work on macOS M1.
-- When disabling, ensure that macOS build doesn't break.
flag with-examples
description: Include examples and their dependencies
default: True
flag with-extra
description: Include non-core functionality
default: True
common extensions
default-extensions:
NoStarIsType
@ -89,9 +74,8 @@ library
build-depends:
, aeson
, async
, base >=4.13.0.0 && <=4.17.0.0
, base >=4.13.0.0 && <4.17.0.0.0
, constraints-extras
, containers
, data-default
, dependent-sum
, dependent-sum-template
@ -99,8 +83,6 @@ library
, file-embed
, filepath
, filepattern
, generic-optics
, generics-sop
, http-types
, lvar
, monad-logger
@ -111,7 +93,6 @@ library
, optparse-applicative
, relude >=1.0
, sop-core
, template-haskell
, text
, unliftio
, url-slug
@ -121,20 +102,6 @@ library
, warp
, websockets
if flag(with-examples)
build-depends:
, blaze-html
, blaze-markup
, fsnotify
, time
if flag(with-extra)
build-depends:
, pandoc
, pandoc-types
, time
, unionmount
mixins:
base hiding (Prelude),
relude (Relude as Prelude, Relude.Container.One),
@ -154,12 +121,6 @@ library
Ema.Dynamic
Ema.Generate
Ema.Route.Class
Ema.Route.Generic
Ema.Route.Generic.RGeneric
Ema.Route.Generic.SubModel
Ema.Route.Generic.SubRoute
Ema.Route.Generic.TH
Ema.Route.Generic.Verification
Ema.Route.Lib.File
Ema.Route.Lib.Folder
Ema.Route.Lib.Multi
@ -170,50 +131,8 @@ library
Ema.Server
Ema.Site
other-modules: GHC.TypeLits.Extra
if flag(with-extra)
exposed-modules:
Ema.Route.Lib.Extra.PandocRoute
Ema.Route.Lib.Extra.SlugRoute
Ema.Route.Lib.Extra.StaticRoute
if impl(ghc >=9.2)
other-modules: GHC.TypeLits.Extra.Symbol
if (flag(with-examples) && impl(ghc >=9.2))
other-modules:
Ema.Example.Common
Ema.Example.Ex00_Hello
Ema.Example.Ex01_Basic
Ema.Example.Ex02_Clock
Ema.Example.Ex03_Store
Ema.Example.Ex04_Multi
Ema.Example.Ex05_MultiRoute
Ema.Route.Generic.Example
hs-source-dirs: src
default-language: Haskell2010
if impl(ghc >=8.10)
ghc-options: -Wunused-packages
test-suite test-type-errors
import: extensions
build-depends:
, base
, ema
, generics-sop
, raw-strings-qq
, template-haskell
, text
, url-slug
other-modules: Deriving
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs: test/type-errors
default-language: Haskell2010
if impl(ghc >=8.10)
ghc-options: -Wunused-packages

View File

@ -85,9 +85,11 @@ prismIsLawfulFor p a s = do
let ma' :: Maybe a = preview p s'
-- log $ "Decoding of that encoding: " <> show ma'
unless (s == s') $
log $ toText s <> " /= " <> toText s' <> " (encoding of '" <> show a <> "')"
log $
toText s <> " /= " <> toText s' <> " (encoding of '" <> show a <> "')"
unless (Just a == ma') $
log $ show (Just a) <> " /= " <> show ma' <> " (decoding of " <> toText s <> ")"
log $
show (Just a) <> " /= " <> show ma' <> " (decoding of " <> toText s <> ")"
pure $ (s == s') && (Just a == ma')
where
log = tell . one

View File

@ -226,7 +226,8 @@ data BadRouteEncoding r = BadRouteEncoding
badRouteEncodingMsg :: Show r => BadRouteEncoding r -> Text
badRouteEncodingMsg BadRouteEncoding {..} =
toText $
"A route Prism' is unlawful.\n\nThe URL '" <> toText _bre_urlFilePath
"A route Prism' is unlawful.\n\nThe URL '"
<> toText _bre_urlFilePath
<> "' decodes to route '"
<> show _bre_decodedRoute
<> "', but it is not isomporphic on any of the allowed candidates: \n\n"

View File

@ -15,9 +15,14 @@
# This attr is provided by https://github.com/srid/haskell-flake
haskellProjects = {
ghc90 = {
packages.ema.root = ./.;
packages = {
# All but ema-examples, which requires GHC 9.2 for TH deriving
ema.root = ./ema;
ema-generics.root = ./ema-generics;
ema-extra.root = ./ema-extra;
};
overrides = self: super: {
ema = pkgs.haskell.lib.dontCheck super.ema; # test/type-errors requires 9.2
ema-generics = pkgs.haskell.lib.dontCheck super.ema-generics; # test/type-errors requires 9.2
};
buildTools = hp: {
inherit (pkgs)
@ -29,7 +34,6 @@
};
};
ghc92 = {
packages.ema.root = ./.;
haskellPackages = pkgs.haskell.packages.ghc924; # Needed for `UnconsSymbol`
buildTools = hp:
let

2
hie.yaml Normal file
View File

@ -0,0 +1,2 @@
cradle:
cabal:

1
www Symbolic link
View File

@ -0,0 +1 @@
ema/www