From 72148feeb9836b0cdccd9c894ecbc12d54af1f1b Mon Sep 17 00:00:00 2001 From: hallgren Date: Fri, 17 Dec 2010 16:29:22 +0000 Subject: [PATCH] Install minibar and some example grammars along with pgf-http Together with the changes to pgf-http, this should make it much easier to run the PGF service and minibar locally. --- src/server/Setup.hs | 87 +++++++++++++++++++++++++++++++++++++- src/server/gf-server.cabal | 2 +- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/src/server/Setup.hs b/src/server/Setup.hs index c46cb0330..290fa3b8b 100644 --- a/src/server/Setup.hs +++ b/src/server/Setup.hs @@ -1,6 +1,89 @@ -module Main where +{-# OPTIONS_GHC -fwarn-unused-imports #-} + +import Control.Monad(when) +import System.Directory(createDirectoryIfMissing,doesFileExist, + getDirectoryContents,copyFile,removeFile) +import System.FilePath(()) +import System.Cmd(system) +import System.Exit(ExitCode(..)) import Distribution.Simple +import Distribution.Simple.Setup +import Distribution.Simple.LocalBuildInfo(datadir,buildDir,absoluteInstallDirs) main :: IO () -main = defaultMainWithHooks simpleUserHooks +main = defaultMainWithHooks simpleUserHooks{ postInst = instWWW + , postCopy = copyWWW + } +-------------------------------------------------------------------------------- +-- To test the GF web service and minibar, use "cabal install" (or +-- "runhaskell Setup.hs install") to install the program pgf-http, the +-- example grammars listed below, and the minibar. Then start the server with +-- the command "pgf-http" and open http://localhost:41296/minibar/minibar.html +-- in your web browser (Firefox, Safari, Opera or Chrome). + +example_grammars = + -- (pgf, tmp, src) + [("Foods.pgf","foods", + "..""..""contrib""summerschool""foods""Foods???.gf"), + ("Letter.pgf","letter", + "..""..""examples""letter""Letter???.gf")] + +minibar_src = "..""runtime""javascript""minibar" + +-------------------------------------------------------------------------------- +instWWW args flags pki lbi = setupWWW args dest pki lbi + where + dest = NoCopyDest + +copyWWW args flags pki lbi = setupWWW args dest pki lbi + where + dest = case copyDest flags of + NoFlag -> NoCopyDest + Flag d -> d + +setupWWW args dest pkg lbi = + do mapM_ (createDirectoryIfMissing True) [grammars_dir,minibar_dir] + mapM_ build_pgf example_grammars + copy_minibar + create_root_index + where + grammars_dir = www_dir "grammars" + minibar_dir = www_dir "minibar" + www_dir = datadir (absoluteInstallDirs pkg lbi dest) "www" + gfo_dir = buildDir lbi "gfo" + + build_pgf (pgf,tmp,src) = + do createDirectoryIfMissing True tmp_dir + execute cmd + copyFile pgf (grammars_dirpgf) + removeFile pgf + where + tmp_dir = gfo_dirtmp + cmd = "gf -make -s -optimize-pgf --gfo-dir="++tmp_dir++ + -- " --output-dir="++grammars_dir++ -- has no effect?! + " "++src + + copy_minibar = + do files <- getDirectoryContents minibar_src + mapM_ copy files + where + copy file = + do isFile <- doesFileExist src + when isFile $ copyFile src (minibar_dirfile) + where + src = minibar_srcfile + + create_root_index = writeFile (www_dir"index.html") index_html + + index_html = "

Available demos

\n" + ++"" + ++"Additional grammars can be installed in" + ++"
"++grammars_dir++"
" +execute command = + do putStrLn command + e <- system command + case e of + ExitSuccess -> return () + _ -> fail "Command failed" + return () diff --git a/src/server/gf-server.cabal b/src/server/gf-server.cabal index 8551f0e51..fe7ad17c8 100644 --- a/src/server/gf-server.cabal +++ b/src/server/gf-server.cabal @@ -1,7 +1,7 @@ name: gf-server version: 1.0 cabal-version: >= 1.2 -build-type: Simple +build-type: Custom license: GPL license-file: LICENSE synopsis: FastCGI Server for Grammatical Framework