FAQ Database Discussion Community

Where to store API keys and other 'secrets' in a yesod app

I'm trying out a yesod applications which I will eventually put up on github or similar. I will use oauth2 with google which means I have to provide an email and secret token. Which I obviously do not want up on github. What is a good place to store these...

Which form to run?

I'm trying to build a page with multiple similar forms on one page. Each form is very simple, it provides an integer input and a submit button. Each form corresponds to a counter, and the counter is supposed to be increased when the form is submitted. incrementCounterForm :: Entity Counter...

why is the cabal sandbox inited after installing yesod-bin?

On the Yesod homepage (http://www.yesodweb.com/page/quickstart) the following installation sequence is suggested: wget http://www.stackage.org/lts/cabal.config cabal update # download package list cabal install alex happy yesod-bin # install build tools yesod init --bare # answer questions as prompted cabal sandbox init # set up a sandbox cabal install --run-tests # install libraries...

How can I run Yesod's DB actions in the REPL?

It is easy to run DB actions in the normal Handler workflow, since the runDB function can be used to transform the SqlPersistM actions into Handler ones. But there is no such way to convert SqlPersistM directly into IO using the default app settings. Looking at the Foundation.hs as its...

SVG tags in hamlet shakespearean (yesod/haskell) templates?

Is there a way to include tags in hamlet? If not, what are the workarounds/alternatives?

Yesod - how to make addScriptRemote add the script in the head section?

In Yesod/Haskell, I'd like to call addScriptRemote and have it add the <script> tag in the head section. As is, it seems to add the script only to the body section.

Composite Primary Key in Yesod

I am fairly new to Haskell and have been experimenting with yesod for about a week now. I have been trying to connect to an existing database that has a composite primary key in sqlite. I managed to get the code to work with Database.Persist.Sqlite as a standalone application. Here...

How can I query using persistent-mysql using withMySQLConn?

I'm using persistent-mysql and trying to find a way to execute a simple command from the SqlPersistM () monad. However I'm running into type errors. First there is withMySQLConn defaultConnectInfo, which has the following type (MonadLogger m, MonadBaseControl IO m, MonadIO m) => (Connection -> m a) -> m a...

Yesod and dynamic Bootstrap/jQuery form

I work with an existing form built with Bootstrap. But this form contains <input>s dynamically added with jQuery. So user can add any number of inputs before submitting the form. I know that the names of these inputs forms like attr1, attr2, attr3 and so on. But I cannot run...

How can I embed both Text and Widget in another Widget in Yesod?

Given a simple example like this glyphicon :: Text -> Widget glyphicon name = toWidget [hamlet|<span class="glyphicon glyphicon-#{name}">|] foo :: ToMarkup a => a -> Widget foo content = toWidget [hamlet|<div class="foo">#{content}</div>|] Is there a builtin mechanism in Yesod which would allow me to do both foo "some text" and...

Send 301 redirect in Yesod

With this Yesod handler: myR :: Handler Html myR = redirect HomeR I can redirect using the 303/302 status code according to the documentation The documentation states that redirectWith shall be used for other status codes. What would be an example of using redirectWith with a 301 status code?...

Haskell Yesod: How to read text from file and apply variable interpolation to its content?

I have quite big markdown text hardcoded inside my handler function currently. To render it I use whamlet quasiquoter and Text.Markdown.markdown from markdown package: let md :: L.Text md = "#Some markdown stuff" authLayout $ [whamlet| <div .StaticContent> #{markdown def md} |] There are some hardcoded links in the text...

where does ^{pageBody pc} come from?

In default-layout-wrapper.hamlet file, there is ^{pageBody pc} which allows me to embed body content. I can find the pc part in Foundation.hs file. but where is pageBody constructed (in what file)? Same question for this variable #{pageTitle pc}.

Simplifying Persistent & Esqueleto code

I have a fairly simple query that does two outer joins. (A meal has many recipes which in turn have many foods). getMeals :: (MonadIO m) => Key DbUser -> SqlPersistT m [Meal] getMeals user = fmap deserializeDb $ E.select $ E.from $ \(m `E.InnerJoin` u `E.LeftOuterJoin` r `E.LeftOuterJoin` f)...

Reading the run mode in Yesod

How can I determine the run mode (Development, Testing, Staging, Production) in a Yesod application? I have a service that should return a value only in Development and Testing modes. The value is a secret token that will be sent as part of a validation for a newly registered user....

Couldn't match type Data.Enumerator.Internal.Iteratee with IO

import qualified Data.ByteString.Lazy as L import Data.Enumerator.List (consume) data App = App mkYesod "App" [parseRoutesNoCheck| /*Texts WikR GET --PathMultiPiece handler for all combinations / WikiR POST |] instance Yesod App getWikR :: [Text] -> Handler Text getWikR parts = return "" --defaultLayout [whamlet||] postWikiR = do bss <- lift consume...

Using JS-variable in Yesod handler's code

I know that we can use Haskell data in the Julius-code, for example: $(function(){ $("section.#{sectionClass}").hide(); }); But how can I use JS-variable in the Haskell code? For example: ... in some .julius $(function set_global_variable( value ) { window.myGlobalValue = value; }); ... in some handler, pseudocode: getMyPageR :: Handler Html...

Yesod CSS lucius

I have made a table in my hamlet file: <table> $forall ivlist <- y <tr> $forall iv <- ivlist <td>^{fvInput iv} and its respective css in lucius file: td { width:1em; height:1em; } The CSS was also generated as expected,but the output was different. When I change the height and...

How to specify type for class constrained value?

I'm trying to use a type signature on the result of the following persistent call. I can't figure out how to define the signature for something that's parameterized and class constrained such as the m inside of the transformer below: saveMyStuff :: MonadIO m => Int -> SqlPersistT m Stuff...

Yesod errors when compiling

For AForm I have got some compile errors: 1. For default Int value: data Person = Person { name :: Text , age :: Maybe Int } deriving Show formPerson :: AForm Handler Person formPerson = Person <$> areq textField "Person Name" Nothing <*> aopt intField "Person Age" (Just 25)...

In yesod (haskell), how do I load a plain html-formatted file (not a hamlet) as a widget?

How do I load a plain html-formatted file (not a hamlet-formatted file) as a widget? In other words I'm looking for the html equivalent of: toWidget $(whamletFile "test.hamlet") ...

How can I store request-local information in Yesod middleware and retrieve it from a Handler?

Before any handler code is executed, I need to load some information about the user, which is determined by the request cookies, and then access that in all of my handler code. I've looked at the yesod-core codebase and found that I could override the yesodMiddleware function and provide a...

Is there a way to pass a Hamlet block as an argument to a function?

Let's say that I have a generic content :: Widget -> Widget helper, which takes a Widget and wraps it in some HTML. Is is possible to call this function giving it the argument inline in the Hamlet file, similarly to what one would do in Ruby on Rails? For...

compile-time vs. run-time cost of Hamlet templates

For the Hamlet template mechanism, I understand that the template is parsed at compile time, resulting in source code that contains calls to blaze-html combinators (and possibly other expressions because of interpolation). So the points (subtrees) where interpolation happens are known at compile-time. At run-time, we need to compute the...

In Yesod/Haskell, how do I use data from IO with the variable interpolation functionality?

How do I take values from an IO monad and interpolate into a yesod widget? For example, I want to interpolate the contents of a file into hamlet: (readFile "test.txt") >>= \x -> toWidget $ [hamlet| <p> text: #{x} |] or equivalently: contents <- (readFile "test.txt") toWidget $ [hamlet| <h2>...

Is there a Yesod alternative to the Rails' `link_to foo, bar, method: “delete”?

Is there a simple way to generate a link that uses a different method than GET in Yesod, such as in Ruby on Rails, where one can do link_to foo, bar, method: "post", which would submit the link via JavaScript? update: What Ruby on Rails does is that it generates...

Cabal build failure on ReadArgs when deploying to OpenShift

I am trying to deploy a web application to OpenShift. My app is written with Yesod web framework. I would like to use the Yesod cartridge from Haskell wiki. I can create the application and deploy the example supplied with the cartridge. However, when I add more dependencies to the...

A typeclass instance that needs configuration data. What are my options?

Using yesod and persistent, I made what I think is a handy type to handle Markdown data: {-# LANGUAGE OverloadedStrings #-} module Utils.MarkdownText where import Prelude import Data.Text.Lazy import Data.Text as T import Database.Persist import Database.Persist.Sql import Text.Blaze import Text.Markdown newtype MarkdownText = MarkdownText { rawMarkdown :: T.Text } instance...

Yeson.json.object is applied to too many arguments

import Yesod import Data.Text data App = App instance Yesod App mkYesod "App" [parseRoutes| / Home GET |] getHome :: String -> Handler Value getHome = object ["name" .= ("Adam"::Text)] main = warpDebug 2012 App throws error as, Couldn't match expected type ‘String -> Handler Value’ with actual type ‘Value’...

Error when starting Yesod app on openshift - command line args?

I am getting the following error when (re)starting my Yesod app on openshift: server: InvalidYaml (Just (YamlException "Yaml file not found: xxx.xxx.xxx.xxx")) Where xxx.xxx.xxx.xxx is an IP address. I did find a link to a Heroku+Yesod issue saying something about "removing an argument" but it didn't say from where, and...

Yesod: Stuck in book “Seven Web frameworks in seven weeks”

I installed Yesod according to the quick start guide. I bought the book "Seven Web frameworks in seven weeks" and I'm trying to follow along. I'm on page 204 (Day 1: Working with models). When I enter ghci Model.hs in order to enter some data into the database, as the...

how to break up the monolithic mkYesod block safely

This question is more to help my understanding of Yesod than anything else. Take the example at http://www.yesodweb.com/book/basics and in particular the code generated by the mkYesod TH function. The problem that I perceive is that this TH generates both the route data type (data Route HelloWorld = HomeR) and...

Yesod Mform and hamlet

Hi I am new to yesod and following the documentation to make a form. In the documentation the form template was created in .hs file itself. But I have a separate hamlet where I want to customize. I want to access "fields" in my hamlet file. The expected type of...

use runDB in a SubSite Yesod

i want create a post method in a SubSite to create a new entity, i have this AForm demoForm :: RenderMessage master FormMessage => Maybe Demo -> AForm (HandlerT master IO) Demo demoForm demo = Demo <$> areq textField (fieldSettingsLabel ("fieldone"::T.Text)) (demoFieldOne <$> demo) <*> areq intField (fieldSettingsLabel ("fieldone"::T.Text)) (demoFieldTwo...

Missing imports from Hamlet libraries

This is the code snippet from O reilly - Yesod - Widgets, getRootR = defaultLayout $ do setTitle "My Page Title" toWidget [lucius| h1 { color: green; } |] addScriptRemote "https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" toWidget [julius| $(function() { $("h1").click(function(){ alert("You clicked on the heading!"); }); }); |] toWidgetHead [hamlet| <meta name=keywords content="some sample...

What are hsfiles? Why use a “.hsfiles” extension instead of a regular “.hs”?

Reading Yesod's source code, I've encountered files with a ".hsfiles" extension. Example: mongo.hsfiles. What are them, why they were created and why use them?

Post and Get a variable using yesod server

var express = require('express') var app = express() var store = undefined app.post("/", function(req, res){ store = req.body }) app.get("/", function(req, res){ res.send(store) } app.listen(some_port_num) This is a simple nodejs/express server application which stores the http request body in a global variable and sends the same variable as responsse on...

Wildcard character asterisk in route path throws error

A simple yesod server code with a single handler for all GET requests i wrote as: {-# LANGUAGE TypeFamilies, QuasiQuotes, MultiParamTypeClasses, TemplateHaskell, OverloadedStrings #-} import Yesod data Links = Links mkYesod "Links" [parseRoutes| /* HomeR GET |] instance Yesod Links getHomeR = defaultLayout [whamlet|Go to page 1!|] main = warpDebug...