4.5 KiB
<%= blogimage("main.png","Title image") %>
begindiv(intro)
en: <%= tldr %>
fr: <%= tlal %>
enddiv
Here it is. You searched for the best technology to handle your new web application. After searching a lot, you finally found the fastest, most reliable language to make it is Haskell.
It is incredibly fast, can handle extremely well parallel tasks, etc...
You start reading a bit about Haskell and you are ready to do some test. First you see you have three different choices of web framework. As you already know Haskell will be a new language to learn, you start slowly by adopting a framework.
The actual choices are:
It is hard to get a real idea about which you should choose. But if you read a bit, it seems the one which went the farther is yesod. As it has a lot of module for you. The documentation seems good.
Snap and Happstack both seems simpler. The feeling is closer to the language but that means more work to do on your own. Of course, these are just feeling and you have to try it for yourself. Now you are ready to start a Yesod.
Install
First you need to install Haskell. The recommended way to do this is to use the Haskell Platform.
Secondly you need to install yesod.
> cabal update
> cabal install yesod cabal-dev
That is all. It should take some time to do this as cabal will download all package and then compile them.
Initialization
Open a terminal and:
> yesod init
I entered my name, the name of the project was yosog
and the name of the Fondation was Yosog
, then I chosen sqlite
.
Perfect. Now you can start the development cycle:
> cd yosog
> cabal-dev install && yesod --dev devel
This will compile the entire project. In the end you should now be able to see your local website by clicking this link:
Congratulation! You were able to see your yesod powered website. For the rest of the tutorial, use another terminal and let this one open in a corner to see what occurs.
Configure git
It is not mandatory for a tutorial, but it is a good practice to have a CVS.
To use git
copy this .gitignore
file into the yosog
folder.
cabal-dev
dist
.static-cache
static/tmp
*.sqlite3
Then initialize your git repository:
> git init .
> git add .
> git commit -a -m "Initial yesod commit"
Now we are ready to modify our web application.
A last point
What did we done:
- We have a directory containing a bunch of files
- We have a local web server on port 3000
If we modify a file inside this directory, yesod should try to recompile as fast as possible the site. This way, you should see the modification you done.
Instead of explaining the role of every file, let's get straight to the point.
Inside the yosog
the important files/directories for this tutorial are:
config/routes
Handler/
templates/
static/
config/models
Obviously:
config/routes
is where you'll configure the map URL → Code.Handler/
contains the files that will contain the code called when a URL is accessed.templates/
contains HTML, JS and CSS templates.static/
contains static files.config/models
is where you'll configure the persistent objects (database tables).
With these informations we should be able to do a lot. Also note until here we don't even typed any line of Haskell.
Let's really start
What could we start to change?
> curl localhost:3000
- Display something, show it is protected.
- Make the same as before, but with an input.
- Create a minimal blog system.
- Change template to html5 boilerplate.
- Use Authentification.