diff --git a/spec/Main.hs b/spec/Main.hs
index 62e3169..351fe4e 100644
--- a/spec/Main.hs
+++ b/spec/Main.hs
@@ -56,7 +56,6 @@ feedTests =
ft <- toXMLFeed (_wordpress ctxt) wpfeed
ft `shouldBe` "\n\n https://myurl.com/feed\n My Blog\n 2014-10-20T07:00:00Z\n \n https://myurl.com/2014/10/foo-bar/\n <i>Foo</i> bar\n 2014-10-20T07:00:00Z\n 2014-10-20T07:00:00Z\n summary\n This is the title: <i>Foo</i> bar\n \n Emma Goldman\n \n \n \n\n"
---larcenyFillTests :: SpecM () ()
larcenyFillTests :: Spec
larcenyFillTests = do
describe "" $ do
diff --git a/src/Web/Offset/Splices.hs b/src/Web/Offset/Splices.hs
index b197b83..3921440 100644
--- a/src/Web/Offset/Splices.hs
+++ b/src/Web/Offset/Splices.hs
@@ -173,7 +173,6 @@ wpPostByPermalinkFill extraFields getURI wpLens = maybeFillChildrenWith' $
return $ Just (postSubs wp extraFields post)
_ -> return Nothing
-
feedSubs :: [Field s] -> WPLens b s -> Object -> Substitutions s
feedSubs fields lens obj=
subs $ [("wpPost", wpPostFromObjectFill fields lens obj)]
@@ -300,6 +299,39 @@ prefetchSubs wp mkeys =
subs [ ("wpPosts", wpPostsPrefetch wp mkeys)
, ("wpPage", useAttrs (a"name") $ wpPagePrefetch mkeys) ]
+postPrefetchSubs :: Wordpress b
+ -> MVar [WPKey]
+ -> [Field s]
+ -> Object
+ -> Substitutions s
+postPrefetchSubs wp mkeys extraFields object =
+ subs (map (buildSplice object) (mergeFields postFields extraFields))
+ where -- run queries for Q fields
+ buildSplice o (Q n endpoint) =
+ (transformName n, customPrefetchFill wp mkeys (toEndpoint endpoint $ getText n o))
+ -- do nothing for other fields
+ buildSplice o (F n) = (transformName n, textFill "")
+ buildSplice o (P n _) = (transformName n, textFill "")
+ buildSplice o (PN n _) = (transformName n, textFill "")
+ buildSplice o (PM n _) = (transformName n, textFill "")
+ buildSplice o (N n _) = (transformName n, textFill "")
+ buildSplice o (C n _) = (transformName n, textFill "")
+ buildSplice o (CN n _ _) = (transformName n, textFill "")
+ buildSplice o (M n fs) = (transformName n, textFill "")
+
+ getText n o = case M.lookup n o of
+ Just (String t) -> t
+ Just (Number i) -> either (tshow :: Double -> Text)
+ (tshow :: Integer -> Text) (floatingOrInteger i)
+ _ -> ""
+
+customPrefetchFill :: Wordpress b -> MVar [WPKey] -> Text -> Fill s
+customPrefetchFill Wordpress{..} mKeys endpoint =
+ Fill $ \attrs (path, tpl) lib ->
+ do let key = EndpointKey endpoint
+ liftIO $ modifyMVar_ mKeys (\keys -> return $ key : keys)
+ return ""
+
wpPostsPrefetch :: Wordpress b
-> MVar [WPKey]
-> Fill s