snaplet-fay 0.3.0.1 → 0.3.1.0
raw patch · 4 files changed
+58/−30 lines, 4 filesdep ~basedep ~bytestringdep ~configurator
Dependency ranges changed: base, bytestring, configurator, data-default, directory, fay, snap, snap-core
Files
- resources/devel.cfg +5/−0
- snaplet-fay.cabal +13/−13
- src/Snap/Snaplet/Fay.hs +13/−4
- src/Snap/Snaplet/Fay/Internal.hs +27/−13
resources/devel.cfg view
@@ -18,3 +18,8 @@ # snaplets/fay/src will always be checked for imports. # Default is "" meaning no additional directories will be checked. includeDirs = ""+# A comma separated list of Fay package names.+# This gives the same result as using includeDirs,+# except Fay figures out the paths for you.+# Default is "" meaning no other Fay packages will be used.+packages = ""
snaplet-fay.cabal view
@@ -5,7 +5,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 0.3.0.1+version: 0.3.1.0 synopsis: Fay integration for Snap with request- and pre-compilation. description: Fay integration for Snap with request based compilation during development and precompilation in production. For more information, please see <https://github.com/faylang/snaplet-fay>.@@ -39,15 +39,15 @@ Snap.Snaplet.Fay.Internal, Paths_snaplet_fay build-depends:- aeson == 0.6.*,- base == 4.5.*,- bytestring == 0.9.*,- configurator == 0.2.*,- data-default >= 0.4,- directory == 1.1.*,- fay >= 0.11,- filepath == 1.3.*,- mtl == 2.1.*,- snap >= 0.9 && < 0.11,- snap-core == 0.9.*,- transformers == 0.3.*+ base == 4.*+ , aeson >= 0.6+ , bytestring >= 0.9+ , configurator >= 0.2+ , data-default >= 0.5+ , directory >= 1.1+ , fay >= 0.14.1+ , filepath >= 1.3+ , mtl >= 2.1+ , snap >= 0.11.1+ , snap-core >= 0.9.3.1+ , transformers >= 0.3
src/Snap/Snaplet/Fay.hs view
@@ -25,7 +25,7 @@ import Data.List import Data.Maybe import Data.String-import Language.Fay.Convert+import Fay.Convert import Snap.Core import Snap.Snaplet import Snap.Util.FileServe@@ -51,11 +51,20 @@ includeDirs <- logErr "Must specify includeDirs" $ C.lookup config "includeDirs" let inc = maybe [] (split ',') includeDirs inc' <- liftIO $ mapM canonicalizePath inc- return (verbose, compileMode, prettyPrint, inc')+ packages <- logErr "Must specify packages" $ C.lookup config "packages"+ let packs = maybe [] (split ',') packages+ return (verbose, compileMode, prettyPrint, inc', packs) let fay = case opts of- (Just verbose, Just compileMode, Just prettyPrint, includeDirs) ->- Fay fp verbose compileMode prettyPrint (fp : includeDirs)+ (Just verbose, Just compileMode, Just prettyPrint, includeDirs, packages) ->+ Fay+ { snapletFilePath = fp+ , verbose = verbose+ , compileMode = compileMode+ , prettyPrint = prettyPrint+ , _includeDirs = fp : includeDirs+ , packages = packages+ } _ -> error $ intercalate "\n" errs -- Make sure snaplet/fay, snaplet/fay/src, snaplet/fay/js are present.
src/Snap/Snaplet/Fay/Internal.hs view
@@ -4,8 +4,11 @@ import Control.Applicative import Control.Monad+import qualified Data.Aeson as A+import qualified Data.ByteString.Lazy.Char8 as C import Data.Default-import qualified Language.Fay as F+import qualified Fay as F+import qualified Fay.Compiler.Config as F import System.Directory import System.FilePath @@ -13,11 +16,12 @@ -- | Configuration data Fay = Fay { snapletFilePath :: FilePath- , verbose :: Bool- , compileMode :: CompileMode- , prettyPrint :: Bool- , _includeDirs :: [FilePath]- }+ , verbose :: Bool+ , compileMode :: CompileMode+ , prettyPrint :: Bool+ , _includeDirs :: [FilePath]+ , packages :: [String]+ } deriving (Show) -- | Location of .hs files srcDir :: Fay -> FilePath@@ -33,7 +37,7 @@ -- | Compile on every request or when Snap starts. data CompileMode = Development | Production- deriving Eq+ deriving (Eq, Show) -- | Used by callers of compileFile to get the status of compilation. data CompileResult = Success String | NotFound | Error String@@ -48,8 +52,19 @@ putStrLn $ "snaplet-fay: Could not find: " ++ hsRelativePath f return NotFound else do- res <- F.compileFile (F.addConfigDirectoryIncludes (includeDirs config) - def { F.configPrettyPrint = prettyPrint config }) f+ print config+ putStrLn ""+ let cfg' = F.addConfigPackages (packages config) $ F.addConfigDirectoryIncludePaths (includeDirs config) $ def { F.configPrettyPrint = prettyPrint config }+ print cfg'+ putStrLn ""+ f' <- canonicalizePath f+ print f'+ putStrLn ""+ res <- flip F.compileFile f' $ F.addConfigPackages (packages config) $+ F.addConfigDirectoryIncludePaths (includeDirs config) $+ def { F.configPrettyPrint = prettyPrint config+ , F.configFilePath = Just f'+ } case res of Right out -> do verbosePut config $ "Compiled " ++ hsRelativePath f@@ -58,7 +73,9 @@ Left err -> do let errString = "snaplet-fay: Error compiling " ++ hsRelativePath f ++ ":\n" ++ show err putStrLn errString- return $ Error errString+ -- return Success so the browser will treat this as a normal JavaScript file.+ -- As of writing this, this means that Error is not used.+ return $ Success $ "console.error('" ++ (C.unpack . A.encode) errString ++ "');" -- | Checks the specified source folder and compiles all new and modified scripts. -- Also removes any js files whose Fay source has been deleted.@@ -77,9 +94,6 @@ forM_ oldFiles $ \f -> do removeFile f verbosePut config $ "Removed orphaned " ++ jsRelativePath f-- where- -- Convert back and forth between the filepaths of hs and js files. -- | Helpers