yesod-fay 0.5.1 → 0.5.2
raw patch · 2 files changed
+52/−24 lines, 2 files
Files
- Yesod/Fay.hs +51/−23
- yesod-fay.cabal +1/−1
Yesod/Fay.hs view
@@ -84,7 +84,9 @@ import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy.UTF8 as BSU import Data.Data (Data)+#if !MIN_VERSION_fay(0,20,0) import Data.Default (def)+#endif import Data.Digest.Pure.MD5 (md5) import Data.List (isPrefixOf) import Data.Maybe (isNothing)@@ -98,15 +100,31 @@ import Data.Text.Lazy.Builder (fromText, toLazyText, Builder) import Filesystem (createTree, isFile, readTextFile) import Filesystem.Path.CurrentOS (directory, encodeString, decodeString)-import Fay (compileFileWithState, CompileState(..), getRuntime,- showCompileError)+import Fay (getRuntime, showCompileError) import Fay.Convert (showToFay)+#if MIN_VERSION_fay(0,20,0)+import Fay (Config(..),+ addConfigDirectoryIncludePaths,+ addConfigPackages,+ compileFileWithResult,+ configDirectoryIncludes,+ configTypecheck,+ configExportRuntime,+ configPrettyPrint,+ defaultConfig,+ CompileError)+import Fay.Types.CompileResult (CompileResult (..))+#else+import Fay (CompileState(..), compileFileWithState)+import Fay.Compiler.Config (addConfigDirectoryIncludePaths,+ addConfigPackages) import Fay.Types (CompileConfig(..), configDirectoryIncludes, configTypecheck, configExportRuntime, configPrettyPrint, CompileError)+#endif import Language.Fay.Yesod (Returns (Returns)) import Language.Haskell.TH.Syntax (Exp (LitE), Lit (StringL), Q,@@ -278,7 +296,7 @@ type FayFile = String -> Q Exp compileFayFile :: FilePath- -> CompileConfig+ -> Config -> IO (Either CompileError String) compileFayFile fp conf = do result <- getFileCache fp@@ -286,19 +304,25 @@ Right cache -> return (Right cache) Left refreshTo -> do packageConf <- fmap (lookup "HASKELL_PACKAGE_SANDBOX") getEnvironment- result <- compileFileWithState conf {- configPackageConf = packageConf- } fp+ let conf' = conf { configPackageConf = packageConf }+#if MIN_VERSION_fay(0,20,0)+ result <- compileFileWithResult conf' fp+#else+ result <- compileFileWithState conf' fp+#endif case result of Left e -> return (Left e) --NOTE: technically this should be (0,18,0,1), but that's not possible.+#if MIN_VERSION_fay(0,20,0)+ Right (CompileResult { resOutput = source', resImported = files }) -> do+#else #if MIN_VERSION_fay(0,18,0)- Right (source',_,state) -> do+ Right (source',_,CompileState { stateImported = files }) -> do #else- Right (source',state) -> do+ Right (source',CompileState { stateImported = files }) -> do #endif- let files = stateImported state- source = "\n(function(){\n" ++ source' ++ "\n})();\n"+#endif+ let source = "\n(function(){\n" ++ source' ++ "\n})();\n" (fp_hi,fp_o) = refreshTo writeFile fp_hi (unlines (filter ours (map snd files))) writeFile fp_o source@@ -338,10 +362,9 @@ let needJQuery = yfsRequireJQuery settings qAddDependentFile fp qRunIO writeYesodFay- eres <- qRunIO $ compileFayFile fp config- { configExportRuntime = exportRuntime- , configPackages = packages- }+ eres <- qRunIO $ compileFayFile fp+ $ addConfigPackages packages+ $ config { configExportRuntime = exportRuntime } case eres of Left e -> throwFayError name e Right s -> do@@ -372,13 +395,13 @@ packages = yfsPackages settings fp = mkfp name -config :: CompileConfig-config = def {- configDirectoryIncludes- = (Nothing, "fay")- : (Nothing, "fay-shared")- : configDirectoryIncludes def- }+config :: Config+config = addConfigDirectoryIncludePaths ["fay", "fay-shared"]+#if MIN_VERSION_fay(0,20,0)+ defaultConfig+#else+ def+#endif -- | Performs no type checking on the Fay code. Each time the widget is -- requested, the Fay code will be compiled from scratch to Javascript.@@ -387,10 +410,11 @@ let needJQuery = yfsRequireJQuery settings qRunIO writeYesodFay [|- liftIO (compileFayFile (mkfp name) config+ liftIO (compileFayFile (mkfp name)+ $ addConfigPackages packages+ $ config { configTypecheck = typecheckDevel , configExportRuntime = exportRuntime- , configPackages = packages #if MIN_VERSION_fay(0, 19, 0) , configSourceMap = True #endif@@ -413,3 +437,7 @@ throwFayError :: String -> CompileError -> error throwFayError name e = error $ "Unable to compile Fay module \"" ++ name ++ "\":\n\n" ++ showCompileError e++#if !MIN_VERSION_fay(0,20,0)+type Config = CompileConfig+#endif
yesod-fay.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: yesod-fay-version: 0.5.1+version: 0.5.2 synopsis: Utilities for using the Fay Haskell-to-JS compiler with Yesod. description: For initial discussion, see <http://www.yesodweb.com/blog/2012/10/yesod-fay-js>. This is a work-in-progress. homepage: https://github.com/fpco/yesod-fay