mirror of
https://github.com/srid/rib.git
synced 2024-09-11 13:37:20 +03:00
Initial commit
This commit is contained in:
commit
50a762797c
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
dist-newstyle
|
||||
result
|
||||
result-android
|
||||
result-ios
|
||||
result-exe
|
||||
.attr-cache
|
||||
ghcid-output.txt
|
7
.obelisk/impl/default.nix
Normal file
7
.obelisk/impl/default.nix
Normal file
@ -0,0 +1,7 @@
|
||||
# DO NOT HAND-EDIT THIS FILE
|
||||
import ((import <nixpkgs> {}).fetchFromGitHub (
|
||||
let json = builtins.fromJSON (builtins.readFile ./github.json);
|
||||
in { inherit (json) owner repo rev sha256;
|
||||
private = json.private or false;
|
||||
}
|
||||
))
|
7
.obelisk/impl/github.json
Normal file
7
.obelisk/impl/github.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"owner": "obsidiansystems",
|
||||
"repo": "obelisk",
|
||||
"branch": "master",
|
||||
"rev": "de99fc6178fe64f6ea3176746e9c273c92fb8e45",
|
||||
"sha256": "1g75262rckkpsm7d3km3wd9pch313qv1hy6kq37v96spi3byg2s9"
|
||||
}
|
28
backend/backend.cabal
Normal file
28
backend/backend.cabal
Normal file
@ -0,0 +1,28 @@
|
||||
name: backend
|
||||
version: 0.1
|
||||
cabal-version: >= 1.8
|
||||
build-type: Simple
|
||||
|
||||
library
|
||||
hs-source-dirs: src
|
||||
if impl(ghcjs)
|
||||
buildable: False
|
||||
build-depends: base
|
||||
, common
|
||||
, frontend
|
||||
, obelisk-backend
|
||||
, obelisk-route
|
||||
exposed-modules:
|
||||
Backend
|
||||
ghc-options: -Wall
|
||||
|
||||
executable backend
|
||||
main-is: main.hs
|
||||
hs-source-dirs: src-bin
|
||||
if impl(ghcjs)
|
||||
buildable: False
|
||||
build-depends: base
|
||||
, backend
|
||||
, common
|
||||
, frontend
|
||||
, obelisk-backend
|
1
backend/frontend.jsexe
Symbolic link
1
backend/frontend.jsexe
Symbolic link
@ -0,0 +1 @@
|
||||
../frontend-js/bin/frontend.jsexe
|
1
backend/frontendJs/frontend.jsexe
Symbolic link
1
backend/frontendJs/frontend.jsexe
Symbolic link
@ -0,0 +1 @@
|
||||
../../frontend-js/bin/frontend.jsexe
|
6
backend/src-bin/main.hs
Normal file
6
backend/src-bin/main.hs
Normal file
@ -0,0 +1,6 @@
|
||||
import Backend
|
||||
import Frontend
|
||||
import Obelisk.Backend
|
||||
|
||||
main :: IO ()
|
||||
main = runBackend backend frontend
|
15
backend/src/Backend.hs
Normal file
15
backend/src/Backend.hs
Normal file
@ -0,0 +1,15 @@
|
||||
{-# LANGUAGE EmptyCase #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE RankNTypes #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
module Backend where
|
||||
|
||||
import Common.Route
|
||||
import Obelisk.Backend
|
||||
|
||||
backend :: Backend BackendRoute FrontendRoute
|
||||
backend = Backend
|
||||
{ _backend_run = \serve -> serve $ const $ return ()
|
||||
, _backend_routeEncoder = backendRouteEncoder
|
||||
}
|
1
backend/static
Symbolic link
1
backend/static
Symbolic link
@ -0,0 +1 @@
|
||||
../static
|
2
cabal.project
Normal file
2
cabal.project
Normal file
@ -0,0 +1,2 @@
|
||||
optional-packages:
|
||||
*
|
17
common/common.cabal
Normal file
17
common/common.cabal
Normal file
@ -0,0 +1,17 @@
|
||||
name: common
|
||||
version: 0.1
|
||||
cabal-version: >= 1.2
|
||||
build-type: Simple
|
||||
|
||||
library
|
||||
hs-source-dirs: src
|
||||
build-depends: base
|
||||
, obelisk-route
|
||||
, mtl
|
||||
, text
|
||||
default-extensions:
|
||||
TypeFamilies
|
||||
PolyKinds
|
||||
exposed-modules:
|
||||
Common.Api
|
||||
Common.Route
|
4
common/src/Common/Api.hs
Normal file
4
common/src/Common/Api.hs
Normal file
@ -0,0 +1,4 @@
|
||||
module Common.Api where
|
||||
|
||||
commonStuff :: String
|
||||
commonStuff = "Here is a string defined in code common to the frontend and backend."
|
52
common/src/Common/Route.hs
Normal file
52
common/src/Common/Route.hs
Normal file
@ -0,0 +1,52 @@
|
||||
{-# LANGUAGE EmptyCase #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE RankNTypes #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE KindSignatures #-}
|
||||
{-# LANGUAGE EmptyCase #-}
|
||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||
{-# LANGUAGE FlexibleInstances #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Common.Route where
|
||||
|
||||
{- -- You will probably want these imports for composing Encoders.
|
||||
import Prelude hiding (id, (.))
|
||||
import Control.Category
|
||||
-}
|
||||
|
||||
import Data.Text (Text)
|
||||
import Data.Functor.Identity
|
||||
import Data.Functor.Sum
|
||||
|
||||
import Obelisk.Route
|
||||
import Obelisk.Route.TH
|
||||
|
||||
data BackendRoute :: * -> * where
|
||||
-- | Used to handle unparseable routes.
|
||||
BackendRoute_Missing :: BackendRoute ()
|
||||
-- You can define any routes that will be handled specially by the backend here.
|
||||
-- i.e. These do not serve the frontend, but do something different, such as serving static files.
|
||||
|
||||
data FrontendRoute :: * -> * where
|
||||
FrontendRoute_Main :: FrontendRoute ()
|
||||
-- This type is used to define frontend routes, i.e. ones for which the backend will serve the frontend.
|
||||
|
||||
backendRouteEncoder
|
||||
:: Encoder (Either Text) Identity (R (Sum BackendRoute (ObeliskRoute FrontendRoute))) PageName
|
||||
backendRouteEncoder = handleEncoder (const (InL BackendRoute_Missing :/ ())) $
|
||||
pathComponentEncoder $ \case
|
||||
InL backendRoute -> case backendRoute of
|
||||
BackendRoute_Missing -> PathSegment "missing" $ unitEncoder mempty
|
||||
InR obeliskRoute -> obeliskRouteSegment obeliskRoute $ \case
|
||||
-- The encoder given to PathEnd determines how to parse query parameters,
|
||||
-- in this example, we have none, so we insist on it.
|
||||
FrontendRoute_Main -> PathEnd $ unitEncoder mempty
|
||||
|
||||
|
||||
concat <$> mapM deriveRouteComponent
|
||||
[ ''BackendRoute
|
||||
, ''FrontendRoute
|
||||
]
|
1
config/common/route
Normal file
1
config/common/route
Normal file
@ -0,0 +1 @@
|
||||
http://localhost:8000
|
9
config/readme.md
Normal file
9
config/readme.md
Normal file
@ -0,0 +1,9 @@
|
||||
### Config
|
||||
|
||||
Obelisk projects should contain a config folder with the following subfolders: common, frontend, and backend.
|
||||
|
||||
Things that should never be transmitted to the frontend belong in backend/ (e.g., email credentials)
|
||||
|
||||
Frontend-only configuration belongs in frontend/.
|
||||
|
||||
Shared configuration files (e.g., the route config) belong in common/
|
16
default.nix
Normal file
16
default.nix
Normal file
@ -0,0 +1,16 @@
|
||||
{ obelisk ? import ./.obelisk/impl {
|
||||
system = builtins.currentSystem;
|
||||
iosSdkVersion = "10.2";
|
||||
# You must accept the Android Software Development Kit License Agreement at
|
||||
# https://developer.android.com/studio/terms in order to build Android apps.
|
||||
# Uncomment and set this to `true` to indicate your acceptance:
|
||||
# config.android_sdk.accept_license = false;
|
||||
}
|
||||
}:
|
||||
with obelisk;
|
||||
project ./. ({ ... }: {
|
||||
android.applicationId = "systems.obsidian.obelisk.examples.minimal";
|
||||
android.displayName = "Obelisk Minimal Example";
|
||||
ios.bundleIdentifier = "systems.obsidian.obelisk.examples.minimal";
|
||||
ios.bundleName = "Obelisk Minimal Example";
|
||||
})
|
32
frontend/frontend.cabal
Normal file
32
frontend/frontend.cabal
Normal file
@ -0,0 +1,32 @@
|
||||
name: frontend
|
||||
version: 0.1
|
||||
cabal-version: >= 1.8
|
||||
build-type: Simple
|
||||
|
||||
library
|
||||
hs-source-dirs: src
|
||||
build-depends: base
|
||||
, common
|
||||
, obelisk-frontend
|
||||
, obelisk-route
|
||||
, reflex-dom
|
||||
, obelisk-generated-static
|
||||
, text
|
||||
exposed-modules:
|
||||
Frontend
|
||||
ghc-options: -Wall
|
||||
|
||||
executable frontend
|
||||
main-is: main.hs
|
||||
hs-source-dirs: src-bin
|
||||
build-depends: base
|
||||
, common
|
||||
, obelisk-frontend
|
||||
, obelisk-route
|
||||
, reflex-dom
|
||||
, obelisk-generated-static
|
||||
, frontend
|
||||
--TODO: Make these ghc-options optional
|
||||
ghc-options: -threaded
|
||||
if os(darwin)
|
||||
ghc-options: -dynamic
|
10
frontend/src-bin/main.hs
Normal file
10
frontend/src-bin/main.hs
Normal file
@ -0,0 +1,10 @@
|
||||
import Frontend
|
||||
import Common.Route
|
||||
import Obelisk.Frontend
|
||||
import Obelisk.Route.Frontend
|
||||
import Reflex.Dom
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
let Right validFullEncoder = checkEncoder backendRouteEncoder
|
||||
run $ runFrontend validFullEncoder frontend
|
23
frontend/src/Frontend.hs
Normal file
23
frontend/src/Frontend.hs
Normal file
@ -0,0 +1,23 @@
|
||||
{-# LANGUAGE DataKinds #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
module Frontend where
|
||||
|
||||
import qualified Data.Text as T
|
||||
import Obelisk.Frontend
|
||||
import Obelisk.Route
|
||||
import Reflex.Dom.Core
|
||||
|
||||
import Common.Api
|
||||
import Common.Route
|
||||
import Obelisk.Generated.Static
|
||||
|
||||
|
||||
frontend :: Frontend (R FrontendRoute)
|
||||
frontend = Frontend
|
||||
{ _frontend_head = el "title" $ text "Obelisk Minimal Example"
|
||||
, _frontend_body = do
|
||||
text "Welcome to Obelisk!"
|
||||
el "p" $ text $ T.pack commonStuff
|
||||
elAttr "img" ("src" =: static @"obelisk.jpg") blank
|
||||
}
|
BIN
static/obelisk.jpg
Normal file
BIN
static/obelisk.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
Loading…
Reference in New Issue
Block a user