Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactorings

  • Loading branch information...
commit 1da2450a4038da41828c4936bbbc8f1edfffaf8d 1 parent 5ee1096
@bergmark bergmark authored
Showing with 21 additions and 21 deletions.
  1. +8 −18 src/Snap/Snaplet/Fay.hs
  2. +13 −3 src/Snap/Snaplet/Fay/Internal.hs
View
26 src/Snap/Snaplet/Fay.hs
@@ -3,8 +3,7 @@
{-# OPTIONS -fno-warn-name-shadowing #-}
module Snap.Snaplet.Fay (
- CompileMethod (..)
- , Fay
+ Fay
, initFay
, fayServe
) where
@@ -51,23 +50,19 @@ initFay = makeSnaplet "fay" description datadir $ do
let fay = case opts of
(Just verbose, Just compileMethod, Just prettyPrint) ->
- Fay (toSrcDir fp) (toDestDir fp) [toSrcDir fp] verbose compileMethod prettyPrint
+ Fay fp verbose compileMethod prettyPrint
_ -> error $ intercalate "\n" errs
- liftIO $ do
- -- Create the snaplet directory
- dirExists <- doesDirectoryExist fp
- unless dirExists $ createDirectory fp
- -- Create the src directory
- dirExists <- doesDirectoryExist $ toSrcDir fp
- unless dirExists . createDirectory $ toSrcDir fp
- -- Create the js directory
- dirExists <- doesDirectoryExist (toDestDir fp)
- unless dirExists $ createDirectory (toDestDir fp)
+ -- Make sure snaplet/fay, snaplet/fay/src, snaplet/fay/js are present.
+ liftIO $ mapM_ createDirUnlessExists [fp, srcDir fay, destDir fay]
return fay
where
+ createDirUnlessExists fp = do
+ dirExists <- doesDirectoryExist fp
+ unless dirExists $ createDirectory fp
+
datadir = Just $ liftM (++ "/resources") getDataDir
description = "Automatic (re)compilation and serving of Fay files"
@@ -78,11 +73,6 @@ initFay = makeSnaplet "fay" description datadir $ do
when (isNothing res) (tell [err])
return res
- toSrcDir :: FilePath -> FilePath
- toSrcDir = (</> "src")
- toDestDir :: FilePath -> FilePath
- toDestDir = (</> "js")
-
-- | Serves the compiled Fay scripts using the chosen compile method.
fayServe :: Handler b Fay ()
fayServe = do
View
16 src/Snap/Snaplet/Fay/Internal.hs
@@ -14,14 +14,24 @@ import System.FilePath
-- | Configuration
data Fay = Fay {
- srcDir :: FilePath
- , destDir :: FilePath
- , includeDirs :: [FilePath]
+ snapletFilePath :: FilePath
, verbose :: Bool
, compileMethod :: CompileMethod
, prettyPrint :: Bool
}
+-- | Location of .hs files
+srcDir :: Fay -> FilePath
+srcDir = (</> "src") . snapletFilePath
+
+-- | Location of .js files
+destDir :: Fay -> FilePath
+destDir = (</> "js") . snapletFilePath
+
+-- | Where Fay should look for includes
+includeDirs :: Fay -> [FilePath]
+includeDirs = (:[]) . srcDir
+
data CompileMethod = CompileOnDemand | CompileAll
-- | Compile a single file, print errors if they occur and return the
Please sign in to comment.
Something went wrong with that request. Please try again.