-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d8f9f86
Showing
8 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
|
||
# Created by https://www.gitignore.io/api/haskell,emacs | ||
|
||
### Haskell ### | ||
dist | ||
dist-* | ||
cabal-dev | ||
*.o | ||
*.hi | ||
*.chi | ||
*.chs.h | ||
*.dyn_o | ||
*.dyn_hi | ||
.hpc | ||
.hsenv | ||
.cabal-sandbox/ | ||
cabal.sandbox.config | ||
*.prof | ||
*.aux | ||
*.hp | ||
*.eventlog | ||
.stack-work/ | ||
cabal.project.local | ||
.HTF/ | ||
|
||
|
||
### Emacs ### | ||
# -*- mode: gitignore; -*- | ||
*~ | ||
\#*\# | ||
/.emacs.desktop | ||
/.emacs.desktop.lock | ||
*.elc | ||
auto-save-list | ||
tramp | ||
.\#* | ||
|
||
# Org-mode | ||
.org-id-locations | ||
*_archive | ||
|
||
# flymake-mode | ||
*_flymake.* | ||
|
||
# eshell files | ||
/eshell/history | ||
/eshell/lastdir | ||
|
||
# elpa packages | ||
/elpa/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Copyright (c) 2022, Gil Mizrahi | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
* Neither the name of Gil Mizrahi nor the names of other | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import qualified Bulletin | ||
|
||
main :: IO () | ||
main = Bulletin.main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Building a bulletin board using Haskell, twain and friends | ||
|
||
Check out the [blog post](https://gilmi.me/blog/post/2020/12/05/scotty-bulletin-board) for the scotty tutorial. | ||
This version uses [twain](https://hackage.haskell.org/package/twain) instead. | ||
|
||
## Run with | ||
|
||
|
||
```sh | ||
stack build && stack run | ||
``` | ||
|
||
## Static executable | ||
|
||
To compile a static executable using docker, uncomment the relevant lines in the `stack.yaml` file, | ||
and rebuild with `stack build`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{-# language OverloadedStrings #-} | ||
|
||
-- | A bulletin board app built with twain. | ||
module Bulletin where | ||
|
||
import qualified Web.Twain as Twain | ||
import Network.Wai.Handler.Warp (run, Port) | ||
|
||
-- | Entry point. Starts a bulletin-board server at port 3000. | ||
main :: IO () | ||
main = runServer 3000 | ||
|
||
-- | Run a bulletin-board server at at specific port. | ||
runServer :: Port -> IO () | ||
runServer port = do | ||
putStrLn $ unwords | ||
[ "Running bulletin board app at" | ||
, "http://localhost:" <> show port | ||
, "(ctrl-c to quit)" | ||
] | ||
run port mkApp | ||
|
||
-- | Bulletin board application description. | ||
mkApp :: Twain.Application | ||
mkApp = | ||
foldr ($) | ||
(Twain.notFound $ Twain.send $ Twain.text "Error: not found.") | ||
routes | ||
|
||
-- | Bulletin board routing. | ||
routes :: [Twain.Middleware] | ||
routes = | ||
-- Our main page, which will display all of the bulletins | ||
[ Twain.get "/" $ | ||
Twain.send $ Twain.text "not yet implemented" | ||
|
||
-- A page for a specific post | ||
, Twain.get "/post/:id" $ | ||
Twain.send $ Twain.text "not yet implemented" | ||
|
||
-- A page for creating a new post | ||
, Twain.get "/new" $ | ||
Twain.send $ Twain.text "not yet implemented" | ||
|
||
-- A request to submit a new page | ||
, Twain.post "/new" $ | ||
Twain.send $ Twain.text "not yet implemented" | ||
|
||
-- A request to delete a specific post | ||
, Twain.post "/post/:id/delete" $ | ||
Twain.send $ Twain.text "not yet implemented" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
resolver: nightly-2022-04-06 | ||
|
||
# uncomment for static executables | ||
# docker: | ||
# enable: true | ||
# image: utdemir/ghc-musl:v24-ghc922 | ||
|
||
packages: | ||
- . | ||
|
||
extra-deps: | ||
- twain-2.1.0.0 | ||
|
||
allow-newer: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This file was autogenerated by Stack. | ||
# You should not edit this file by hand. | ||
# For more information, please see the documentation at: | ||
# https://docs.haskellstack.org/en/stable/lock_files | ||
|
||
packages: | ||
- completed: | ||
hackage: twain-2.1.0.0@sha256:9b434a5290791ab370845ded0d2167377cdc1478a592b87c5f5a9d499d069ba3,1864 | ||
pantry-tree: | ||
size: 500 | ||
sha256: 09cd5490f751e8740f294483d02987a2a387b7dfd4b0db0b0d66c9cd391a9d48 | ||
original: | ||
hackage: twain-2.1.0.0 | ||
snapshots: | ||
- completed: | ||
size: 545843 | ||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2022/4/6.yaml | ||
sha256: e59512928378e2411fea0269b3a658e31c8b24c9824dc213361dcce50a2b3f29 | ||
original: nightly-2022-04-06 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: twain-bulletin-app | ||
version: 0.1.0.0 | ||
synopsis: A simple bulletin board web app using twain | ||
description: Please see readme.md | ||
homepage: https://github.com/soupi/learn-twain-bulletin-app | ||
license-file: LICENSE | ||
author: Gil Mizrahi | ||
maintainer: gilmi@posteo.net | ||
copyright: 2022 Gil Mizrahi | ||
category: Web | ||
build-type: Simple | ||
cabal-version: >=1.10 | ||
extra-source-files: readme.md | ||
|
||
library | ||
hs-source-dirs: src | ||
exposed-modules: Bulletin | ||
|
||
ghc-options: -Wall -fno-warn-type-defaults | ||
default-language: Haskell2010 | ||
build-depends: base >= 4.7 && < 5 | ||
, text >= 2 | ||
, containers | ||
, time | ||
, stm | ||
, twain >= 2.1.0.0 | ||
, warp | ||
, wai-extra | ||
, lucid | ||
|
||
executable bulletin-app | ||
hs-source-dirs: app | ||
main-is: Main.hs | ||
default-language: Haskell2010 | ||
ghc-options: -Wall -static -optl-static -optl-pthread -fPIC -O -threaded -rtsopts -with-rtsopts=-N | ||
build-depends: base >= 4.7 && < 5 | ||
, twain-bulletin-app |