on master help sign in
Merge branch 'develop' into tar-in-backend-path-2
commit2650249bf61bd35ad5e33cbc5005aabe90b50281 authorAli Abrar <aliabrar@gmail.com> dateWed 14 Aug 2019, 18:04 (7 years ago) parentaf8f85e202a25f
4 files changed+35−19
default.nix+1−1 lib/executable-config/lookup/src-ghcjs/Obelisk/ExecutableConfig/Lookup.hs+17−8 lib/frontend/src/Obelisk/Frontend.hs+16−9 lib/route/src/Obelisk/Route.hs+1−1
default.nix+1−1
@@ -211,7 +211,7 @@ in rec {
211211 script = ''
212212 ln -sft . '${exe}'/*
213213 mkdir -p log
214− exec ./backend ${backendArgs} >>backend.out 2>>backend.err </dev/null
214+ exec ./backend ${backendArgs} </dev/null
215215 '';
216216 serviceConfig = {
217217 User = user;
lib/executable-config/lookup/src-ghcjs/Obelisk/ExecutableConfig/Lookup.hs+17−8
@@ -15,28 +15,37 @@ import GHCJS.DOM.Document (getHead)
1515import GHCJS.DOM.DOMStringMap (get)
1616import GHCJS.DOM.Element (getInnerHTML)
1717import GHCJS.DOM.HTMLElement (HTMLElement(HTMLElement), getDataset)
18−import GHCJS.DOM.NodeList (item, getLength)
18+import GHCJS.DOM.NodeList (IsNodeList, item, getLength)
1919import GHCJS.DOM.ParentNode (querySelectorAll)
20−import GHCJS.DOM.Types (Node(Node), castTo)
20+import GHCJS.DOM.Types (MonadJSM, Node(Node), castTo)
2121
2222getConfigs :: IO (Map Text ByteString)
2323getConfigs = do
2424 Just doc <- currentDocument
2525 Just hd <- getHead doc
26− nodes <- collToList =<< querySelectorAll hd ("[data-obelisk-executable-config-inject-key]" :: Text)
26+ nodes <- nodeListNodes =<< querySelectorAll hd ("[data-obelisk-executable-config-inject-key]" :: Text)
2727 fmap Map.fromList $ for nodes $ \node -> do
2828 e <- castTo HTMLElement node >>= \case
2929 Nothing -> error "Found node with data attribute obelisk-executable-config-inject-key that is not an HTMLElement."
3030 Just htmlE -> return htmlE
3131 dataset <- getDataset e
3232 (,)
33− <$> get dataset ("obelisk-executable-config-inject-key" :: Text)
33+ -- the key is camelCased: https://html.spec.whatwg.org/multipage/dom.html#dom-dataset
34+ <$> get dataset ("obeliskExecutableConfigInjectKey" :: Text)
3435 <*> (fmap decodeOrFail (getInnerHTML e))
3536 where
36− collToList es = do
37− len <- getLength es
38− list <- traverse (item es) [0..len-1]
39− pure $ catMaybes list
4037 decodeOrFail x = case B64.decode (T.encodeUtf8 x) of
4138 Left e -> error ("Obelisk.ExecutableConfig.Lookup.getConfigs: error when decoding base64: " ++ e)
4239 Right x' -> x'
40+
41+-- | Collect all nodes in the node list.
42+--
43+-- TODO: this and the version in obelisk-frontend should be
44+-- upstreamed to jsaddle.
45+nodeListNodes :: (IsNodeList l, MonadJSM m) => l -> m [Node]
46+nodeListNodes es = do
47+ len <- getLength es
48+ -- Warning! len is unsigned. If the NodeList is empty, we must avoid
49+ -- accidentally traversing over [0..maxBound::Word]
50+ nodes <- traverse (item es) $ if len == 0 then [] else [0..len-1]
51+ pure $ catMaybes nodes
lib/frontend/src/Obelisk/Frontend.hs+16−9
@@ -43,11 +43,11 @@ import qualified GHCJS.DOM as DOM
4343import qualified GHCJS.DOM.Types as DOM
4444import qualified GHCJS.DOM.History as DOM
4545import qualified GHCJS.DOM.Window as DOM
46−import Language.Javascript.JSaddle (JSM, jsNull)
46+import Language.Javascript.JSaddle (MonadJSM, JSM, jsNull)
4747import GHCJS.DOM (currentDocument)
4848import GHCJS.DOM.Document (getHead)
49−import GHCJS.DOM.Node (removeChild_)
50−import GHCJS.DOM.NodeList (item, getLength)
49+import GHCJS.DOM.Node (Node, removeChild_)
50+import GHCJS.DOM.NodeList (IsNodeList, item, getLength)
5151import GHCJS.DOM.ParentNode (querySelectorAll)
5252import Obelisk.Frontend.Cookie
5353import Obelisk.Route.Frontend
@@ -105,13 +105,20 @@ removeHTMLConfigs :: JSM ()
105105removeHTMLConfigs = void $ runMaybeT $ do
106106 doc <- MaybeT currentDocument
107107 hd <- MaybeT $ getHead doc
108− es <- collToList =<< querySelectorAll hd ("[data-obelisk-executable-config-inject-key]" :: Text)
108+ es <- nodeListNodes =<< querySelectorAll hd ("[data-obelisk-executable-config-inject-key]" :: Text)
109109 for_ es $ removeChild_ hd
110− where
111− collToList es = do
112− len <- getLength es
113− lst <- traverse (item es) $ take (fromIntegral len) $ [0..] -- fun with unsigned types ...
114− pure $ catMaybes lst
110+
111+-- | Collect all nodes in the node list.
112+--
113+-- TODO: this and the version in exe-config/ghcjs/lookup should be
114+-- upstreamed to jsaddle.
115+nodeListNodes :: (IsNodeList l, MonadJSM m) => l -> m [Node]
116+nodeListNodes es = do
117+ len <- getLength es
118+ -- Warning! len is unsigned. If the NodeList is empty, we must avoid
119+ -- accidentally traversing over [0..maxBound::Word]
120+ nodes <- traverse (item es) $ if len == 0 then [] else [0..len-1]
121+ pure $ catMaybes nodes
115122
116123setInitialRoute :: Bool -> JSM ()
117124setInitialRoute useHash = do
lib/route/src/Obelisk/Route.hs+1−1
@@ -202,7 +202,7 @@ decode e x = runIdentity (tryDecode e x)
202202tryDecode :: Encoder Identity parse decoded encoded -> encoded -> parse decoded
203203tryDecode (Encoder (Identity impl)) x = _encoderImpl_decode impl x
204204
205−-- | Similar to 'decode' above, once an encoder has been checked so that its check monad is Identity, it
205+-- | Similar to 'decode', once an encoder has been checked so that its check monad is Identity, it
206206-- can be used to actually encode by using this. Note that while there's no constraint on the parse monad here,
207207-- one should usually be applying decode and encode to the same 'Encoder'
208208encode :: Encoder Identity parse decoded encoded -> decoded -> encoded