Skip to content

Commit

Permalink
init ob project
Browse files Browse the repository at this point in the history
  • Loading branch information
dfordivam committed Nov 9, 2018
1 parent 60275ca commit 5825358
Show file tree
Hide file tree
Showing 20 changed files with 230 additions and 34 deletions.
40 changes: 6 additions & 34 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,35 +1,7 @@
dist
dist-newstyle
dist-ghcjs
cabal-dev
*.o
*.hi
*.chi
*.chs.h
*.dyn_hi
*.dyn_o
*.p_hi
*.p_o
*.js_dyn_hi
*.js_dyn_o
*.js_p_hi
*.js_p_o
*.js_o
*.js_hi
.virthualenv
.hsenv*
*.*~
*.swp
.DS_Store
backend.pid
backend.out
.shelly
TAGS
tags
*~
*.orig
hsenv.log
\#*#
.#*
src/Main
*.jsexe
result
result-android
result-ios
result-exe
.attr-cache
ghcid-output.txt
7 changes: 7 additions & 0 deletions .obelisk/impl/default.nix
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions .obelisk/impl/github.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"owner": "obsidiansystems",
"repo": "obelisk",
"branch": "master",
"rev": "59456f318f9618ce12e78f5937a968c58071b686",
"sha256": "06y25i3s0daa417j7j2if3k8y66wb8zgszhlclw4nq0427jf3d2y"
}
28 changes: 28 additions & 0 deletions backend/backend.cabal
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions backend/frontend.jsexe
1 change: 1 addition & 0 deletions backend/frontendJs/frontend.jsexe
6 changes: 6 additions & 0 deletions backend/src-bin/main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Backend
import Frontend
import Obelisk.Backend

main :: IO ()
main = runBackend backend frontend
15 changes: 15 additions & 0 deletions backend/src/Backend.hs
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions backend/static
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
optional-packages:
*
15 changes: 15 additions & 0 deletions common/common.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: common
version: 0.1
cabal-version: >= 1.2
build-type: Simple

library
hs-source-dirs: src
build-depends: base
, obelisk-route
, mtl
, text

exposed-modules:
Common.Api
Common.Route
4 changes: 4 additions & 0 deletions common/src/Common/Api.hs
Original file line number Diff line number Diff line change
@@ -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 changes: 52 additions & 0 deletions common/src/Common/Route.hs
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions config/common/route
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://localhost:8000
9 changes: 9 additions & 0 deletions config/readme.md
Original file line number Diff line number Diff line change
@@ -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/
10 changes: 10 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ system ? builtins.currentSystem # TODO: Get rid of this system cruft
, iosSdkVersion ? "10.2"
}:
with import ./.obelisk/impl { inherit system iosSdkVersion; };
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 changes: 32 additions & 0 deletions frontend/frontend.cabal
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions frontend/src-bin/main.hs
Original file line number Diff line number Diff line change
@@ -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 changes: 23 additions & 0 deletions frontend/src/Frontend.hs
Original file line number Diff line number Diff line change
@@ -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
}
Binary file added static/obelisk.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5825358

Please sign in to comment.