Skip to content

Commit

Permalink
Merge pull request #199 from dmjio/website
Browse files Browse the repository at this point in the history
haskell-miso.org
  • Loading branch information
dmjio authored Jul 25, 2017
2 parents 8f6a295 + d51f1d8 commit c3c7e21
Show file tree
Hide file tree
Showing 21 changed files with 1,100 additions and 33 deletions.
5 changes: 5 additions & 0 deletions examples/haskell-miso.org/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for haskell-miso

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
30 changes: 30 additions & 0 deletions examples/haskell-miso.org/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright (c) 2017, David Johnson

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 David Johnson 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.
2 changes: 2 additions & 0 deletions examples/haskell-miso.org/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
39 changes: 39 additions & 0 deletions examples/haskell-miso.org/client/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{-# LANGUAGE RecordWildCards #-}
module Main where

import Common
import Data.Proxy
import Network.URI

import Miso
import Miso.String

instance HasURI Model where
lensURI = makeLens getter setter
where
getter = uri
setter = \m u -> m { uri = u }

main :: IO ()
main = do
currentURI <- getCurrentURI
miso App { model = Model currentURI, ..}
where
initialAction = NoOp
update = updateModel
events = defaultEvents
subs = [ uriSub HandleURI ]
view m =
either (const $ the404 m) id $
runRoute (Proxy :: Proxy ClientRoutes) handlers m

updateModel :: Action -> Model -> Effect Model Action
updateModel (HandleURI u) m = m { uri = u } <# do
pure NoOp
updateModel (ChangeURI u) m = m <# do
pushURI u
pure NoOp
updateModel Alert m@Model{..} = m <# do
alert $ pack (show uri)
pure NoOp
updateModel NoOp m = noEff m
12 changes: 12 additions & 0 deletions examples/haskell-miso.org/client/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ mkDerivation, aeson, base, containers, miso, servant, stdenv, network-uri }:
mkDerivation {
pname = "haskell-miso";
version = "0.1.0.0";
src = ../.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [ aeson base containers miso servant network-uri ];
homepage = "https://haskell-miso.org";
description = "https://haskell-miso.org";
license = stdenv.lib.licenses.bsd3;
}
16 changes: 16 additions & 0 deletions examples/haskell-miso.org/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ pkgs ? import <nixpkgs> {} }:
let
inherit (pkgs) runCommand closurecompiler;
inherit (pkgs.haskell.packages) ghcjs ghc802;
miso-ghc = ghc802.callPackage ./../../miso-ghc.nix { };
miso-ghcjs = ghcjs.callPackage ./../../miso-ghcjs.nix { };
client = ghcjs.callPackage ./client { miso = miso-ghcjs; };
server = ghc802.callPackage ./server { miso = miso-ghc; };
in
runCommand "haskell-miso.org" { inherit client server; } ''
mkdir -p $out/{bin,static}
cp ${client}/bin/client.jsexe/all.js $out/static/all.js
cp ${server}/bin/* $out/bin
''


60 changes: 60 additions & 0 deletions examples/haskell-miso.org/haskell-miso.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: haskell-miso
version: 0.1.0.0
synopsis: https://haskell-miso.org
description: Website for the Miso web framework
homepage: https://haskell-miso.org
license: BSD3
license-file: LICENSE
author: David Johnson
maintainer: djohnson.m@gmail.com
copyright: David Johnson (c) 2017
category: Web
build-type: Simple
extra-source-files: ChangeLog.md
cabal-version: >=1.10

executable server
main-is:
Main.hs
if impl(ghcjs)
buildable: False
else
ghc-options:
-O2 -threaded -Wall -rtsopts
hs-source-dirs:
server, shared
build-depends:
aeson,
base < 5,
containers,
http-types,
lucid,
miso,
mtl,
network-uri,
servant,
servant-lucid,
servant-server,
wai,
wai-extra,
warp
default-language:
Haskell2010

executable client
main-is:
Main.hs
if !impl(ghcjs)
buildable: False
else
hs-source-dirs:
client, shared
build-depends:
aeson,
base < 5,
containers,
network-uri,
miso,
servant
default-language:
Haskell2010
24 changes: 24 additions & 0 deletions examples/haskell-miso.org/nix/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ pkgs, config, ... }:
{
imports = [ ./module.nix ];
nixpkgs.config.packageOverrides = pkgs: {
haskell-miso = import ./../default.nix {};
};
services = {
haskell-miso.enable = true;
nginx = {
enable = true;
virtualHosts = {
"haskell-miso.org" = {
forceSSL = true;
enableACME = true;
locations = {
"/" = {
proxyPass = "http://localhost:3002";
};
};
};
};
};
};
}
25 changes: 25 additions & 0 deletions examples/haskell-miso.org/nix/module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ options, lib, config, pkgs, modulesPath }:
let
cfg = config.services.haskell-miso;
in {
options.services.haskell-miso.enable = lib.mkEnableOption "Enable the haskell-miso.org service";
config = lib.mkIf cfg.enable {
systemd.services.haskell-miso = {
path = with pkgs; [ haskell-miso bash ];
wantedBy = [ "multi-user.target" ];
script = ''
./bin/server +RTS -N -A4M -RTS
'';
description = ''
https://haskell-miso.org
'';
serviceConfig = {
WorkingDirectory=pkgs.haskell-miso;
KillSignal="INT";
Type = "simple";
Restart = "on-abort";
RestartSec = "10";
};
};
};
}
123 changes: 123 additions & 0 deletions examples/haskell-miso.org/server/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeApplications #-}
module Main where

import Common
import Data.Proxy
import qualified Lucid as L
import Lucid.Base
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Handler.Warp
import Network.Wai.Middleware.Gzip
import Network.Wai.Middleware.RequestLogger
import Servant
import qualified System.IO as IO

import Miso
import Miso.String

main :: IO ()
main = do
IO.hPutStrLn IO.stderr "Running on port 3002..."
run 3002 $ logStdout (compress app)
where
compress = gzip def { gzipFiles = GzipCompress }

app :: Application
app = serve (Proxy @ API) (static :<|> serverHandlers :<|> handle404)
where
static = serveDirectory "static"

-- | Wrapper for setting HTML doctype and header
newtype Wrapper a = Wrapper a
deriving (Show, Eq)

-- | Convert client side routes into server-side web handlers
type ServerRoutes = ToServerRoutes ClientRoutes Wrapper Action

-- | API type
type API = ("static" :> Raw)
:<|> ServerRoutes
:<|> Raw

handle404 :: Application
handle404 _ respond = respond $ responseLBS
status404
[("Content-Type", "text/html")] $
renderBS $ toHtml $ Wrapper $ the404 Model { uri = goHome }

instance L.ToHtml a => L.ToHtml (Wrapper a) where
toHtmlRaw = L.toHtml
toHtml (Wrapper x) =
L.doctypehtml_ $ do
L.head_ $ do
L.meta_ [L.charset_ "utf-8"]
L.meta_ [ L.httpEquiv_ "X-UA-Compatible"
, L.content_ "IE=edge"
]
L.meta_ [ L.name_ "viewport"
, L.content_ "width=device-width, initial-scale=1"
]
L.meta_ [ L.name_ "description"
, L.content_ "Miso is a small isomorphic Haskell front-end framework featuring a virtual-dom, diffing / patching algorithm, event delegation, event batching, SVG, Server-sent events, Websockets, type-safe servant-style routing and an extensible Subscription-based subsystem. Inspired by Elm, Redux and Bobril. Miso is pure by default, but side effects (like XHR) can be introduced into the system via the Effect data type. Miso makes heavy use of the GHCJS FFI and therefore has minimal dependencies."
]
cssRef animateRef
cssRef bulmaRef
cssRef fontAwesomeRef
jsRef "https://buttons.github.io/buttons.js"
L.script_ analytics
jsRef "static/all.js"
L.body_ (L.toHtml x)
where
jsRef href =
L.with (L.script_ mempty)
[ makeAttribute "src" href
, makeAttribute "async" mempty
, makeAttribute "defer" mempty
]
cssRef href =
L.with (L.link_ mempty) [
L.rel_ "stylesheet"
, L.type_ "text/css"
, L.href_ href
]

fontAwesomeRef :: MisoString
fontAwesomeRef = "https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"

animateRef :: MisoString
animateRef = "https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css"

bulmaRef :: MisoString
bulmaRef = "https://cdnjs.cloudflare.com/ajax/libs/bulma/0.4.3/css/bulma.min.css"

analytics :: MisoString
analytics =
"(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\
\(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\
\m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\
\})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');\
\ga('create', 'UA-102668481-1', 'auto');\
\ga('send', 'pageview');"

serverHandlers ::
Handler (Wrapper (View Action))
:<|> Handler (Wrapper (View Action))
:<|> Handler (Wrapper (View Action))
:<|> Handler (Wrapper (View Action))
serverHandlers = examplesHandler
:<|> docsHandler
:<|> communityHandler
:<|> homeHandler
where
send f u = pure $ Wrapper $ f Model {uri = u}
homeHandler = send home goHome
examplesHandler = send examples goExamples
docsHandler = send docs goDocs
communityHandler = send community goCommunity

18 changes: 18 additions & 0 deletions examples/haskell-miso.org/server/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ mkDerivation, aeson, base, containers, lucid, miso, mtl
, network-uri, servant, servant-lucid, servant-server, stdenv, time
, wai-extra, warp
}:
mkDerivation {
pname = "haskell-miso";
version = "0.1.0.0";
src = ../.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [
aeson base containers lucid miso mtl network-uri servant
servant-lucid servant-server time wai-extra warp
];
homepage = "https://haskell-miso.org";
description = "https://haskell-miso.org";
license = stdenv.lib.licenses.bsd3;
}
Loading

0 comments on commit c3c7e21

Please sign in to comment.