diff --git a/Setup.hs b/Setup.hs index d136c943c..68d4035a4 100644 --- a/Setup.hs +++ b/Setup.hs @@ -1,4 +1,3 @@ -module Main where import Distribution.Simple import Distribution.Simple.LocalBuildInfo @@ -7,26 +6,34 @@ import Distribution.Simple.Utils import Distribution.Simple.Setup import Distribution.PackageDescription hiding (Flag) import Control.Monad -import Data.Maybe import Data.List(isPrefixOf) import System.IO import System.Cmd import System.FilePath import System.Directory -import System.Environment import System.Process import System.Exit +import WebSetup + main :: IO () main = defaultMainWithHooks simpleUserHooks{ preBuild =checkRGLArgs , postBuild=buildRGL , preInst =checkRGLArgs - , postInst =installRGL + , postInst =gfPostInst , preCopy =checkRGLArgs - , postCopy =copyRGL + , postCopy =gfPostCopy , sDistHook=sdistRGL , runTests =testRGL } + where + gfPostInst args flags pkg lbi = + do installWeb args flags pkg lbi + installRGL args flags pkg lbi + + gfPostCopy args flags pkg lbi = + do copyWeb args flags pkg lbi + copyRGL args flags pkg lbi -------------------------------------------------------- -- Commands for building the Resource Grammar Library diff --git a/WebSetup.hs b/WebSetup.hs new file mode 100644 index 000000000..c0ac0a66c --- /dev/null +++ b/WebSetup.hs @@ -0,0 +1,62 @@ +module WebSetup(installWeb,copyWeb) where + +import System.Directory(createDirectoryIfMissing,copyFile,removeFile) +import System.FilePath(()) +import System.Cmd(system) +import System.Exit(ExitCode(..)) +import Distribution.Simple.Setup(Flag(..),CopyDest(..),copyDest) +import Distribution.Simple.LocalBuildInfo(datadir,buildDir,absoluteInstallDirs) + +{- + To test the GF web services, the minibar and the grammar editor, use + "cabal install" (or "runhaskell Setup.hs install") to install gf as usual. + Then start the server with the command "gf -server" and + open http://localhost:41296/minibar/minibar.html in your web browser + (Firefox, Safari, Opera or Chrome). The example grammars listed below will + be available in the minibar. +-} + +example_grammars = -- :: [(pgf, tmp, src)] + [("Foods.pgf","foods","contrib""summerschool""foods""Foods???.gf"), + ("Letter.pgf","letter","examples""letter""Letter???.gf")] + + +installWeb args flags pki lbi = setupWeb args dest pki lbi + where + dest = NoCopyDest + +copyWeb args flags pki lbi = setupWeb args dest pki lbi + where + dest = case copyDest flags of + NoFlag -> NoCopyDest + Flag d -> d + +setupWeb args dest pkg lbi = + do putStrLn "setupWeb" + mapM_ (createDirectoryIfMissing True) [grammars_dir,cloud_dir] + mapM_ build_pgf example_grammars + where + grammars_dir = www_dir "grammars" + cloud_dir = www_dir "tmp" -- hmm + 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) + putStrLn (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 + +execute command = + do putStrLn command + e <- system command + case e of + ExitSuccess -> return () + _ -> fail "Command failed" + return () diff --git a/gf.cabal b/gf.cabal index 748066d31..105415964 100644 --- a/gf.cabal +++ b/gf.cabal @@ -12,10 +12,23 @@ homepage: http://www.grammaticalframework.org/ bug-reports: http://code.google.com/p/grammatical-framework/issues/list tested-with: GHC==6.12.3, GHC==7.0.3 +data-dir: src +data-files: www/index.html + www/gfse/*.html + www/gfse/*.css + www/gfse/*.js + www/gfse/P/*.png + www/gfse/P/*.jpg + www/minibar/*.html + www/minibar/*.css + www/minibar/*.js + www/minibar/*.png + source-repository head type: darcs location: http://www.grammaticalframework.org/ + flag interrupt Description: Enable Ctrl+Break in the shell Default: True diff --git a/src/compiler/GFServer.hs b/src/compiler/GFServer.hs index 6e9b26a8d..bc5bdbdaf 100644 --- a/src/compiler/GFServer.hs +++ b/src/compiler/GFServer.hs @@ -27,21 +27,19 @@ import qualified ExampleService as ES import Paths_gf(getDataDir) import RunHTTP(Options(..),cgiHandler) --- * Configuraiton - -options = Options { documentRoot = "." {-datadir"www"-}, port = gfport } -gfport = 41296 - -- * HTTP server server execute1 state0 = do state <- newMVar M.empty cache <- PS.newPGFCache - --datadir <- getDataDir - putStrLn $ "Starting server on port "++show gfport - initServer gfport (modifyMVar state . handle state0 cache execute1) + datadir <- getDataDir + let options = Options { documentRoot = datadir"www", port = 41296 } + putStrLn $ "Starting HTTP server, open http://localhost:" + ++show (port options)++"/ in your web browser." + initServer (port options) + (modifyMVar state . handle options state0 cache execute1) -- * HTTP request handler -handle state0 cache execute1 +handle options state0 cache execute1 rq@(Request method URI{uriPath=upath,uriQuery=q} hdrs body) state = do let qs = decodeQ $ case method of @@ -67,6 +65,8 @@ handle state0 cache execute1 where root = documentRoot options + translatePath rpath = rootrpath -- hmm, check for ".." + wrapCGI cgi = do resp <- cgiHandler root (handleErrors . handleCGIErrors $ cgi) rq return (state,resp) @@ -191,8 +191,6 @@ escape1 c = [c] -- * Static content -translatePath path = documentRoot optionspath -- hmm, check for ".." - serveStaticFile path = do b <- doesDirectoryExist path let path' = if b then path "index.html" else path diff --git a/src/editor/simple/Makefile b/src/www/gfse/Makefile similarity index 100% rename from src/editor/simple/Makefile rename to src/www/gfse/Makefile diff --git a/src/editor/simple/P/1306856253_weather_06.png b/src/www/gfse/P/1306856253_weather_06.png similarity index 100% rename from src/editor/simple/P/1306856253_weather_06.png rename to src/www/gfse/P/1306856253_weather_06.png diff --git a/src/editor/simple/P/1307545089_weather_04.png b/src/www/gfse/P/1307545089_weather_04.png similarity index 100% rename from src/editor/simple/P/1307545089_weather_04.png rename to src/www/gfse/P/1307545089_weather_04.png diff --git a/src/editor/simple/P/w1s.jpg b/src/www/gfse/P/w1s.jpg similarity index 100% rename from src/editor/simple/P/w1s.jpg rename to src/www/gfse/P/w1s.jpg diff --git a/src/editor/simple/P/w2s.jpg b/src/www/gfse/P/w2s.jpg similarity index 100% rename from src/editor/simple/P/w2s.jpg rename to src/www/gfse/P/w2s.jpg diff --git a/src/editor/simple/P/w3s.jpg b/src/www/gfse/P/w3s.jpg similarity index 100% rename from src/editor/simple/P/w3s.jpg rename to src/www/gfse/P/w3s.jpg diff --git a/src/editor/simple/P/w4s.jpg b/src/www/gfse/P/w4s.jpg similarity index 100% rename from src/editor/simple/P/w4s.jpg rename to src/www/gfse/P/w4s.jpg diff --git a/src/editor/simple/TODO b/src/www/gfse/TODO similarity index 100% rename from src/editor/simple/TODO rename to src/www/gfse/TODO diff --git a/src/editor/simple/about.html b/src/www/gfse/about.html similarity index 100% rename from src/editor/simple/about.html rename to src/www/gfse/about.html diff --git a/src/editor/simple/cloud.js b/src/www/gfse/cloud.js similarity index 100% rename from src/editor/simple/cloud.js rename to src/www/gfse/cloud.js diff --git a/src/editor/simple/cloud2.js b/src/www/gfse/cloud2.js similarity index 100% rename from src/editor/simple/cloud2.js rename to src/www/gfse/cloud2.js diff --git a/src/editor/simple/editor.css b/src/www/gfse/editor.css similarity index 100% rename from src/editor/simple/editor.css rename to src/www/gfse/editor.css diff --git a/src/editor/simple/editor.js b/src/www/gfse/editor.js similarity index 100% rename from src/editor/simple/editor.js rename to src/www/gfse/editor.js diff --git a/src/editor/simple/example_based.js b/src/www/gfse/example_based.js similarity index 100% rename from src/editor/simple/example_based.js rename to src/www/gfse/example_based.js diff --git a/src/editor/simple/gf_abs.js b/src/www/gfse/gf_abs.js similarity index 100% rename from src/editor/simple/gf_abs.js rename to src/www/gfse/gf_abs.js diff --git a/src/editor/simple/gfse.manifest b/src/www/gfse/gfse.manifest similarity index 100% rename from src/editor/simple/gfse.manifest rename to src/www/gfse/gfse.manifest diff --git a/src/editor/simple/grammars.cgi b/src/www/gfse/grammars.cgi similarity index 100% rename from src/editor/simple/grammars.cgi rename to src/www/gfse/grammars.cgi diff --git a/src/editor/simple/index.html b/src/www/gfse/index.html similarity index 92% rename from src/editor/simple/index.html rename to src/www/gfse/index.html index 27b053300..c683a1ebf 100644 --- a/src/editor/simple/index.html +++ b/src/www/gfse/index.html @@ -32,7 +32,7 @@ This page does not work without JavaScript.
HTML - Last modified: Mon Oct 10 17:54:37 CEST 2011 + Last modified: Mon Oct 10 19:24:05 CEST 2011
About

@@ -42,7 +42,7 @@ HTML
 
 
 
-
+
 
 
 
diff --git a/src/editor/simple/localstorage.js b/src/www/gfse/localstorage.js
similarity index 100%
rename from src/editor/simple/localstorage.js
rename to src/www/gfse/localstorage.js
diff --git a/src/editor/simple/molto.css b/src/www/gfse/molto.css
similarity index 100%
rename from src/editor/simple/molto.css
rename to src/www/gfse/molto.css
diff --git a/src/editor/simple/save.hs b/src/www/gfse/save.hs
similarity index 100%
rename from src/editor/simple/save.hs
rename to src/www/gfse/save.hs
diff --git a/src/editor/simple/share.html b/src/www/gfse/share.html
similarity index 86%
rename from src/editor/simple/share.html
rename to src/www/gfse/share.html
index 643d298ba..260a7b066 100644
--- a/src/editor/simple/share.html
+++ b/src/www/gfse/share.html
@@ -13,12 +13,12 @@
 
 
- Last modified: Mon Aug 1 16:24:44 CEST 2011 + Last modified: Mon Oct 10 20:29:01 CEST 2011 - +