Permalink
Browse files

Serve static assets

  • Loading branch information...
1 parent 947aac1 commit d6ad2399b96e1874d393a95cb2eac0c852e40a1b @singpolyma committed Mar 23, 2013
Showing with 48 additions and 77 deletions.
  1. +0 −3 Application.hs
  2. +11 −3 Main.hs
  3. BIN assets/arrow_down.gif
  4. +32 −0 assets/common.css
  5. BIN assets/logo.png
  6. +2 −36 view/home.mustache
  7. +3 −35 view/report.mustache
View
@@ -50,9 +50,6 @@ htmlEscape = concatMap escChar
responseTextBuilder :: Status -> ResponseHeaders -> TL.Builder -> Response
responseTextBuilder s h = ResponseBuilder s h . Blaze.fromLazyText . TL.toLazyText
-on404 :: Application
-on404 _ = string notFound404 [] "Not Found"
-
home :: URI -> Connection -> Application
home root db req =
return $ responseTextBuilder ok200 headers (viewHome htmlEscape $ HomeRec [Form $ forPath `relativeTo` root])
View
@@ -1,34 +1,42 @@
module Main (main) where
+import Prelude hiding (FilePath)
import Control.Monad (void)
import System.Environment (getArgs)
import Network.URI (parseAbsoluteURI, URI(..))
import Control.Error (err)
+import Filesystem.Path (FilePath)
+import Filesystem (getWorkingDirectory)
+import Network.Wai (Application)
import Network.Wai.Handler.Warp (run)
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
import Network.Wai.Middleware.Autohead (autohead)
import Network.Wai.Middleware.Jsonp (jsonp)
import Network.Wai.Middleware.AcceptOverride (acceptOverride)
+import Network.Wai.Application.Static (staticApp, defaultWebAppSettings)
import Database.SQLite.Simple (withConnection)
import Network.Wai.Dispatch
import Routes
-import Application
addTrailingSlash :: URI -> URI
addTrailingSlash u@(URI {uriPath = []}) = u {uriPath = "/"}
addTrailingSlash u@(URI {uriPath = p})
| last p == '/' = u
| otherwise = u {uriPath = p ++ "/"}
+staticRoot :: FilePath -> Application
+staticRoot = staticApp . defaultWebAppSettings
+
main :: IO ()
main = main' . map (fmap addTrailingSlash . parseAbsoluteURI) =<< getArgs
where
- main' [Just root@(URI {uriAuthority = Just _})] =
+ main' [Just root@(URI {uriAuthority = Just _})] = do
+ cwd <- getWorkingDirectory
void $ withConnection "./dev.db"
(\db -> run 3000 $
logStdoutDev $ autohead $ acceptOverride $ jsonp $ -- Middleware
- dispatch on404 $ routes root db) -- Do routing
+ dispatch (staticRoot cwd) $ routes root db) -- Do routing
main' _ = err "Usage: ./Main <Root URI>"
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,32 @@
+html, body {
+ background-color: #abcdef;
+ font-family: "Liberation Sans", sans-serif;
+}
+
+body {
+ margin-left: 10%;
+ margin-right: 10%;
+ margin-top: 2em;
+}
+
+body > h1 {
+ overflow: hidden;
+}
+
+h1 * {
+ vertical-align: middle;
+}
+
+h1 img {
+ float: left;
+ padding-right: 5em;
+}
+
+.rippleAddress {
+ font-size: 0.5em;
+}
+
+a[rel=enclosure] img {
+ position: relative;
+ top: 4px;
+}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -3,45 +3,11 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Ripple Union Credit Reports</title>
-
- <style type="text/css">
- html, body {
- background-color: #abcdef;
- font-family: "Liberation Sans", sans-serif;
- }
-
- body {
- margin-left: 10%;
- margin-right: 10%;
- margin-top: 2em;
- }
-
- body > h1 {
- overflow: hidden;
- }
-
- h1 * {
- vertical-align: middle;
- }
-
- h1 img {
- float: left;
- padding-right: 5em;
- }
-
- .rippleAddress {
- font-size: 0.5em;
- }
-
- a[rel=enclosure] img {
- position: relative;
- top: 4px;
- }
- </style>
+ <link rel="stylesheet" type="text/css" href="/assets/common.css" />
</head>
<body>
- <h1><img src="/logo.png" alt="Ripple Union" /> Credit Reports</h1>
+ <h1><img src="/assets/logo.png" alt="Ripple Union" /> Credit Reports</h1>
<p>This credit reporting system is designed to give support to Ripple.com organizations and users who want to extend credit to other users. Every time a user to whom you have extended credit makes a payment on that credit, you may submit an OpenPGP signed message saying:</p>
View
@@ -4,54 +4,22 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Ripple Union Credit Report for {{address}}</title>
+ <link rel="stylesheet" type="text/css" href="/assets/common.css" />
<style type="text/css">
- html, body {
- background-color: #abcdef;
- font-family: "Liberation Sans", sans-serif;
- }
-
- body {
- margin-left: 10%;
- margin-right: 10%;
- margin-top: 2em;
- }
-
- body > h1 {
- overflow: hidden;
- }
-
- h1 * {
- vertical-align: middle;
- }
-
- h1 img {
- float: left;
- padding-right: 5em;
- }
-
- .rippleAddress {
- font-size: 0.5em;
- }
-
- a[rel=enclosure] img {
- position: relative;
- top: 4px;
- }
-
input { display: block; }
</style>
</head>
<body>
- <h1><img src="/logo.png" alt="Ripple Union" /> Credit Report for <span class="rippleAddress">{{address}}</span></h1>
+ <h1><img src="/assets/logo.png" alt="Ripple Union" /> Credit Report for <span class="rippleAddress">{{address}}</span></h1>
<section>
<h1>Assertions</h1>
<ul>
{{#assertions}}
<li>
- <a href="data:application/pgp-encrypted;base64,{{signedAssertion}}" rel="enclosure"><img src="http://www.famfamfam.com/lab/icons/mini/icons/arrow_down.gif" alt="download signed assertion" title="download signed assertion" /></a>
+ <a href="data:application/pgp-encrypted;base64,{{signedAssertion}}" rel="enclosure"><img src="/assets/arrow_down.gif" alt="download signed assertion" title="download signed assertion" /></a>
<time datetime="{{at8601}}">{{atHuman}}</time> —
<a href="http://singpolyma.net:11371/pks/lookup?op=vindex&amp;search=0x{{#row}}{{fromFingerprint}}{{/row}}">{{keyId}}</a>

0 comments on commit d6ad239

Please sign in to comment.