yesod-fay 0.1.0.4 → 0.1.1
raw patch · 3 files changed
+34/−9 lines, 3 filesdep ~fayPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: fay
API changes (from Hackage documentation)
+ Language.Fay.Yesod: ajaxCommandWithErrorHandling :: (Foreign a, Foreign command) => command -> (a -> Fay ()) -> (Fay ()) -> Fay ()
+ Language.Fay.Yesod: callWithErrorHandling :: (Foreign a, Foreign command) => (Returns a -> command) -> (a -> Fay ()) -> (Fay ()) -> Fay ()
Files
- Language/Fay/Yesod.hs +19/−2
- Yesod/Fay.hs +13/−5
- yesod-fay.cabal +2/−2
Language/Fay/Yesod.hs view
@@ -16,13 +16,30 @@ -- | Call a command. call :: (Foreign a, Foreign command) => (Returns a -> command)- -> (a -> Fay ())+ -> (a -> Fay ()) -- ^ Success Handler -> Fay () call f g = ajaxCommand (f Returns) g +-- ! Call a command, handling errors as well+callWithErrorHandling :: (Foreign a, Foreign command)+ => (Returns a -> command)+ -> (a -> Fay ()) -- ^ Success Handler+ -> (Fay ()) -- ^ Failure Handler+ -> Fay ()+callWithErrorHandling f g h = ajaxCommandWithErrorHandling (f Returns) g h+ -- | Run the AJAX command. ajaxCommand :: (Foreign a, Foreign command) => command- -> (a -> Fay ())+ -> (a -> Fay ()) -- ^ Success Handler -> Fay () ajaxCommand = ffi "jQuery['ajax']({ url: window['yesodFayCommandPath'], type: 'POST', data: { json: JSON.stringify(%1) }, dataType: 'json', success : %2})"++-- | Run the AJAX command, handling errors as well+ajaxCommandWithErrorHandling :: (Foreign a, Foreign command)+ => command+ -> (a -> Fay ()) -- ^ Success Handler+ -> (Fay ()) -- ^ Failure Handler+ -> Fay ()+ajaxCommandWithErrorHandling = ffi "jQuery['ajax']({ url: window['yesodFayCommandPath'], type: 'POST', data: { json: JSON.stringify(%1) }, dataType: 'json', success : %2, error: %3})"+
Yesod/Fay.hs view
@@ -79,10 +79,10 @@ import qualified Data.ByteString.Lazy as L import Data.Data (Data) import Data.Default (def)-import Data.Text (pack)+import Data.Text (pack, unpack) import Data.Text.Encoding (encodeUtf8) import Data.Text.Lazy.Builder (fromText, toLazyText)-import Filesystem (createTree)+import Filesystem (createTree, isFile, readTextFile) import Filesystem.Path.CurrentOS (directory, encodeString) #if MIN_VERSION_fay(0,10,0) import Language.Fay (compileFile)@@ -206,13 +206,20 @@ go Returns = jsonToRepJson . showToFay langYesodFay :: String-langYesodFay = $(qRunIO $ fmap (LitE . StringL) $ readFile "Language/Fay/Yesod.hs")+langYesodFay = $(qRunIO $ fmap (LitE . StringL . unpack) $ readTextFile "Language/Fay/Yesod.hs") writeYesodFay :: IO () writeYesodFay = do let fp = "fay/Language/Fay/Yesod.hs"- createTree $ directory fp- writeFile (encodeString fp) langYesodFay+ content = "-- NOTE: This file is auto-generated.\n" ++ langYesodFay+ exists <- isFile fp+ mcurrent <-+ if exists+ then fmap (Just . unpack) $ readTextFile fp+ else return Nothing+ unless (mcurrent == Just content) $ do+ createTree $ directory fp+ writeFile (encodeString fp) content requireJQuery :: YesodFay master => GWidget sub master () requireJQuery = do@@ -235,6 +242,7 @@ fayFileProd :: FayFile fayFileProd name = do qAddDependentFile fp+ qRunIO writeYesodFay eres <- qRunIO $ compileFile config fp case eres of Left e -> error $ "Unable to compile Fay module \"" ++ name ++ "\": " ++ show e
yesod-fay.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: yesod-fay-version: 0.1.0.4+version: 0.1.1 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/snoyberg/yesod-fay@@ -18,7 +18,7 @@ exposed-modules: Yesod.Fay Language.Fay.Yesod build-depends: base >= 4 && < 5- , fay >= 0.9+ , fay >= 0.10 , transformers >= 0.2 , aeson >= 0.6 , bytestring >= 0.9