Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Switch incoming.julius to Fay

  • Loading branch information...
commit f7527feab714a90a0b9a28c5eef81e5e43361d8b 1 parent 3e20ba9
Michael Snoyman authored October 28, 2012
2  .gitignore
@@ -4,3 +4,5 @@ dist/
4 4
 config/client_session_key.aes
5 5
 photosorter.sqlite3
6 6
 photosorter.keter
  7
+*.o
  8
+*.hi
1  Application.hs
@@ -30,6 +30,7 @@ import Handler.SetName
30 30
 import Handler.SetDescription
31 31
 import Handler.ToPostList
32 32
 import Handler.UnPost
  33
+import Handler.Command
33 34
 
34 35
 -- This line actually creates our YesodDispatch instance. It is the second half
35 36
 -- of the call to mkYesodData which occurs in Foundation.hs. Please see the
45  Handler/Command.hs
... ...
@@ -0,0 +1,45 @@
  1
+module Handler.Command where
  2
+
  3
+import Import
  4
+import SharedTypes
  5
+import Data.Aeson (decode)
  6
+import Language.Fay.Convert
  7
+import qualified Data.ByteString.Lazy as L
  8
+import Data.Text.Encoding (encodeUtf8)
  9
+import qualified Data.Text as T
  10
+
  11
+type HandleCommand = forall s. (forall a. Show a => Returns a -> a -> Handler s) -> Command -> Handler s
  12
+
  13
+handle :: HandleCommand -> Handler RepJson
  14
+handle f = do
  15
+    mtxt <- lookupPostParam "json"
  16
+    case mtxt of
  17
+        Nothing -> error "No JSON provided"
  18
+        Just txt ->
  19
+            case decode (L.fromChunks [encodeUtf8 txt]) >>= readFromFay of
  20
+                Nothing -> error $ "Unable to parse input: " ++ show txt
  21
+                Just cmd -> f go cmd
  22
+  where
  23
+    go Returns = jsonToRepJson . showToFay
  24
+
  25
+handleCommand :: HandleCommand
  26
+handleCommand respond command =
  27
+    case command of
  28
+        AddPost date slug r -> do
  29
+            liftIO $ addPost $ PostName $ T.pack $ filter (/= '-') date ++ slug
  30
+            respond r ()
  31
+        SetPost f' p' r -> do
  32
+            let f = FilePath' $ T.pack f'
  33
+                p = PostName $ T.pack p'
  34
+            runDB $ do
  35
+                x <- getBy $ UniqueMedia f
  36
+                case x of
  37
+                    Nothing -> do
  38
+                        _ <- insert $ Media f (Just p)
  39
+                        return ()
  40
+                    Just (Entity key val) -> do
  41
+                        replace key $ val { mediaPost = Just p }
  42
+            respond r ()
  43
+
  44
+postCommandR :: Handler RepJson
  45
+postCommandR = handle handleCommand
1  Handler/Incoming.hs
@@ -17,6 +17,7 @@ getIncomingR root = do
17 17
     defaultLayout $ do
18 18
         setTitle "Incoming"
19 19
         $(widgetFile "incoming")
  20
+        $(fayFile "Incoming")
20 21
         addScriptEither $ urlJqueryJs y
21 22
   where
22 23
     isChosen Nothing _ = False
1  Import.hs
@@ -21,6 +21,7 @@ import Control.Monad (foldM, filterM)
21 21
 import Data.List (sortBy, sort)
22 22
 import Data.Ord (comparing)
23 23
 import Control.Arrow ((&&&))
  24
+import Import.Fay as Import
24 25
 
25 26
 #if __GLASGOW_HASKELL__ >= 704
26 27
 import           Data.Monoid          as Import
49  Import/Fay.hs
... ...
@@ -0,0 +1,49 @@
  1
+module Import.Fay
  2
+    ( fayFile
  3
+    ) where
  4
+
  5
+import Prelude
  6
+import Yesod
  7
+import Language.Haskell.TH.Syntax
  8
+import Language.Fay.Compiler
  9
+import Language.Fay.Types
  10
+import Data.Default (def)
  11
+import Text.Julius
  12
+import qualified Data.Text as T
  13
+import Data.Text.Lazy.Builder (fromText)
  14
+import Settings.Development (development)
  15
+import System.Process (rawSystem)
  16
+import System.Exit (ExitCode (ExitSuccess))
  17
+import Control.Monad (unless)
  18
+
  19
+fayFile :: String -> Q Exp
  20
+fayFile
  21
+    | development = fayFileReload
  22
+    | otherwise   = fayFileProd
  23
+
  24
+fayFileProd :: String -> Q Exp
  25
+fayFileProd name = do
  26
+    qAddDependentFile fp
  27
+    ec <- qRunIO $ rawSystem "ghc" ["-O0", "--make", "-ifay", "-ifay-shared", fp]
  28
+    unless (ec == ExitSuccess) $ error $ "Type checking of fay module failed: " ++ name
  29
+    eres <- qRunIO $ compileFile config fp
  30
+    case eres of
  31
+        Left e -> error $ "Unable to compile Fay module \"" ++ name ++ "\": " ++ show e
  32
+        Right s -> [|toWidget $ const $ Javascript $ fromText $ T.pack s|]
  33
+  where
  34
+    fp = mkfp name
  35
+
  36
+mkfp :: String -> FilePath
  37
+mkfp name = "fay/" ++ name ++ ".hs"
  38
+
  39
+config :: CompileConfig
  40
+config = def
  41
+    { configDirectoryIncludes = ["fay", "fay-shared"]
  42
+    }
  43
+
  44
+fayFileReload :: String -> Q Exp
  45
+fayFileReload name = [|
  46
+    liftIO (compileFile config $ mkfp name) >>= \eres ->
  47
+    (case eres of
  48
+        Left e -> error $ "Unable to compile Fay module \"" ++ name ++ "\": " ++ show e
  49
+        Right s -> toWidget $ const $ Javascript $ fromText $ T.pack s)|]
1  config/routes
@@ -16,3 +16,4 @@
16 16
 /set-description SetDescriptionR POST
17 17
 /topost ToPostListR GET
18 18
 /topost/#PostName/unpost UnPostR POST
  19
+/json CommandR POST
15  fay-shared/SharedTypes.hs
... ...
@@ -0,0 +1,15 @@
  1
+{-# LANGUAGE NoImplicitPrelude #-}
  2
+{-# LANGUAGE DeriveDataTypeable #-}
  3
+module SharedTypes where
  4
+
  5
+import Language.Fay.Prelude
  6
+import Language.Fay.FFI
  7
+
  8
+data Returns a = Returns
  9
+    deriving (Show, Read, Data, Typeable)
  10
+
  11
+data Command = AddPost String String (Returns ())
  12
+             | SetPost String String (Returns ())
  13
+    deriving (Show, Read, Data, Typeable)
  14
+
  15
+instance Foreign Command
22  fay/Client/API.hs
... ...
@@ -0,0 +1,22 @@
  1
+{-# LANGUAGE NoImplicitPrelude #-}
  2
+
  3
+module Client.API where
  4
+
  5
+import SharedTypes
  6
+
  7
+import Language.Fay.FFI
  8
+import Language.Fay.Prelude
  9
+
  10
+-- | Call a command.
  11
+call :: (Foreign a) => (Returns a -> Command) -> (a -> Fay ()) -> Fay ()
  12
+call f g = ajaxCommand (f Returns) g
  13
+
  14
+-- | Run the AJAX command.
  15
+ajaxCommand :: (Foreign a) => Command -> (a -> Fay ()) -> Fay ()
  16
+ajaxCommand = ffi "jQuery['ajax']({\
  17
+                  \ \"url\": '/json', \
  18
+                  \ \"type\": 'POST', \
  19
+                  \ \"data\": { \"json\": JSON.stringify(%1) }, \
  20
+                  \ \"dataType\": 'json', \
  21
+                  \ \"success\" : %2 \
  22
+                  \})"
33  fay/Incoming.hs
... ...
@@ -0,0 +1,33 @@
  1
+{-# LANGUAGE NoImplicitPrelude #-}
  2
+module Incoming where
  3
+
  4
+import Language.Fay.Prelude
  5
+import Language.Fay.JQuery
  6
+import Language.Fay.DOM
  7
+import Language.Fay.FFI
  8
+
  9
+import Client.API
  10
+import SharedTypes
  11
+
  12
+main :: Fay ()
  13
+main = ready $ do
  14
+    select "button.add-new-post" >>= onClick (\e -> do
  15
+        alert' "You clicked the button"
  16
+        eventSource e >>= hide >>= next >>= unhide
  17
+        return False
  18
+        )
  19
+    select "button.add-new-post2" >>= onClick (\e -> do
  20
+        t <- eventSource e
  21
+        date <- parent t >>= childrenMatching "input[type=date]" >>= getVal
  22
+        slug <- parent t >>= childrenMatching "input[type=text]" >>= getVal
  23
+        call (AddPost date slug) $ const reload
  24
+        return False
  25
+        )
  26
+    select "input[type=radio]" >>= onClick (\e -> do
  27
+        t <- eventSource e
  28
+        file <- parentsSelector "form" t >>= childrenMatching "input[name=file]" >>= getVal
  29
+        post <- getVal t
  30
+        call (SetPost file post) $ const $ return ()
  31
+        return False
  32
+        )
  33
+    return ()
36  fay/Language/Fay/DOM.hs
... ...
@@ -0,0 +1,36 @@
  1
+{-# LANGUAGE FlexibleInstances #-}
  2
+{-# LANGUAGE EmptyDataDecls #-}
  3
+{-# LANGUAGE NoImplicitPrelude #-}
  4
+
  5
+module Language.Fay.DOM  where
  6
+
  7
+import Language.Fay.FFI
  8
+import Language.Fay.Prelude
  9
+
  10
+data Element
  11
+instance Foreign Element
  12
+
  13
+-- | Get body.
  14
+getBody :: Fay Element
  15
+getBody = ffi "document['body']"
  16
+
  17
+data Timer
  18
+instance Foreign Timer
  19
+
  20
+-- | Set a timer.
  21
+setTimeout :: Double -> Fay () -> Fay Timer
  22
+setTimeout = ffi "window['setTimeout'](%2,%1)"
  23
+
  24
+-- | Set a timer.
  25
+setInterval :: Double -> Fay () -> Fay Timer
  26
+setInterval = ffi "window['setInterval'](%2,%1)"
  27
+
  28
+-- | Clear a timer.
  29
+clearTimeout :: Timer -> Fay ()
  30
+clearTimeout = ffi "window['clearTimeout'](%1)"
  31
+
  32
+alert :: String -> Fay ()
  33
+alert = ffi "window.alert(%1)"
  34
+
  35
+reload :: Fay ()
  36
+reload = ffi "window.location.reload()"
526  fay/Language/Fay/JQuery.hs
... ...
@@ -0,0 +1,526 @@
  1
+{-# LANGUAGE EmptyDataDecls #-}
  2
+{-# LANGUAGE NoImplicitPrelude #-}
  3
+
  4
+module Language.Fay.JQuery  where
  5
+
  6
+import Language.Fay.Prelude
  7
+import Language.Fay.FFI
  8
+import Language.Fay.DOM
  9
+
  10
+data JQuery
  11
+instance Foreign JQuery
  12
+instance Show JQuery
  13
+
  14
+data EventObject
  15
+instance Foreign EventObject
  16
+instance Show EventObject
  17
+
  18
+currentTarget :: EventObject -> Fay Element
  19
+currentTarget = ffi "%1.currentTarget"
  20
+
  21
+eventSource :: EventObject -> Fay JQuery
  22
+eventSource e = currentTarget e >>= selectElement
  23
+
  24
+getThis :: Fay JQuery
  25
+getThis = ffi "this"
  26
+
  27
+addClass :: String -> JQuery -> Fay JQuery
  28
+addClass = ffi "%2['addClass'](%1)"
  29
+
  30
+addClassWith :: (Double -> String -> Fay String) -> JQuery -> Fay JQuery
  31
+addClassWith = ffi "%2['addClass'](%1)"
  32
+
  33
+getAttr :: String -> JQuery -> Fay String
  34
+getAttr = ffi "%2['attr'](%1)"
  35
+
  36
+setAttr :: String -> String -> JQuery -> Fay JQuery
  37
+setAttr = ffi "%3['attr'](%1, %2)"
  38
+
  39
+setAttrWith :: String -> (Double -> String -> Fay String) -> JQuery -> Fay JQuery
  40
+setAttrWith = ffi "%3['attr'](%1, %2)"
  41
+
  42
+hasClass :: String -> JQuery -> Fay Bool
  43
+hasClass = ffi "%2['hasClass'](%1)"
  44
+
  45
+getHtml :: JQuery -> Fay String
  46
+getHtml = ffi "%1['html']()"
  47
+
  48
+setHtml :: String -> JQuery -> Fay JQuery
  49
+setHtml = ffi "%2['html'](%1)"
  50
+
  51
+setHtmlWith :: (Double -> String -> Fay JQuery) -> JQuery -> Fay JQuery
  52
+setHtmlWith = ffi "%2['html'](%1)"
  53
+
  54
+getProp :: String -> JQuery -> Fay String
  55
+getProp = ffi "%2['prop'](%1)"
  56
+
  57
+setProp :: String -> String -> JQuery -> Fay JQuery
  58
+setProp = ffi "%3['prop'](%1, %2)"
  59
+
  60
+setPropWith :: String -> (Double -> String -> Fay String) -> JQuery -> Fay JQuery
  61
+setPropWith = ffi "%3['prop'](%1, %2)"
  62
+
  63
+removeAttr :: String -> JQuery -> Fay JQuery
  64
+removeAttr = ffi "%2['removeAttr'](%1)"
  65
+
  66
+removeClass :: String -> JQuery -> Fay JQuery
  67
+removeClass = ffi "%2['removeClass'](%1)"
  68
+
  69
+removeClassWith :: (Double -> String -> Fay JQuery) -> JQuery -> Fay JQuery
  70
+removeClassWith = ffi "%2['removeClass'](%1)"
  71
+
  72
+removeProp :: String -> JQuery -> Fay JQuery
  73
+removeProp = ffi "%2['removeProp'](%1)"
  74
+
  75
+toggleClass :: String -> JQuery -> Fay JQuery
  76
+toggleClass = ffi "%2['toggleClass'](%1)"
  77
+
  78
+toggleClassBool :: String -> Bool -> JQuery -> Fay JQuery
  79
+toggleClassBool = ffi "%3['toggleClass'](%1, %2)"
  80
+
  81
+toggleAllClasses :: Bool -> JQuery -> Fay JQuery
  82
+toggleAllClasses = ffi "%2['toggleClass'](%1)"
  83
+
  84
+toggleClassWith :: (Double -> String -> Bool -> Fay JQuery) -> JQuery -> Fay JQuery
  85
+toggleClassWith = ffi "%2['toggleClass'](%1)"
  86
+
  87
+toggleClassBoolWith :: (Double -> String -> Bool -> Fay JQuery) -> Bool -> JQuery -> Fay JQuery
  88
+toggleClassBoolWith = ffi "%3['toggleClass'](%1, %2)"
  89
+
  90
+getVal :: JQuery -> Fay String
  91
+getVal = ffi "%1['val']()"
  92
+
  93
+setVal :: String -> JQuery -> Fay JQuery
  94
+setVal = ffi "%2['val'](%1)"
  95
+
  96
+setValWith :: (Double -> String -> Fay JQuery) -> JQuery -> Fay JQuery
  97
+setValWith = ffi "%2['val'](%1)"
  98
+
  99
+setText :: String -> JQuery -> Fay JQuery
  100
+setText = ffi "%2['text'](%1)"
  101
+
  102
+setTextWith :: (Double -> String -> Fay JQuery) -> JQuery -> Fay JQuery
  103
+setTextWith = ffi "%2['text'](%1)"
  104
+
  105
+getText :: JQuery -> Fay String
  106
+getText = ffi "%1['text']()"
  107
+
  108
+holdReady :: Bool -> Fay JQuery
  109
+holdReady = ffi "window['jQuery']['holdReady'](%1)"
  110
+
  111
+selectElement :: Element -> Fay JQuery
  112
+selectElement = ffi "window['jQuery'](%1)"
  113
+
  114
+select :: String -> Fay JQuery
  115
+select = ffi "window['jQuery'](%1)"
  116
+
  117
+selectEmpty :: Fay JQuery
  118
+selectEmpty = ffi "window['jQuery']()"
  119
+
  120
+selectQuery :: String -> JQuery -> Fay JQuery
  121
+selectQuery = ffi "window['jQuery'](%1, %2)"
  122
+
  123
+ready :: Fay () -> Fay ()
  124
+ready = ffi "window['jQuery'](%1)"
  125
+
  126
+getCss :: String -> JQuery -> Fay String
  127
+getCss = ffi "%2['css'](%1)"
  128
+
  129
+setCss :: String -> String -> JQuery -> Fay JQuery
  130
+setCss = ffi "%3['css'](%1, %2)"
  131
+
  132
+setCssWith :: String -> (Double -> String -> Fay String) -> JQuery -> Fay JQuery
  133
+setCssWith = ffi "%3['css'](%1, %2)"
  134
+
  135
+getHeight :: JQuery -> Fay Double
  136
+getHeight = ffi "%1['height']()"
  137
+
  138
+setHeight :: Double -> JQuery -> Fay JQuery
  139
+setHeight = ffi "%2['height'](%1)"
  140
+
  141
+setHeightWith :: (Double -> Double -> Fay Double) -> JQuery -> Fay JQuery
  142
+setHeightWith = ffi "%2['height'](%1)"
  143
+
  144
+getInnerHeight :: JQuery -> Fay Double
  145
+getInnerHeight = ffi "%1['innerHeight']()"
  146
+
  147
+getInnerWidth :: JQuery -> Fay Double
  148
+getInnerWidth = ffi "%1['innerWidth']()"
  149
+
  150
+getOuterHeight :: JQuery -> Fay Double
  151
+getOuterHeight = ffi "%1['outerHeight']()"
  152
+
  153
+getOuterHeightBool :: Bool -> JQuery -> Fay Double
  154
+getOuterHeightBool = ffi "%2['outerHeight'](%1)"
  155
+
  156
+getOuterWidth :: JQuery -> Fay Double
  157
+getOuterWidth = ffi "%1['outerWidth']()"
  158
+
  159
+getOuterWidthBool :: Bool -> JQuery -> Fay Double
  160
+getOuterWidthBool = ffi "%2['outerWidth'](%1)"
  161
+
  162
+getScrollLeft :: JQuery -> Fay Double
  163
+getScrollLeft = ffi "%1['scrollLeft']()"
  164
+
  165
+setScrollLeft :: Double -> JQuery -> Fay JQuery
  166
+setScrollLeft = ffi "%2['scrollLeft'](%1)"
  167
+
  168
+getScrollTop :: JQuery -> Fay Double
  169
+getScrollTop = ffi "%1['scrollTop']()"
  170
+
  171
+setScrollTop :: Double -> JQuery -> Fay JQuery
  172
+setScrollTop = ffi "%2['scrollTop'](%1)"
  173
+
  174
+getWidth :: JQuery -> Fay Double
  175
+getWidth = ffi "%1['width']()"
  176
+
  177
+setWidth :: Double -> JQuery -> Fay JQuery
  178
+setWidth = ffi "%2['width'](%1)"
  179
+
  180
+setWidthWith :: (Double -> Double -> Fay Double) -> JQuery -> Fay JQuery
  181
+setWidthWith = ffi "%2['width'](%1)"
  182
+
  183
+after :: JQuery -> JQuery -> Fay JQuery
  184
+after = ffi "%2['after'](%1)"
  185
+
  186
+afterWith :: (Double -> Fay JQuery) -> JQuery -> Fay JQuery
  187
+afterWith = ffi "%2['after'](%1)"
  188
+
  189
+append :: JQuery -> JQuery -> Fay JQuery
  190
+append = ffi "%2['append'](%1)"
  191
+
  192
+appendWith :: (Double -> Fay JQuery) -> JQuery -> Fay JQuery
  193
+appendWith = ffi "%2['append'](%1)"
  194
+
  195
+appendTo :: JQuery -> JQuery -> Fay JQuery
  196
+appendTo = ffi "%2['appendTo'](%1)"
  197
+
  198
+appendToJQuery :: JQuery -> JQuery -> Fay JQuery
  199
+appendToJQuery = ffi "%2['appendTo'](%1)"
  200
+
  201
+before :: JQuery -> JQuery -> Fay JQuery
  202
+before = ffi "%2['before'](%1)"
  203
+
  204
+beforeWith :: (Double -> Fay JQuery) -> JQuery -> Fay JQuery
  205
+beforeWith = ffi "%2['before'](%1)"
  206
+
  207
+detach :: JQuery -> Fay JQuery
  208
+detach = ffi "%1['detach']()"
  209
+
  210
+detachSelector :: String -> JQuery -> Fay JQuery
  211
+detachSelector = ffi "%2['detach'](%1)"
  212
+
  213
+empty :: JQuery -> Fay JQuery
  214
+empty = ffi "%1['empty']()"
  215
+
  216
+insertAfter :: JQuery -> JQuery -> Fay JQuery
  217
+insertAfter = ffi "%2['insertAfter'](%1)"
  218
+
  219
+insertBefore :: JQuery -> JQuery -> Fay JQuery
  220
+insertBefore = ffi "%2['insertBefore'](%1)"
  221
+
  222
+prepend :: JQuery -> JQuery -> Fay JQuery
  223
+prepend = ffi "%2['prepend'](%1)"
  224
+
  225
+prependWith :: (Double -> Fay JQuery) -> JQuery -> Fay JQuery
  226
+prependWith = ffi "%2['prepend'](%1)"
  227
+
  228
+prependTo :: JQuery -> JQuery -> Fay JQuery
  229
+prependTo = ffi "%2['prependTo'](%1)"
  230
+
  231
+remove :: JQuery -> Fay JQuery
  232
+remove = ffi "%1['remove']()"
  233
+
  234
+removeSelector :: String -> JQuery -> Fay JQuery
  235
+removeSelector = ffi "%2['remove'](%1)"
  236
+
  237
+replaceAll :: String -> JQuery -> Fay JQuery
  238
+replaceAll = ffi "%2['replaceAll'](%1)"
  239
+
  240
+replaceWith :: String -> JQuery -> Fay JQuery
  241
+replaceWith = ffi "%2['replaceWith'](%1)"
  242
+
  243
+replaceWithJQuery :: JQuery -> JQuery -> Fay JQuery
  244
+replaceWithJQuery = ffi "%2['replaceWith'](%1)"
  245
+
  246
+replaceWithWith :: (Fay JQuery) -> JQuery -> Fay JQuery
  247
+replaceWithWith = ffi "%2['replaceWith'](%1)"
  248
+
  249
+unwrap :: JQuery -> Fay JQuery
  250
+unwrap = ffi "%1['unwrap']()"
  251
+
  252
+wrap :: String -> JQuery -> Fay JQuery
  253
+wrap = ffi "%2['wrap'](%1)"
  254
+
  255
+wrapWith :: (Double -> Fay JQuery) -> JQuery -> Fay JQuery
  256
+wrapWith = ffi "%2['wrap'](%1)"
  257
+
  258
+wrapAllHtml :: String -> JQuery -> Fay JQuery
  259
+wrapAllHtml = ffi "%2['wrapAll'](%1)"
  260
+
  261
+wrapAllSelector :: String -> JQuery -> Fay JQuery
  262
+wrapAllSelector = ffi "%2['wrapAll'](%1)"
  263
+
  264
+wrapAllElement :: Element -> JQuery -> Fay JQuery
  265
+wrapAllElement = ffi "%2['wrapAll'](%1)"
  266
+
  267
+wrapInnerHtml :: String -> JQuery -> Fay JQuery
  268
+wrapInnerHtml = ffi "%2['wrapInner'](%1)"
  269
+
  270
+wrapInnerSelector :: String -> JQuery -> Fay JQuery
  271
+wrapInnerSelector = ffi "%2['wrapInner'](%1)"
  272
+
  273
+wrapInnerElement :: Element -> JQuery -> Fay JQuery
  274
+wrapInnerElement = ffi "%2['wrapInner'](%1)"
  275
+
  276
+addSelector :: String -> JQuery -> Fay JQuery
  277
+addSelector = ffi "$2['add'](%1)"
  278
+
  279
+addElement :: Element -> JQuery -> Fay JQuery
  280
+addElement = ffi "%2['add'](%1)"
  281
+
  282
+addHtml :: String -> JQuery -> Fay JQuery
  283
+addHtml = ffi "%2['add'](%1)"
  284
+
  285
+add :: JQuery -> JQuery -> Fay JQuery
  286
+add = ffi "%2['add'](%1)"
  287
+
  288
+addSelectorWithContext :: String -> JQuery -> JQuery -> Fay JQuery
  289
+addSelectorWithContext = ffi "%3['add'](%1, %2)"
  290
+
  291
+andSelf :: JQuery -> Fay JQuery
  292
+andSelf = ffi "%1['andSelf']()"
  293
+
  294
+children :: JQuery -> Fay JQuery
  295
+children = ffi "%1['children']()"
  296
+
  297
+childrenMatching :: String -> JQuery -> Fay JQuery
  298
+childrenMatching = ffi "%2['children'](%1)"
  299
+
  300
+closestSelector :: String -> JQuery -> Fay JQuery
  301
+closestSelector = ffi "%2['closest'](%1)"
  302
+
  303
+closestWithContext :: String -> String -> JQuery -> Fay JQuery
  304
+closestWithContext = ffi "%3['closest'](%1, %2)"
  305
+
  306
+closest :: JQuery -> JQuery -> Fay JQuery
  307
+closest = ffi "%2['closest'](%1)"
  308
+
  309
+closestElement :: Element -> JQuery -> Fay JQuery
  310
+closestElement = ffi "%2['closest'](%1)"
  311
+
  312
+contents :: JQuery -> Fay JQuery
  313
+contents = ffi "%1['contents']()"
  314
+
  315
+each :: (Double -> Element -> Bool) -> JQuery -> Fay JQuery
  316
+each = ffi "%2['each'](%1)"
  317
+
  318
+end :: JQuery -> Fay JQuery
  319
+end = ffi "%1['end']()"
  320
+
  321
+eq :: Double -> JQuery -> Fay JQuery
  322
+eq = ffi "%2['eq'](%1)"
  323
+
  324
+filterWith :: (Double -> Fay Bool) -> JQuery -> Fay JQuery
  325
+filterWith = ffi "%2['filter'](%1)"
  326
+
  327
+filterElement :: Element -> JQuery -> Fay JQuery
  328
+filterElement = ffi "%2['filter'](%1)"
  329
+
  330
+filterJQuery :: JQuery -> JQuery -> Fay JQuery
  331
+filterJQuery = ffi "%2['filter'](%1)"
  332
+
  333
+findSelector :: String -> JQuery -> Fay JQuery
  334
+findSelector = ffi "%2['find'](%1)"
  335
+
  336
+findJQuery :: JQuery -> JQuery -> Fay JQuery
  337
+findJQuery = ffi "%2['find'](%1)"
  338
+
  339
+findElement :: Element -> JQuery -> Fay JQuery
  340
+findElement = ffi "%2['find'](%1)"
  341
+
  342
+first :: JQuery -> Fay JQuery
  343
+first = ffi "%1['first']()"
  344
+
  345
+getElement :: JQuery -> Fay Element
  346
+getElement = ffi "%1['get'](0)"
  347
+
  348
+has :: String -> JQuery -> Fay JQuery
  349
+has = ffi "%2['has'](%1)"
  350
+
  351
+hasElement :: Element -> JQuery -> Fay JQuery
  352
+hasElement = ffi "%2['has'](%1)"
  353
+
  354
+is :: String -> JQuery -> Fay JQuery
  355
+is = ffi "%2['is'](%1)"
  356
+
  357
+isWith :: (Double -> Bool) -> JQuery -> Fay JQuery
  358
+isWith = ffi "%2['is'](%1)"
  359
+
  360
+isJQuery :: JQuery -> JQuery -> Fay JQuery
  361
+isJQuery = ffi "%2['is'](%1)"
  362
+
  363
+isElement :: Element -> JQuery -> Fay JQuery
  364
+isElement = ffi "%2['is'](%1)"
  365
+
  366
+last :: JQuery -> Fay JQuery
  367
+last = ffi "%1['last']()"
  368
+
  369
+jQueryMap :: (Double -> Element -> Fay JQuery) -> JQuery -> Fay JQuery
  370
+jQueryMap = ffi "%2['map'](%1)"
  371
+
  372
+next :: JQuery -> Fay JQuery
  373
+next = ffi "%1['next']()"
  374
+
  375
+nextSelector :: String -> JQuery -> Fay JQuery
  376
+nextSelector = ffi "%2['next'](%1)"
  377
+
  378
+nextAll :: JQuery -> Fay JQuery
  379
+nextAll = ffi "%1['nextAll']()"
  380
+
  381
+nextAllSelector :: String -> JQuery -> Fay JQuery
  382
+nextAllSelector = ffi "%2['nextAll'](%1)"
  383
+
  384
+nextUntil :: String -> JQuery -> Fay JQuery
  385
+nextUntil = ffi "%2['nextUntil'](%1)"
  386
+
  387
+nextUntilFiltered :: String -> String -> JQuery -> Fay JQuery
  388
+nextUntilFiltered = ffi "%3['nextUntil'](%1, %2)"
  389
+
  390
+nextUntilElement :: Element -> JQuery -> Fay JQuery
  391
+nextUntilElement = ffi "%2['nextUntil'](%1)"
  392
+
  393
+nextUntilElementFiltered :: Element -> String -> JQuery -> Fay JQuery
  394
+nextUntilElementFiltered = ffi "%3['nextUntil'](%1, %2)"
  395
+
  396
+isNot :: String -> JQuery -> Fay JQuery
  397
+isNot = ffi "%2['not'](%1)"
  398
+
  399
+notElement :: Element -> JQuery -> Fay JQuery
  400
+notElement = ffi "%2['not'](%1)"
  401
+
  402
+notElements :: [Element] -> JQuery -> Fay JQuery
  403
+notElements = ffi "%2['not'](%1)"
  404
+
  405
+notWith :: (Double -> Bool) -> JQuery -> Fay JQuery
  406
+notWith = ffi "%2['not'](%1)"
  407
+
  408
+notJQuery :: JQuery -> JQuery -> Fay JQuery
  409
+notJQuery = ffi "%2['not'](%1)"
  410
+
  411
+offsetParent :: JQuery -> Fay JQuery
  412
+offsetParent = ffi "%1['offsetParent']()"
  413
+
  414
+parent :: JQuery -> Fay JQuery
  415
+parent = ffi "%1['parent']()"
  416
+
  417
+parentSelector :: String -> JQuery -> Fay JQuery
  418
+parentSelector = ffi "%2['parent'](%1)"
  419
+
  420
+parents :: JQuery -> Fay JQuery
  421
+parents = ffi "%1['parents']()"
  422
+
  423
+parentsSelector :: String -> JQuery -> Fay JQuery
  424
+parentsSelector = ffi "%2['parents'](%1)"
  425
+
  426
+parentsUntil :: String -> JQuery -> Fay JQuery
  427
+parentsUntil = ffi "%2['parentsUntil'](%1)"
  428
+
  429
+parentsUntilFiltered :: String -> String -> JQuery -> Fay JQuery
  430
+parentsUntilFiltered = ffi "%3['parentsUntil'](%1, %2)"
  431
+
  432
+parentsUntilElement :: Element -> JQuery -> Fay JQuery
  433
+parentsUntilElement = ffi "%2['parentsUntil'](%1)"
  434
+
  435
+parentsUntilElementFiltered :: Element -> String -> JQuery -> Fay JQuery
  436
+parentsUntilElementFiltered = ffi "%3['parentsUntil'](%1, %2)"
  437
+
  438
+prev :: JQuery -> Fay JQuery
  439
+prev = ffi "%1['prev']()"
  440
+
  441
+hide :: JQuery -> Fay JQuery
  442
+hide = ffi "%1['hide']()"
  443
+
  444
+unhide :: JQuery -> Fay JQuery
  445
+unhide = ffi "%1['show']()"
  446
+
  447
+fadeOut :: JQuery -> Fay JQuery
  448
+fadeOut = ffi "%1['fadeOut']()"
  449
+
  450
+fadeIn :: JQuery -> Fay JQuery
  451
+fadeIn = ffi "%1['fadeIn']()"
  452
+
  453
+focus :: JQuery -> Fay JQuery
  454
+focus = ffi "%1['focus']()"
  455
+
  456
+prevSelector :: String -> JQuery -> Fay JQuery
  457
+prevSelector = ffi "%2['prev'](%1)"
  458
+
  459
+prevAll :: JQuery -> Fay JQuery
  460
+prevAll = ffi "%1['prevAll']()"
  461
+
  462
+prevAllSelector :: String -> JQuery -> Fay JQuery
  463
+prevAllSelector = ffi "%2['prevAll'](%1)"
  464
+
  465
+prevUntil :: String -> JQuery -> Fay JQuery
  466
+prevUntil = ffi "%2['prevUntil'](%1)"
  467
+
  468
+prevUntilFiltered :: String -> String -> JQuery -> Fay JQuery
  469
+prevUntilFiltered = ffi "%3['prevUntil'](%1, %2)"
  470
+
  471
+prevUntilElement :: Element -> JQuery -> Fay JQuery
  472
+prevUntilElement = ffi "%2['prevUntil'](%1)"
  473
+
  474
+prevUntilElementFiltered :: Element -> String -> JQuery -> Fay JQuery
  475
+prevUntilElementFiltered = ffi "%3['prevUntil'](%1, %2)"
  476
+
  477
+siblings :: JQuery -> Fay JQuery
  478
+siblings = ffi "%1['siblings']()"
  479
+
  480
+siblingsSelector :: String -> JQuery -> Fay JQuery
  481
+siblingsSelector = ffi "%2['siblings'](%1)"
  482
+
  483
+slice :: Double -> JQuery -> Fay JQuery
  484
+slice = ffi "%2['slice'](%1)"
  485
+
  486
+sliceFromTo :: Double -> Double -> JQuery -> Fay JQuery
  487
+sliceFromTo = ffi "%3['slice'](%1, %2)"
  488
+
  489
+fin :: a -> Fay ()
  490
+fin _ = return ()
  491
+
  492
+size :: JQuery -> Fay Double
  493
+size = ffi "%1['length']"
  494
+
  495
+void :: Fay a -> Fay ()
  496
+void m = m >> return ()
  497
+
  498
+make :: String -> Fay JQuery
  499
+make n = select $ "<" ++ n ++ "></" ++ n ++ ">"
  500
+
  501
+_onKeycode :: (Double -> Fay Bool) -> JQuery -> Fay JQuery
  502
+_onKeycode = ffi "%2['keycode'](%1)"
  503
+
  504
+data KeyCode = KeyUp | KeyDown | KeyRet | SomeKey Double
  505
+  deriving (Show,Eq)
  506
+
  507
+onKeycode :: (KeyCode -> Fay Bool) -> JQuery -> Fay JQuery
  508
+onKeycode callback el = do
  509
+  _onKeycode (\code -> callback (case code of
  510
+                                   38 -> KeyUp
  511
+                                   40 -> KeyDown
  512
+                                   13 -> KeyRet
  513
+                                   _  -> SomeKey code))
  514
+             el
  515
+
  516
+onClick :: (EventObject -> Fay Bool) -> JQuery -> Fay JQuery
  517
+onClick = ffi "%2['click'](%1)"
  518
+
  519
+onSubmit :: Fay Bool -> JQuery -> Fay JQuery
  520
+onSubmit = ffi "%2['submit'](%1)"
  521
+
  522
+click :: JQuery -> Fay JQuery
  523
+click = ffi "%1['click']()"
  524
+
  525
+onLiveChange :: Double -> Fay () -> JQuery -> Fay JQuery
  526
+onLiveChange = ffi "%3['livechange'](%1,%2)"
8  photosorter.cabal
@@ -21,9 +21,11 @@ Flag library-only
21 21
     Default:       False
22 22
 
23 23
 library
  24
+    hs-source-dirs: ., fay-shared
24 25
     exposed-modules: Application
25 26
                      Foundation
26 27
                      Import
  28
+                     Import.Fay
27 29
                      Model
28 30
                      Settings
29 31
                      Settings.StaticFiles
@@ -40,6 +42,8 @@ library
40 42
                      Handler.SetDescription
41 43
                      Handler.ToPostList
42 44
                      Handler.UnPost
  45
+                     Handler.Command
  46
+                     SharedTypes
43 47
 
44 48
     if flag(dev) || flag(library-only)
45 49
         cpp-options:   -DDEVELOPMENT
@@ -59,6 +63,7 @@ library
59 63
                 FlexibleContexts
60 64
                 EmptyDataDecls
61 65
                 NoMonomorphismRestriction
  66
+                RankNTypes
62 67
 
63 68
     build-depends: base                          >= 4          && < 5
64 69
                  -- , yesod-platform                >= 1.1        && < 1.2
@@ -91,6 +96,9 @@ library
91 96
                  , system-fileio
92 97
                  , transformers
93 98
                  , blaze-html
  99
+                 , fay
  100
+                 , aeson
  101
+                 , process
94 102
 
95 103
 executable         photosorter
96 104
     if flag(library-only)
35  templates/incoming.julius
... ...
@@ -1,35 +0,0 @@
1  
-$(function() {
2  
-    $("button.add-new-post").click(function() {
3  
-        $(this).hide().next().show();
4  
-    });
5  
-    $("button.add-new-post2").click(function() {
6  
-        $.ajax({
7  
-            url: "@{AddPostR}",
8  
-            data: {
9  
-                date: $(this).parent().children("input[type=date]").val(),
10  
-                slug: $(this).parent().children("input[type=text]").val()
11  
-            },
12  
-            dataType: "json",
13  
-            success: function() {
14  
-                window.location.reload();
15  
-            },
16  
-            error: function () {
17  
-                alert("Some error occurred");
18  
-            },
19  
-            type: 'POST'
20  
-        });
21  
-        return false;
22  
-    });
23  
-    $("input[type=radio]").click(function() {
24  
-        $.ajax({
25  
-            url: "@{SetPostR}",
26  
-            data: {
27  
-                file: $(this).parents("form").children("input[name=file]").val(),
28  
-                post: $(this).val()
29  
-            },
30  
-            dataType: "json",
31  
-            type: 'POST'
32  
-        });
33  
-        return false;
34  
-    });
35  
-});

0 notes on commit f7527fe

Please sign in to comment.
Something went wrong with that request. Please try again.