View StaticRewrite.hs
-- something like this can be used to make friendlier urls for the static pages
-- import Network.Wai.Middleware.Rewrite (rewritePure)
-- rewritePure rewriteConvert
rewriteConvert :: [Text] -> H.RequestHeaders -> [Text]
rewriteConvert pieces _ = staticRewrite pieces
where
staticRewrite :: [Text] -> [Text]
staticRewrite [] = homePage
staticRewrite ("static":"html":_) = homePage -- prevent direct access, not really necessary
staticRewrite route@("pages":_) | ".html" `T.isSuffixOf` last route = staticHtml ++ route
View combine.html.hamlet
$with scripts <- ["Prelude", "Config", "KV"]
^{combineScripts "app" scripts}
View static-pages.hs
import Prelude
import Yesod.Routes.Parse (staticPageRoutes)
import Yesod hiding (Request)
import Text.Hamlet
import Network.Wai
import Network.Wai.Test
import Data.Conduit (runResourceT)
import Blaze.ByteString.Builder (toLazyByteString)
import qualified Data.ByteString.Char8 as BS8
import qualified Data.ByteString.Lazy as LBS
View External.hs
module External where
import Language.Haskell.TH.Syntax
import Language.Haskell.TH.Lib
loadStringFromFile :: Q Exp
loadStringFromFile = do
let externalDependency = "external.txt"
qAddDependentFile externalDependency
s <- qRunIO $ readFile externalDependency
View mongoApp.hs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Yesod
import Database.Persist
import Database.Persist.MongoDB
View pid-wrap
#!/bin/bash
DIR="$( cd "$( dirname "$0" )" && pwd )"
cd $DIR/..
name=`basename "$2"`
case $1 in
'start')
echo $ > ./tmp/$name.pid
exec $2 2>&1 1> ./log/$name.log
View memoized methods
def self.cached_method(meth)
eval <<-CODE
def #{meth}_with_cache
return @#{meth} if @#{meth}
result = #{meth}_without_cache
@#{meth} ||= result
end
CODE
alias_method_chain meth, :cache
end