mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-15 15:59:32 -06:00
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.
This commit is contained in:
@@ -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_dir</>pgf)
|
||||
removeFile pgf
|
||||
where
|
||||
tmp_dir = gfo_dir</>tmp
|
||||
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_dir</>file)
|
||||
where
|
||||
src = minibar_src</>file
|
||||
|
||||
create_root_index = writeFile (www_dir</>"index.html") index_html
|
||||
|
||||
index_html = "<h2>Available demos</h2>\n"
|
||||
++"<ul><li><a href=\"minibar/minibar.html\">Minibar</a></ul>"
|
||||
++"Additional grammars can be installed in"
|
||||
++"<blockquote><code>"++grammars_dir++"</code></blockquote>"
|
||||
execute command =
|
||||
do putStrLn command
|
||||
e <- system command
|
||||
case e of
|
||||
ExitSuccess -> return ()
|
||||
_ -> fail "Command failed"
|
||||
return ()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user