Skip to content
Snippets Groups Projects
Commit 297c8335 authored by jan.hamal.dvorak's avatar jan.hamal.dvorak
Browse files

Some more cleanup

parent ca1a3d1e
No related branches found
No related tags found
No related merge requests found
...@@ -55,7 +55,7 @@ library ...@@ -55,7 +55,7 @@ library
DisambiguateRecordFields NoFieldSelectors OverloadedRecordDot DisambiguateRecordFields NoFieldSelectors OverloadedRecordDot
ghc-options: ghc-options:
-Wall -Wcompat -Wincomplete-uni-patterns -Wall -Wcompat -Wincomplete-uni-patterns -Wpartial-fields
-Wincomplete-record-updates -Widentities -Wredundant-constraints -Wincomplete-record-updates -Widentities -Wredundant-constraints
-Wunused-packages -Wunused-packages
...@@ -69,6 +69,7 @@ library ...@@ -69,6 +69,7 @@ library
containers >=0.6, containers >=0.6,
cookie >=0.4, cookie >=0.4,
foreign-store >=0.2, foreign-store >=0.2,
HsOpenSSL >=0.11,
http-types >=0.12, http-types >=0.12,
hvect >=0.4, hvect >=0.4,
lucid >=2.9, lucid >=2.9,
...@@ -82,8 +83,7 @@ library ...@@ -82,8 +83,7 @@ library
wai >=3.2, wai >=3.2,
wai-extra >=3.0, wai-extra >=3.0,
wai-websockets >=3.0, wai-websockets >=3.0,
websockets >=0.12, websockets >=0.12
HsOpenSSL >=0.11
test-suite spec test-suite spec
type: exitcode-stdio-1.0 type: exitcode-stdio-1.0
...@@ -111,7 +111,7 @@ test-suite spec ...@@ -111,7 +111,7 @@ test-suite spec
DisambiguateRecordFields NoFieldSelectors OverloadedRecordDot DisambiguateRecordFields NoFieldSelectors OverloadedRecordDot
ghc-options: ghc-options:
-Wall -Wcompat -Wincomplete-uni-patterns -Wall -Wcompat -Wincomplete-uni-patterns -Wpartial-fields
-Wincomplete-record-updates -Widentities -Wredundant-constraints -Wincomplete-record-updates -Widentities -Wredundant-constraints
-threaded -rtsopts -with-rtsopts=-N -threaded -rtsopts -with-rtsopts=-N
...@@ -125,6 +125,8 @@ test-suite spec ...@@ -125,6 +125,8 @@ test-suite spec
containers >=0.6, containers >=0.6,
cookie >=0.4, cookie >=0.4,
foreign-store >=0.2, foreign-store >=0.2,
hikaru,
hspec,
http-types >=0.12, http-types >=0.12,
hvect >=0.4, hvect >=0.4,
lucid >=2.9, lucid >=2.9,
...@@ -138,6 +140,4 @@ test-suite spec ...@@ -138,6 +140,4 @@ test-suite spec
wai >=3.2, wai >=3.2,
wai-extra >=3.0, wai-extra >=3.0,
wai-websockets >=3.0, wai-websockets >=3.0,
websockets >=0.12, websockets >=0.12
hikaru,
hspec
...@@ -18,17 +18,15 @@ where ...@@ -18,17 +18,15 @@ where
import Praha import Praha
import Praha.Config.Environment import Praha.Config.Environment
import System.IO.Unsafe import Hikaru.Action
import Data.Text (splitOn)
import Data.Time.Clock.POSIX (getPOSIXTime)
import OpenSSL import OpenSSL
import OpenSSL.Random
import OpenSSL.EVP.Base64 import OpenSSL.EVP.Base64
import OpenSSL.EVP.Digest import OpenSSL.EVP.Digest
import OpenSSL.Random
import Data.Text (splitOn) import System.IO.Unsafe
import Data.Time.Clock.POSIX (getPOSIXTime)
import Hikaru.Action
sha256 :: Digest sha256 :: Digest
......
...@@ -34,12 +34,11 @@ where ...@@ -34,12 +34,11 @@ where
import Hikaru.Action (abortMiddleware) import Hikaru.Action (abortMiddleware)
import Hikaru.Route import Hikaru.Route
import Network.HTTP.Types.Status import Data.List (sortOn, reverse, lookup)
import Network.HTTP.Types.Header import Network.HTTP.Types.Header
import Network.HTTP.Types.Status
import Network.Wai import Network.Wai
import Data.List (reverse, lookup, sortOn)
-- | -- |
-- Since routes do not share a common type (due to their captured parameters -- Since routes do not share a common type (due to their captured parameters
......
...@@ -24,15 +24,12 @@ where ...@@ -24,15 +24,12 @@ where
import Hikaru.Route import Hikaru.Route
import Hikaru.Types import Hikaru.Types
import Network.HTTP.Types.URI
import Data.Binary.Builder import Data.Binary.Builder
import Data.HVect
import Data.List (map, filter) import Data.List (map, filter)
import Data.Maybe (isJust) import Data.Maybe (isJust)
import Data.HVect
import Lucid import Lucid
import Network.HTTP.Types.URI
-- | -- |
......
...@@ -27,10 +27,9 @@ module Hikaru.Media ...@@ -27,10 +27,9 @@ module Hikaru.Media
where where
import Praha import Praha
import Data.List (filter, lookup, sortOn)
import Data.Char
import Data.Attoparsec.Text import Data.Attoparsec.Text
import Data.Char
import Data.List (filter, lookup, sortOn)
-- | -- |
......
...@@ -55,18 +55,17 @@ module Hikaru.Route ...@@ -55,18 +55,17 @@ module Hikaru.Route
) )
where where
import Praha hiding (curry) import Praha hiding (curry)
import Hikaru.Media import Hikaru.Media
import Hikaru.Types import Hikaru.Types
import Data.HVect hiding (reverse)
import Data.List (nub, reverse, lookup)
import Data.Typeable (TypeRep, typeRep)
import Network.HTTP.Types.Header import Network.HTTP.Types.Header
import Network.Wai import Network.Wai
import Network.Wai.Handler.WebSockets import Network.Wai.Handler.WebSockets
import Data.List (reverse, nub, lookup)
import Data.Typeable (TypeRep, typeRep)
import Data.HVect hiding (reverse)
-- | -- |
-- Route combines path description with a handler that gets saturated -- Route combines path description with a handler that gets saturated
......
...@@ -54,6 +54,7 @@ module Hikaru.Widget ...@@ -54,6 +54,7 @@ module Hikaru.Widget
-- * Building Widgets -- * Building Widgets
, WidgetT , WidgetT
, getPrefix
, getArguments , getArguments
, getArgumentMaybe , getArgumentMaybe
, getArgumentDefault , getArgumentDefault
...@@ -64,11 +65,12 @@ module Hikaru.Widget ...@@ -64,11 +65,12 @@ module Hikaru.Widget
) )
where where
import Praha import Praha
import Data.Text (stripPrefix)
import Data.List (lookup, filter) import Data.List (lookup, filter)
import Lucid import Data.Text (stripPrefix)
import Hikaru.Types
import Hikaru.Action import Hikaru.Action
import Hikaru.Types
import Lucid
-- | -- |
...@@ -161,6 +163,15 @@ where ...@@ -161,6 +163,15 @@ where
} }
-- |
-- Obtain widget prefix as text.
--
getPrefix :: (Monad m) => WidgetT m Text
getPrefix = WidgetT do
Env{prefix} <- ask
return prefix
-- | -- |
-- Obtain all widget arguments as pieces of text. -- Obtain all widget arguments as pieces of text.
-- --
......
...@@ -16,13 +16,12 @@ where ...@@ -16,13 +16,12 @@ where
import Hikaru import Hikaru
import UnliftIO.MVar
import Data.Aeson (Value) import Data.Aeson (Value)
import Data.Text (unlines)
import Lucid import Lucid
import Network.HTTP.Types.Header import Network.HTTP.Types.Header
import Network.HTTP.Types.Status import Network.HTTP.Types.Status
import Network.Wai import UnliftIO.MVar
import Data.Text (unlines)
-- Action ------------------------------------------------------------------ -- Action ------------------------------------------------------------------
...@@ -39,10 +38,10 @@ where ...@@ -39,10 +38,10 @@ where
deriving (Functor, Applicative, Monad, MonadIO) deriving (Functor, Applicative, Monad, MonadIO)
instance MonadAction Action where instance MonadAction Action where
getActionEnv = Action (demoActionEnv <$> ask) getActionEnv = Action ((.demoActionEnv) <$> ask)
instance MonadModel Action where instance MonadModel Action where
getModelEnv = Action (demoModelEnv <$> ask) getModelEnv = Action ((.demoModelEnv) <$> ask)
data DemoEnv data DemoEnv
...@@ -74,7 +73,7 @@ where ...@@ -74,7 +73,7 @@ where
countVisitor :: (MonadModel m) => m Word countVisitor :: (MonadModel m) => m Word
countVisitor = do countVisitor = do
counter <- modelCounter <$> getModelEnv counter <- (.modelCounter) <$> getModelEnv
liftIO do liftIO do
modifyMVar_ counter (return . (+ 1)) modifyMVar_ counter (return . (+ 1))
readMVar counter readMVar counter
...@@ -82,7 +81,7 @@ where ...@@ -82,7 +81,7 @@ where
addCase :: (MonadModel m) => AddCase -> m Case addCase :: (MonadModel m) => AddCase -> m Case
addCase AddCase{..} = do addCase AddCase{..} = do
nextId <- liftIO . readMVar . modelCounter =<< getModelEnv nextId <- liftIO . readMVar . (.modelCounter) =<< getModelEnv
let case' = Case { caseId = nextId let case' = Case { caseId = nextId
, caseName = acName , caseName = acName
...@@ -91,7 +90,7 @@ where ...@@ -91,7 +90,7 @@ where
, caseActive = acActive , caseActive = acActive
} }
cases <- modelCases <$> getModelEnv cases <- (.modelCases) <$> getModelEnv
liftIO do liftIO do
modifyMVar_ cases (return . (<> [case'])) modifyMVar_ cases (return . (<> [case']))
...@@ -110,7 +109,7 @@ where ...@@ -110,7 +109,7 @@ where
runAction :: ModelEnv -> Action () -> Application runAction :: ModelEnv -> Action () -> Application
runAction me act = do runAction me act = do
respond \ae -> do respond \ae -> do
runReaderT (unAction act) (DemoEnv ae me) runReaderT ((.unAction) act) (DemoEnv ae me)
makeApplication :: ModelEnv -> Application makeApplication :: ModelEnv -> Application
...@@ -215,7 +214,7 @@ where ...@@ -215,7 +214,7 @@ where
handle = do handle = do
setHeader hCacheControl "no-store" setHeader hCacheControl "no-store"
cases <- liftIO . readMVar . modelCases =<< getModelEnv cases <- liftIO . readMVar . (.modelCases) =<< getModelEnv
sendHTML do sendHTML do
h1_ "Cases" h1_ "Cases"
...@@ -361,18 +360,18 @@ where ...@@ -361,18 +360,18 @@ where
(\(x1, x2) x3 x4 -> AddCase x1 x2 x3 x4) (\(x1, x2) x3 x4 -> AddCase x1 x2 x3 x4)
<$> element MsgCaseName do <$> element MsgCaseName do
(,) (,)
<$> input "name" acName do <$> input "name" (.acName) do
return () return ()
<*> input "recno" acRecNo do <*> input "recno" (.acRecNo) do
return () return ()
<*> element MsgCaseMode do <*> element MsgCaseMode do
select "mode" acMode do select "mode" (.acMode) do
return () return ()
<*> element MsgCaseEnabled do <*> element MsgCaseEnabled do
select "active" acActive do select "active" (.acActive) do
hint RenderExpanded hint RenderExpanded
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment