RSS

Yesod でアプリを作る 2

ここではscaffoldをつかってプロジェクトを作成する。名前は自分の名前を入れてプロジェクト名はblogとする。データベースにはsqliteを使う。

$ yesod init 
Welcome to the Yesod scaffolder.
I'm going to be creating a skeleton Yesod project for you.

What is your name? We're going to put this in the cabal and LICENSE files.

Your name: takaki
Welcome takaki.
What do you want to call your project? We'll use this for the cabal name.

Project name: blog
Yesod uses Persistent for its (you guessed it) persistence layer.
This tool will build in either SQLite or PostgreSQL or MongoDB support for you.
We recommend starting with SQLite: it has no dependencies.

    s     = sqlite
    p     = postgresql
    mongo = mongodb
    mysql = MySQL (experimental)

So, what'll it be? s
That's it! I'm creating your files now...
Generating deploy/Procfile
Generating config/sqlite.yml
Generating config/settings.yml
Generating main.hs
Generating devel.hs
Generating blog.cabal
Generating .ghci
Generating LICENSE
Generating Foundation.hs
Generating Import.hs
Generating Application.hs
Generating Handler/Home.hs
Generating Model.hs
Generating Settings.hs
Generating Settings/StaticFiles.hs
Generating Settings/Development.hs
Generating static/css/bootstrap.css
Generating templates/default-layout.hamlet
Generating templates/default-layout-wrapper.hamlet
Generating templates/normalize.lucius
Generating templates/homepage.hamlet
Generating config/routes
Generating templates/homepage.lucius
Generating templates/homepage.julius
Generating config/models
Generating messages/en.msg
Generating tests/main.hs
Generating tests/HomeTest.hs

---------------------------------------

                     ___
                            {-)   |\
                       [m,].-"-.   /
      [][__][__]         \(/\__/\)/
      [__][__][__][__]  |  |
      [][__][__][__][__][] /   |
      [__][__][__][__][__]| /| |
      [][__][__][__][__][]| || |  
  ejm [__][__][__][__][__]__,__,  \__/


---------------------------------------

The foundation for your web application has been built.


There are a lot of resources to help you use Yesod.
Start with the book: http://www.yesodweb.com/book
Take part in the community: http://yesodweb.com/page/community


Start your project:

   cd blog && cabal install && yesod devel

or if you use cabal-dev:

   cd blog && cabal-dev install && yesod --dev devel

と実行する。そして次のように実行する。

$ cd blog && cabal install && yesod devel
Resolving dependencies...
Configuring blog-0.0.0...
Building blog-0.0.0...
Preprocessing library blog-0.0.0...
[1 of 8] Compiling Settings.Development ( Settings/Development.hs, dist/build/Settings/Development.o )
[2 of 8] Compiling Model            ( Model.hs, dist/build/Model.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package HUnit-1.2.4.2 ... linking ... done.
Loading package array-0.4.0.0 ... linking ... done.
Loading package bytestring-0.9.2.1 ... linking ... done.
Loading package deepseq-1.3.0.0 ... linking ... done.
Loading package containers-0.4.2.1 ... linking ... done.
Loading package text-0.11.2.0 ... linking ... done.
Loading package attoparsec-0.10.1.1 ... linking ... done.
Loading package blaze-builder-0.3.1.0 ... linking ... done.
Loading package blaze-html-0.4.3.1 ... linking ... done.
Loading package hashable-1.1.2.3 ... linking ... done.
Loading package case-insensitive-0.4.0.1 ... linking ... done.
Loading package extensible-exceptions-0.1.1.4 ... linking ... done.
Loading package old-locale-1.0.0.4 ... linking ... done.
Loading package time-1.4 ... linking ... done.
Loading package random-1.0.1.1 ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package QuickCheck-2.4.2 ... linking ... done.
Loading package unix-2.5.1.0 ... linking ... done.
Loading package ansi-terminal-0.5.5 ... linking ... done.
Loading package filepath-1.3.0.0 ... linking ... done.
Loading package old-time-1.1.0.0 ... linking ... done.
Loading package directory-1.1.0.2 ... linking ... done.
Loading package process-1.1.0.1 ... linking ... done.
Loading package Cabal-1.14.0 ... linking ... done.
Loading package binary-0.5.1.0 ... linking ... done.
Loading package bin-package-db-0.0.0.0 ... linking ... done.
Loading package hoopl-3.8.7.3 ... linking ... done.
Loading package hpc-0.5.1.1 ... linking ... done.
Loading package ghc-7.4.1 ... linking ... done.
Loading package silently-1.1.4 ... linking ... done.
Loading package transformers-0.3.0.0 ... linking ... done.
Loading package hspec-1.1.0 ... linking ... done.
Loading package base-unicode-symbols-0.2.2.3 ... linking ... done.
Loading package transformers-base-0.4.1 ... linking ... done.
Loading package monad-control-0.3.1.3 ... linking ... done.
Loading package lifted-base-0.1.1 ... linking ... done.
Loading package resourcet-0.3.2.1 ... linking ... done.
Loading package semigroups-0.8.3.2 ... linking ... done.
Loading package void-0.5.5.1 ... linking ... done.
Loading package conduit-0.4.2 ... linking ... done.
Loading package system-filepath-0.4.6 ... linking ... done.
Loading package system-fileio-0.3.8 ... linking ... done.
Loading package filesystem-conduit-0.4.0 ... linking ... done.
Loading package blaze-builder-conduit-0.4.0.2 ... linking ... done.
Loading package tagstream-conduit-0.3.2 ... linking ... done.
Loading package attoparsec-conduit-0.4.0.1 ... linking ... done.
Loading package dlist-0.5 ... linking ... done.
Loading package data-default-0.4.0 ... linking ... done.
Loading package failure-0.2.0.1 ... linking ... done.
Loading package xml-types-0.3.1 ... linking ... done.
Loading package xml-conduit-0.7.0.2 ... linking ... done.
Loading package html-conduit-0.0.1 ... linking ... done.
Loading package http-types-0.6.11 ... linking ... done.
Loading package hxt-charproperties-9.1.1 ... linking ... done.
Loading package mtl-2.1.1 ... linking ... done.
Loading package parsec-3.1.2 ... linking ... done.
Loading package hxt-regex-xmlschema-9.0.4 ... linking ... done.
Loading package hxt-unicode-9.0.2 ... linking ... done.
Loading package network-2.3.0.13 ... linking ... done.
Loading package hxt-9.2.2 ... linking ... done.
Loading package syb-0.3.6.1 ... linking ... done.
Loading package unordered-containers-0.2.1.0 ... linking ... done.
Loading package primitive-0.4.1 ... linking ... done.
Loading package vector-0.9.1 ... linking ... done.
Loading package aeson-0.6.0.2 ... linking ... done.
Loading package base64-bytestring-0.1.1.1 ... linking ... done.
Loading package path-pieces-0.1.0 ... linking ... done.
Loading package stm-2.3 ... linking ... done.
Loading package resource-pool-0.2.1.0 ... linking ... done.
Loading package pool-conduit-0.1.0.2 ... linking ... done.
Loading package persistent-0.9.0.4 ... linking ... done.
Loading package vault-0.2.0.0 ... linking ... done.
Loading package wai-1.2.0.2 ... linking ... done.
Loading package cookie-0.4.0 ... linking ... done.
Loading package wai-test-1.2.0.2 ... linking ... done.
Loading package xml2html-0.1.2.3 ... linking ... done.
Loading package yesod-test-0.2.0.6 ... linking ... done.
Loading package cereal-0.3.5.2 ... linking ... done.
Loading package entropy-0.2.1 ... linking ... done.
Loading package largeword-1.0.1 ... linking ... done.
Loading package tagged-0.4.2.1 ... linking ... done.
Loading package crypto-api-0.10.2 ... linking ... done.
Loading package crypto-conduit-0.3.2 ... linking ... done.
Loading package cryptohash-0.7.5 ... linking ... done.
Loading package file-embed-0.0.4.4 ... linking ... done.
Loading package unix-compat-0.3.0.1 ... linking ... done.
Loading package http-date-0.0.2 ... linking ... done.
Loading package wai-app-static-1.2.0.3 ... linking ... done.
Loading package cpu-0.1.1 ... linking ... done.
Loading package crypto-pubkey-types-0.1.1 ... linking ... done.
Loading package cryptocipher-0.3.5 ... linking ... done.
Loading package cprng-aes-0.2.3 ... linking ... done.
Loading package skein-0.1.0.7 ... linking ... done.
Loading package clientsession-0.7.5 ... linking ... done.
Loading package fast-logger-0.0.2 ... linking ... done.
Loading package shakespeare-1.0.0.2 ... linking ... done.
Loading package hamlet-1.0.1.3 ... linking ... done.
Loading package shakespeare-css-1.0.1.2 ... linking ... done.
Loading package shakespeare-i18n-1.0.0.2 ... linking ... done.
Loading package shakespeare-js-1.0.0.2 ... linking ... done.
Loading package zlib-0.5.3.3 ... linking ... done.
Loading package zlib-bindings-0.1.0.1 ... linking ... done.
Loading package zlib-conduit-0.4.0.1 ... linking ... done.
Loading package wai-extra-1.2.0.4 ... linking ... done.
Loading package byteorder-1.0.3 ... linking ... done.
Loading package wai-logger-0.1.4 ... linking ... done.
Loading package yesod-routes-1.0.1.2 ... linking ... done.
Loading package yesod-core-1.0.1.2 ... linking ... done.
Loading package yesod-static-1.0.0.2 ... linking ... done.
Loading package network-conduit-0.4.0.1 ... linking ... done.
Loading package simple-sendfile-0.2.3 ... linking ... done.
Loading package warp-1.2.1.1 ... linking ... done.
Loading package yaml-0.7.0.2 ... linking ... done.
Loading package yesod-default-1.0.1.1 ... linking ... done.
Loading package shakespeare-text-1.0.0.2 ... linking ... done.
Loading package SHA-1.5.0.1 ... linking ... done.
Loading package enumerator-0.4.19 ... linking ... done.
Loading package attoparsec-enumerator-0.3 ... linking ... done.
Loading package asn1-data-0.6.1.3 ... linking ... done.
Loading package pem-0.1.1 ... linking ... done.
Loading package certificate-1.2.3 ... linking ... done.
Loading package regex-base-0.93.2 ... linking ... done.
Loading package regex-posix-0.95.1 ... linking ... done.
Loading package regex-compat-0.95.1 ... linking ... done.
Loading package socks-0.4.1 ... linking ... done.
Loading package tls-0.9.5 ... linking ... done.
Loading package tls-extra-0.4.6 ... linking ... done.
Loading package utf8-string-0.3.7 ... linking ... done.
Loading package http-conduit-1.4.1.6 ... linking ... done.
Loading package tagsoup-0.12.6 ... linking ... done.
Loading package authenticate-1.2.1.1 ... linking ... done.
Loading package mime-mail-0.4.1.1 ... linking ... done.
Loading package persistent-template-0.9.0.2 ... linking ... done.
Loading package pureMD5-2.1.0.3 ... linking ... done.
Loading package pwstore-fast-2.2 ... linking ... done.
Loading package ranges-0.2.4 ... linking ... done.
Loading package email-validate-0.2.8 ... linking ... done.
Loading package css-text-0.1.1 ... linking ... done.
Loading package xss-sanitize-0.3.2 ... linking ... done.
Loading package yesod-persistent-1.0.0.1 ... linking ... done.
Loading package yesod-form-1.0.0.4 ... linking ... done.
Loading package safe-0.3.3 ... linking ... done.
Loading package yesod-json-1.0.0.1 ... linking ... done.
Loading package yesod-auth-1.0.2.1 ... linking ... done.
Loading package yesod-1.0.1.6 ... linking ... done.
Loading package persistent-sqlite-0.9.0.2 ... linking ... done.
Loading package utf8-light-0.4.0.1 ... linking ... done.
Loading package language-javascript-0.5.4 ... linking ... done.
Loading package hjsmin-0.1.1 ... linking ... done.
[3 of 8] Compiling Settings         ( Settings.hs, dist/build/Settings.o )
[4 of 8] Compiling Settings.StaticFiles ( Settings/StaticFiles.hs, dist/build/Settings/StaticFiles.o )
[5 of 8] Compiling Foundation       ( Foundation.hs, dist/build/Foundation.o )
[6 of 8] Compiling Import           ( Import.hs, dist/build/Import.o )
[7 of 8] Compiling Handler.Home     ( Handler/Home.hs, dist/build/Handler/Home.o )
[8 of 8] Compiling Application      ( Application.hs, dist/build/Application.o )
Registering blog-0.0.0...
Preprocessing executable 'blog' for blog-0.0.0...
[1 of 1] Compiling Main             ( dist/../main.hs, dist/build/blog/blog-tmp/Main.o )
Linking dist/build/blog/blog ...
Installing library in /home/takaki/.cabal/lib/blog-0.0.0/ghc-7.4.1
Installing executable(s) in /home/takaki/.cabal/bin
Registering blog-0.0.0...
Yesod devel server. Press ENTER to quit
Resolving dependencies...
Configuring blog-0.0.0...
Rebuilding application...
Building blog-0.0.0...
Preprocessing library blog-0.0.0...
[1 of 8] Compiling Settings.Development ( Settings/Development.hs, dist/build/Settings/Development.o )
[2 of 8] Compiling Model            ( Model.hs, dist/build/Model.o )
[3 of 8] Compiling Settings         ( Settings.hs, dist/build/Settings.o )
[4 of 8] Compiling Settings.StaticFiles ( Settings/StaticFiles.hs, dist/build/Settings/StaticFiles.o )
[5 of 8] Compiling Foundation       ( Foundation.hs, dist/build/Foundation.o )
[6 of 8] Compiling Import           ( Import.hs, dist/build/Import.o )
[7 of 8] Compiling Handler.Home     ( Handler/Home.hs, dist/build/Handler/Home.o )
[8 of 8] Compiling Application      ( Application.hs, dist/build/Application.o )
Registering blog-0.0.0...
Starting development server: runghc -package-confdist/package.conf.inplace devel.hs
Starting devel application
Devel application launched: http://localhost:3000
Migrating: CREATE TABLE "user"("id" INTEGER PRIMARY KEY,"ident" VARCHAR NOT NULL,"password" VARCHAR NULL,CONSTRAINT "unique_user" UNIQUE ("ident"))
Migrating: CREATE TABLE "email"("id" INTEGER PRIMARY KEY,"email" VARCHAR NOT NULL,"user" INTEGER NULL REFERENCES "user","verkey" VARCHAR NULL,CONSTRAINT "unique_email" UNIQUE ("email"))

ここまで実行して http://localhost:3000/ にアクセスすると yesod の初期のトップページが表示される