haskell-snap-framework

Passing data directly into templates in compiled Heist (Haskell)?

二次信任 提交于 2019-12-11 06:57:14
问题 I use compiled Heist. My splices only do run-time work (no load-time work). I have a template.tpl like this: <html> <head> <title><titleSplice/></title> </head> <body> <bodySplice/> </body> </html> This is how I do things: Within the Snap action for a /:param route, I use renderTemplate heistState "template" to obtain a MyHeistRuntimeMonad Builder . I can pass the :param value to my splice by putting it into my runtime monad via ReaderT: type MyHeistRuntimeMonad = ReaderT String IO . (Where

Digestive Functors with a variable number of subforms (Snap/Heist)

落花浮王杯 提交于 2019-12-08 15:41:03
问题 I'm working on porting a site from PHP to Snap w/ Heist. I've ported some of the simpler forms to using Digestive Functors successfully, but now I have to do the tricky ones that require the use of subforms. This application manages producing flyers for retail stores, so one of the tasks that need to be done is adding an ad size and defining its physical dimensions on the printed flyer. Sizes will vary depending on the type of page (configurable by the flyer owner) and its orientation (which

Snap Framework: Custom snaplet handler won't render template

a 夏天 提交于 2019-12-08 05:11:08
问题 I'm just getting started with writing custom snaplets and hit a road block. I have the following basic snaplet which has a "roles" template located in the "snaplets/admin-pg/snaplets/heist/templates". Can someone tell me why the handleUsers function does not render the "roles" template? I get a "No handler accepted '/pgadmin/users' " error. I'm sure I'm missing something very basic. Thanks. My main app is defined as follows. It is an instance of HasHeist data App = App { _heist :: Snaplet

Use subsnaplet during snaplet initialization?

こ雲淡風輕ζ 提交于 2019-12-07 22:58:03
问题 I have some snaplet like this: data DB b = DB {_pgsql :: Snaplet Postgresql ,dbCache :: Map Text Text } And I wish to fill dbCache from postgresql database. Seems that it is natural to do this during snaplet initialization. initDB :: SnapletInit b (DB b) initDB = makeSnaplet "db" "cached database" Nothing $ do pgs <- nestSnaplet "pgsql" pgsql pgsInit cache <- getSomeDataPlease pgs return $ DB pgs cache So, the question is: How is it possible to use pgs :: Snaplet Postgres within Initializer

Snap 0.9 routing behavior

谁说胖子不能爱 提交于 2019-12-07 15:14:16
问题 I can't figure out the routing strangeness in Snap 0.9 (and, most likely, other versions) I understand "/" is a catch everything pattern unless I put ifTop function inside the handler, right? So, with ("/", blah) route, any URL should be handled by the blah handler, correct? Playing with the default app generated by snap init, I can't get snap to render anything but index.tpl for the root request. Given root ("/", blah) and handler blah :: Handler App App () blah = render "blah" it renders

Use subsnaplet during snaplet initialization?

五迷三道 提交于 2019-12-06 11:52:38
I have some snaplet like this: data DB b = DB {_pgsql :: Snaplet Postgresql ,dbCache :: Map Text Text } And I wish to fill dbCache from postgresql database. Seems that it is natural to do this during snaplet initialization. initDB :: SnapletInit b (DB b) initDB = makeSnaplet "db" "cached database" Nothing $ do pgs <- nestSnaplet "pgsql" pgsql pgsInit cache <- getSomeDataPlease pgs return $ DB pgs cache So, the question is: How is it possible to use pgs :: Snaplet Postgres within Initializer monad to read data from db? The DB access functions provided by snaplet-postgresql-simple run in any

Snap: inner/outer loops with heist

余生长醉 提交于 2019-12-06 10:01:21
问题 I am not sure if I phrased the question in the title correctly but here is the situation.. I need to create a dynamic table with heist when table fields (schema) are only available at run time. So usually, when the schema is known at compile, I would do something like this: <table> <row-splice> <tr> <td> <field1/> </td> <td> <field2/> </td> <td> <field3/> </td> </tr> </row-splice> </table> That is when I know the number of fields and their names at compile time. I understand how to process

Snap: compiled splices code example

巧了我就是萌 提交于 2019-12-06 05:57:39
问题 I think I did asked a similar question some time ago but it was not answered due to unstable API. So I was waiting for the 0.13 to pass by. I am not sure if it is correct to bring up a similar question...? What is the alternative to interpreted runChildrenWith(Text) and mapSplices in the compiled splices world? (this combination seems to be the most common) I would really appreciate some code examples if possible. If I understand correctly, we get together all the application splices and then

How do I maintain a server-side state with Snap Framework?

青春壹個敷衍的年華 提交于 2019-12-05 08:52:55
Server-side sessions are not [yet] part of the Snap Framework. Is there a way to add some sort of server side state? Let's pretend I want to increment a counter for each HTTP request. How would I do it? Easiest way is to put the state behind an mvar: fooHandler :: MVar Int -> Snap () fooHandler mvar = do x <- liftIO $ modifyMVar mvar $ \y -> let y'=y+1 in (y',y') writeBS $ S.pack $ "Incremented counter to: " ++ show x Initialize the mvar when the site is initialized. Hope this helps. The above answer is correct as far as it goes, but it doesn't deal with some real issues. First up is server

Snap: inner/outer loops with heist

回眸只為那壹抹淺笑 提交于 2019-12-04 17:37:30
I am not sure if I phrased the question in the title correctly but here is the situation.. I need to create a dynamic table with heist when table fields (schema) are only available at run time. So usually, when the schema is known at compile, I would do something like this: <table> <row-splice> <tr> <td> <field1/> </td> <td> <field2/> </td> <td> <field3/> </td> </tr> </row-splice> </table> That is when I know the number of fields and their names at compile time. I understand how to process all that in the handler with 'runChildrenWith', 'mapSplices' and so on ... Now I am in a situation when