packages feed

plzwrk 0.0.0.0 → 0.0.0.1

raw patch · 7 files changed

+168/−68 lines, 7 filesdep ~hspecPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependency ranges changed: hspec

API changes (from Hackage documentation)

+ Web.Framework.Plzwrk: (<.>) :: (s -> Attributes s opq) -> (s -> Attributes s opq) -> s -> Attributes s opq
+ Web.Framework.Plzwrk: (@=) :: k -> v -> (k, v)
+ Web.Framework.Plzwrk: wAttr :: String -> String -> s -> Attributes s opq
+ Web.Framework.Plzwrk: wAttr' :: String -> String -> Attributes s opq
+ Web.Framework.Plzwrk: wAttrs :: [(String, String)] -> s -> Attributes s opq
+ Web.Framework.Plzwrk: wAttrs' :: [(String, String)] -> Attributes s opq
+ Web.Framework.Plzwrk: wClass :: String -> s -> Attributes s opq
+ Web.Framework.Plzwrk: wClass' :: String -> Attributes s opq
+ Web.Framework.Plzwrk: wClasses :: [String] -> s -> Attributes s opq
+ Web.Framework.Plzwrk: wClasses' :: [String] -> Attributes s opq
+ Web.Framework.Plzwrk: wId :: String -> s -> Attributes s opq
+ Web.Framework.Plzwrk: wId' :: String -> Attributes s opq
+ Web.Framework.Plzwrk: wOnClick :: (opq -> s -> IO s) -> s -> Attributes s opq
+ Web.Framework.Plzwrk: wOnClick' :: (opq -> s -> IO s) -> Attributes s opq
+ Web.Framework.Plzwrk: wOnInput :: (opq -> s -> IO s) -> s -> Attributes s opq
+ Web.Framework.Plzwrk: wOnInput' :: (opq -> s -> IO s) -> Attributes s opq
+ Web.Framework.Plzwrk: wStyle :: String -> String -> s -> Attributes s opq
+ Web.Framework.Plzwrk: wStyle' :: String -> String -> Attributes s opq
+ Web.Framework.Plzwrk: wStyles :: [(String, String)] -> s -> Attributes s opq
+ Web.Framework.Plzwrk: wStyles' :: [(String, String)] -> Attributes s opq

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for plzwrk +## 0.0.0.1++- Adds util functions for attribute creation like `wClass`, `wId` etc.+ ## 0.0.0.0  - Initial release.
README.md view
@@ -43,7 +43,7 @@ 
 ## Documentation
 
-The main documentation for `plzwrk` is on [hackage](https://https://hackage.haskell.org/package/plzwrk). The four importable modules are:
+The main documentation for `plzwrk` is on [hackage](https://hackage.haskell.org/package/plzwrk). The four importable modules are:
 
 - `Web.Frameworks.Plzwrk` for the basic functions
 - `Web.Frameworks.Plzwrk.Tag` for helper functions to make takes like `input` or `br`.
kitchen-sink/Main.hs view
@@ -51,32 +51,24 @@           )
           <$> _myNoun
   -- here is our input
-  let
-    inputF = input
-      (pure dats'
-        { _simple   = singleton "type" "text"
-        , _style    = singleton "box-sizing" "content-box"
-        , _handlers = singleton
-                        "input"
-                        (\e s -> do
-                          opq <- (getOpaque browser) e "target"
-                          v   <- maybe (pure Nothing)
-                                       (\y -> (getString browser) y "value")
-                                       opq
-                          return $ maybe s (\q -> s { _myNoun = q }) v
-                        )
-        }
-      )
-      []
+  let inputF = input
+        (wAttr "type" "text" <.> wStyle "box-sizing" "content-box" <.> wOnInput
+          (\e s -> do
+            opq <- (getOpaque browser) e "target"
+            v <- maybe (pure Nothing) (\y -> (getString browser) y "value") opq
+            return $ maybe s (\q -> s { _myNoun = q }) v
+          )
+        )
+        []
   -- and here is our main div
   let
     mainDivF =
       (\abstractToConcrete name -> T.main'_
           [ section
-              (pure dats' { _class = S.singleton "content" })
+              (wClass "content")
               [ h1__ "Aphorism Machine"
               , ul
-                (pure dats' { _class = S.singleton "res" })
+                (wClass "res")
                 (fmap
                   (\(abs, conc) ->
                     (li__ (concat [abs, " is like", a_n conc, conc]))
@@ -86,57 +78,38 @@               , br
               , surpriseF
               , div
-                (pure dats'
-                  { _style = fromList
-                               [("width", "100%"), ("display", "inline-block")]
-                  }
-                )
+                (wStyles [("width", "100%"), ("display", "inline-block")])
                 [ button
-                  (pure dats'
-                    { _simple   = singleton "id" "incr"
-                    , _class    = S.singleton "dim"
-                    , _handlers = singleton
-                      "click"
-                      (\_ s -> do
-                        (consoleLog browser)
-                          $  "Here is the current state "
-                          <> show s
-                        concept    <- randAbstract (random01 browser)
-                        comparedTo <- randConcrete (random01 browser)
-                        let
-                          newS = s
-                            { _abstractToConcrete = (concept, comparedTo)
-                                                      : abstractToConcrete
-                            }
-                        (consoleLog browser)
-                          $  "Here is the new state "
-                          <> show newS
-                        return $ newS
-                      )
-                    }
+                  (wId "incr" <.> wClass "dim" <.> wOnClick
+                    (\_ s -> do
+                      (consoleLog browser)
+                        $  "Here is the current state "
+                        <> show s
+                      concept    <- randAbstract (random01 browser)
+                      comparedTo <- randConcrete (random01 browser)
+                      let
+                        newS = s
+                          { _abstractToConcrete = (concept, comparedTo)
+                                                    : abstractToConcrete
+                          }
+                      (consoleLog browser) $ "Here is the new state " <> show newS
+                      return $ newS
+                    )
                   )
                   [txt "More aphorisms"]
                 , button
-                  (pure dats'
-                    { _simple   = singleton "id" "decr"
-                    , _class    = S.singleton "dim"
-                    , _handlers = singleton
-                      "click"
-                      (\_ s -> pure $ s
-                        { _abstractToConcrete = if (null abstractToConcrete)
-                                                  then []
-                                                  else tail abstractToConcrete
-                        }
-                      )
-                    }
+                  (wId "decr" <.> wClass "dim" <.> wOnClick
+                    (\_ s -> pure $ s
+                      { _abstractToConcrete = if (null abstractToConcrete)
+                                                then []
+                                                else tail abstractToConcrete
+                      }
+                    )
                   )
                   [txt "Less aphorisms"]
                 ]
               , inputF
-              , p_
-                [ txt "Logged in as: "
-                , span (pure dats' { _class = S.singleton "username" }) [txt name]
-                ]
+              , p_ [txt "Logged in as: ", span (wClass "username") [txt name]]
               ]
           ]
         )
plzwrk.cabal view
@@ -7,7 +7,7 @@ -- hash: 8099ceb0d406f862d89306de053aba4c75999a9e0d74ac6a502458d503e7dcc1  name:           plzwrk-version:        0.0.0.0+version:        0.0.0.1 category:       Web synopsis:        A front-end framework description:    Please see the README on GitHub at <https://github.com/meeshkan/plzwrk#readme>@@ -43,6 +43,7 @@     , Web.Framework.Plzwrk.Base     , Web.Framework.Plzwrk.Browserful     , Web.Framework.Plzwrk.Domify+    , Web.Framework.Plzwrk.Util   hs-source-dirs:       src   build-depends:@@ -109,7 +110,7 @@   ghc-options: -threaded -rtsopts -with-rtsopts=-N   build-depends:       base >=4.7 && <5-    , hspec >=2.7.0 && <2.7.1+    , hspec >=2.7.0 && <2.7.2     , mtl >=2.2.2 && <2.3     , plzwrk     , text >=1.2.3 && <1.3
src/Web/Framework/Plzwrk.hs view
@@ -27,6 +27,27 @@   , plzwrk'
   , plzwrk'_
   , OldStuff(..)
+  -- util
+  , (@=)
+  , (<.>)
+  , wStyle
+  , wStyle'
+  , wStyles
+  , wStyles'
+  , wClass
+  , wClass'
+  , wClasses
+  , wClasses'
+  , wOnClick
+  , wOnClick'
+  , wId
+  , wId'
+  , wOnInput
+  , wOnInput'
+  , wAttr
+  , wAttr'
+  , wAttrs
+  , wAttrs'
   )
 where
 
@@ -36,3 +57,4 @@ import           Web.Framework.Plzwrk.Base
 import           Web.Framework.Plzwrk.Browserful
 import           Web.Framework.Plzwrk.Domify
+import           Web.Framework.Plzwrk.Util
src/Web/Framework/Plzwrk/Base.hs view
@@ -24,9 +24,9 @@ -- data classes
 
 data Attributes s opq = MkAttributes
-  { _style   :: HashMap String String
-  , _class   :: Set String
-  , _simple  :: HashMap String String
+  { _style    :: HashMap String String
+  , _class    :: Set String
+  , _simple   :: HashMap String String
   , _handlers :: HashMap String (opq -> s -> IO s)
   }
 
+ src/Web/Framework/Plzwrk/Util.hs view
@@ -0,0 +1,100 @@+module Web.Framework.Plzwrk.Util+  ( (@=)+  , (<.>)+  , wStyle+  , wStyle'+  , wStyles+  , wStyles'+  , wClass+  , wClass'+  , wClasses+  , wClasses'+  , wOnClick+  , wOnClick'+  , wId+  , wId'+  , wOnInput+  , wOnInput'+  , wAttr+  , wAttr'+  , wAttrs+  , wAttrs'+  )+where++import           Data.HashMap.Strict           as HM+import           Data.Set                      as S+import           Web.Framework.Plzwrk.Base      ( dats+                                                , dats'+                                                , Attributes(..)+                                                )++(@=) :: k -> v -> (k, v)+k @= v = (k, v)++merge :: Attributes s opq -> Attributes s opq -> Attributes s opq+merge a b = MkAttributes { _style    = HM.union (_style a) (_style b)+                         , _class    = S.union (_class a) (_class b)+                         , _simple   = HM.union (_simple a) (_simple b)+                         , _handlers = HM.union (_handlers a) (_handlers b)+                         }++(<.>)+  :: (s -> Attributes s opq)+  -> (s -> Attributes s opq)+  -> (s -> Attributes s opq)+a <.> b = (\s -> merge (a s) (b s))++wStyle :: String -> String -> (s -> Attributes s opq)+wStyle k v = (\s -> dats' { _style = HM.singleton k v })++wStyle' :: String -> String -> Attributes s opq+wStyle' k v = dats' { _style = HM.singleton k v }++wStyles :: [(String, String)] -> (s -> Attributes s opq)+wStyles kvs = (\s -> dats' { _style = HM.fromList kvs })++wStyles' :: [(String, String)] -> Attributes s opq+wStyles' kvs = dats' { _style = HM.fromList kvs }++wClass :: String -> (s -> Attributes s opq)+wClass k = (\s -> dats' { _class = S.singleton k })++wClass' :: String -> Attributes s opq+wClass' k = dats' { _class = S.singleton k }++wClasses :: [String] -> (s -> Attributes s opq)+wClasses ks = (\s -> dats' { _class = S.fromList ks })++wClasses' :: [String] -> Attributes s opq+wClasses' ks = dats' { _class = S.fromList ks }++wId :: String -> (s -> Attributes s opq)+wId v = (\s -> dats' { _simple = HM.singleton "id" v })++wId' :: String -> Attributes s opq+wId' v = dats' { _simple = HM.singleton "id" v }++wOnClick :: (opq -> s -> IO s) -> (s -> Attributes s opq)+wOnClick v = (\s -> dats' { _handlers = HM.singleton "click" v })++wOnClick' :: (opq -> s -> IO s) -> Attributes s opq+wOnClick' v = dats' { _handlers = HM.singleton "click" v }++wOnInput :: (opq -> s -> IO s) -> (s -> Attributes s opq)+wOnInput v = (\s -> dats' { _handlers = HM.singleton "input" v })++wOnInput' :: (opq -> s -> IO s) -> Attributes s opq+wOnInput' v = dats' { _handlers = HM.singleton "input" v }++wAttr :: String -> String -> (s -> Attributes s opq)+wAttr k v = (\s -> dats' { _simple = HM.singleton k v })++wAttr' :: String -> String -> Attributes s opq+wAttr' k v = dats' { _simple = HM.singleton k v }++wAttrs :: [(String, String)] -> (s -> Attributes s opq)+wAttrs kvs = (\s -> dats' { _simple = HM.fromList kvs })++wAttrs' :: [(String, String)] -> Attributes s opq+wAttrs' kvs = dats' { _simple = HM.fromList kvs }