tools: fancy .ghci for hledger-web

Some configuration for running hledger-web in ghci, and misc. utilities
including hlint/hoogle/hayoo and a not-yet-working yesod devel-like
reloader from a recent reddit thread. (If enabling these, also uncomment
the required libs in hledger-web.cabal). Although it's not yet
automated, we can now test hledger-web changes without relinking:

>>> :serve
Starting web app on port 3000 with base url http://localhost:3000
Press ctrl-c to quit
  C-c C-cInterrupted.
>>> :r
Ok, modules loaded: Settings, Main, Hledger.Web.Main, Application, Hledger.Web.Options, Settings.Development, Import, Handler.RootR, Handler.JournalR, Handler.RegisterR, Handler.SidebarR, Handler.Common, Handler.Utils, Foundation, Settings.StaticFiles, Handler.Post.
>>> :serve
Starting web app on port 3000 with base url http://localhost:3000
This commit is contained in:
Simon Michael 2014-07-06 10:38:41 -07:00
parent e13dd554a1
commit 7d984fb2e4
2 changed files with 76 additions and 2 deletions

View File

@ -1,2 +1,68 @@
:set -i.:config:dist/build/autogen
:set -XCPP -XTemplateHaskell -XQuasiQuotes -XTypeFamilies -XFlexibleContexts -XGADTs -XOverloadedStrings -XMultiParamTypeClasses -XGeneralizedNewtypeDeriving -XEmptyDataDecls
-- -*- haskell -*-
-- .ghci for hledger-web
-- yesod
:set -i.:config:dist/build/autogen:app
:set -XCPP -XTemplateHaskell -XQuasiQuotes -XTypeFamilies -XFlexibleContexts -XGADTs -XOverloadedStrings -XMultiParamTypeClasses -XGeneralizedNewtypeDeriving -XEmptyDataDecls -XDeriveDataTypeable
import Prelude
-- hledger-web
:def serve const . return $ ":main --server --port 3000 -f t.j"
-- misc
import Control.Applicative
import Data.Char
import Data.List
import qualified Data.Text as T
import Data.Text (Text)
:set prompt "λ "
:def hlint \s -> return $ ":! hlint \"" ++ s ++ "\""
:def hoogle \s -> return $ ":! hoogle --count=15 \"" ++ s ++ "\""
:def doc \s -> return $ ":! hoogle --info \"" ++ s ++ "\""
:def pl \s -> return $ ":! pointfree \"" ++ s ++ "\""
-- extra
-- -- hayoo search (requires hsdev, mtl)
-- -- λ :hayoo (a -> c) -> (b -> c)
-- -- either :: (a -> c) -> (b -> c) -> Either a b -> c
-- -- Case analysis for the Either type.
-- -- If the value is Left a, apply the first function to a;
-- -- if it is Right b, apply the second function to b.
-- -- -- Defined in 'Prelude', base
-- import Control.Monad.Error
-- import HsDev.Tools.Hayoo
-- :{
-- let
-- showHayooFunction f =
-- (hayooName f ++ " :: " ++ hayooSignature f) :
-- (map ('\t':) $
-- lines (untagDescription (hayooDescription f)) ++
-- ["-- Defined in '" ++ hayooModule f ++ "', " ++ hayooPackage f])
-- showHayoo = concatMap showHayooFunction . hayooFunctions
-- :}
-- :def hayoo \s -> return $ "runErrorT (hayoo \"" ++ s ++ "\") >>= (mapM_ putStrLn) . either (return . (\"Error: \" ++)) showHayoo"
-- -- watch for changes and restart, like yesod devel in interpreted mode (requires fsnotify)
-- -- from https://gist.github.com/rehno-lindeque/10490026
-- import System.FSNotify
-- import Data.String
-- import Control.Concurrent.MVar
-- import Control.Concurrent
-- :{
-- :def serveAndReload const (withManager (\manager ->
-- do putStrLn "Listening to changes, press any key to stop..."
-- lock <- newEmptyMVar
-- watchTree manager (fromString ".") (const True) (const $ putMVar lock True)
-- forkIO (getLine >> putMVar lock False)
-- rerun <- readMVar lock
-- return $ if rerun
-- then ":reload \n :main Development\n :serveAndReload"
-- else ""
-- ))
-- :}

View File

@ -165,6 +165,10 @@ library
, yesod-core
, yesod-static
, json
-- required by extra ghci utilities:
-- , fsnotify
-- , hsdev
-- , mtl
if flag(blaze_html_0_4)
cpp-options: -DBLAZE_HTML_0_4
@ -258,6 +262,10 @@ executable hledger-web
, yesod-core
, yesod-static
, json
-- required by extra ghci utilities:
-- , fsnotify
-- , hsdev
-- , mtl
if flag(blaze_html_0_4)
cpp-options: -DBLAZE_HTML_0_4