Permalink
Browse files

reorganized files in prep for cabal-ization

  • Loading branch information...
1 parent f85538d commit 384993e27262feeb664ab1b443cb847145f6bbf0 Matt Parker committed Jun 14, 2010
Showing with 150 additions and 132 deletions.
  1. +1 −2 .gitignore
  2. +55 −13 Bird.hs
  3. +0 −19 BirdApp.hs
  4. +30 −0 LICENSE
  5. +0 −25 Main.hs
  6. +27 −18 README.markdown
  7. +2 −0 Setup.hs
  8. +0 −55 bin/bird.hs
  9. +22 −0 bird.cabal
  10. +13 −0 src/Bird.hs
  11. 0 { → src}/Bird/Reply.hs
  12. 0 { → src}/Bird/Reply/Codes.hs
  13. 0 { → src}/Bird/Request.hs
View
@@ -1,5 +1,4 @@
-[Mm]ain
*.hi
*.o
*.swp
-bin/bird
+dist/
View
@@ -1,13 +1,55 @@
-module Bird(
- module Hack,
- module Data.Default,
- module Bird.Reply,
- module Bird.Request,
- module Bird.Reply.Codes
-) where
-
-import Hack
-import Data.Default
-import Bird.Reply
-import Bird.Request
-import Bird.Reply.Codes
+module Main where
+import System.Process
+import System.Environment (getArgs)
+import Directory
+
+main = do
+ args <- getArgs
+ runArg $ head args
+
+runArg a =
+ case a of
+ "build" -> runProcess "ghc" ["--make", "-O2", "Main.hs"] Nothing Nothing Nothing Nothing Nothing >> return ()
+ "run" -> runProcess "./Main" [] Nothing Nothing Nothing Nothing Nothing >> return ()
+ appName -> createBirdApp appName
+
+createBirdApp a = do
+ createDirectory a
+ writeFile (a ++ "/" ++ a ++ ".hs") (routeFile a)
+ writeFile (a ++ "/" ++ "Main.hs") (mainFile a)
+
+routeFile a =
+ "module " ++ a ++ " where\n" ++
+ "import Bird\n\n" ++
+ "get, post, put, delete :: Request -> IO Reply\n" ++
+ "get _ = return notFound_\n" ++
+ "post _ = return notFound_\n" ++
+ "put _ = return notFound_\n" ++
+ "delete _ = return notFound_\n"
+
+mainFile a =
+ "import Hack\n" ++
+ "import Hack.Handler.Hyena\n" ++
+ "import Bird\n" ++
+ "import " ++ a ++ "\n" ++ "\n" ++
+
+ "app :: Application\n" ++
+ "app = \\e -> route e\n" ++ "\n" ++
+
+ "route :: Env -> IO Response\n" ++
+ "route e = response\n" ++
+ " where \n" ++
+ " r = envToRequest e\n" ++
+ " response = do \n" ++
+ " reply <- matchRequest r\n" ++
+ " return $ replyToResponse reply\n" ++ "\n" ++
+
+ "matchRequest r = \n" ++
+ " case verb r of \n" ++
+ " GET -> get r\n" ++
+ " POST -> post r\n" ++
+ " PUT -> put r\n" ++
+ " DELETE -> delete r\n" ++
+ " _ -> error \"not supported\"\n" ++ "\n" ++
+
+ "main = run app\n"
View
@@ -1,19 +0,0 @@
-module BirdApp where
-import Bird
-import qualified Data.Map as Hash
-
-get, post, put, delete :: Request -> IO Reply
-get Request { path = [] } =
- return $ ok_ { replyBody = "Hello World", replyMime = "text/plain" }
-
-get Request { path = ("hello":xs) }
- = ok $ "Hello " ++ (foldr ((++) . (++ " ")) "" xs)
-
-get Request { path = ("echo":w:[]) }
- | length w == 4 = forbidden "We cannot echo 4 letter words."
- | otherwise = ok w
-
-get _ = return notFound_
-post _ = return notFound_
-put _ = return notFound_
-delete _ = return notFound_
View
@@ -0,0 +1,30 @@
+Copyright (c)2010, Matt Parker
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of Matt Parker nor the names of other
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -1,25 +0,0 @@
-import Hack
-import Hack.Handler.Hyena
-import Bird
-import BirdApp
-
-app :: Application
-app = \e -> route e
-
-route :: Env -> IO Response
-route e = response
- where
- r = envToRequest e
- response = do
- reply <- matchRequest r
- return $ replyToResponse reply
-
-matchRequest r =
- case verb r of
- GET -> get r
- POST -> post r
- PUT -> put r
- DELETE -> delete r
- _ -> error "not supported"
-
-main = run app
View
@@ -10,38 +10,47 @@ bells and whistles: lazy evaluation, first-class functions, currying, polymorphi
## Install
- git clone git://github.com/moonmaster9000/bird.git
+ $ cabal update && cabal install bird
-## Compile
+Note: make sure $HOME/.cabal/bin is in your PATH.
- bird# ghc --make -O2 Main.hs
+## Create an app
-## Start the app
+ $ bird MyApp
- bird# ./main &
- bird# curl http://localhost:3000
- Hello, World!
- bird# curl http://localhost:3000/hello/github
- Hello, github!
- bird# curl http://localhost:3000/hi
+## Compile your app
+
+ $ cd MyApp
+ $ bird build
+
+## Start your app (runs on port 3000)
+
+ $ bird run
+
+## Try it out
+
+ $ curl http://localhost:3000
404 Not Found
## Improvise!
- -- BirdApp.hs
- module BirdApp where
+ -- MyApp.hs
+ module MyApp where
import Bird
import Data.String.Utils
- get :: Request -> Reply
-
+ get, post, put, delete :: Request -> IO Reply
get Request { path = ("howdy":xs) }
- = ok { bod = "Howdy " ++ $ join ", " xs}
+ = ok $ ("Howdy " ++) $ join ", " xs
- get _ = notFound
+ get _ = return notFound_
+ post _ = return notFound_
+ put _ = return notFound_
+ delete _ = return notFound_
## Notes
-This project is in it's infancy. Like, it was seriously just born. It's not even close to being feature-complete yet. It's not even sure
-what feature complete means yet. Stay tuned.
+This project is *still* in its infancy. Coming features:
+* logging
+* support for sending files
View
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
View
@@ -1,55 +0,0 @@
-module Main where
-import System.Process
-import System.Environment (getArgs)
-import Directory
-
-main = do
- args <- getArgs
- runArg $ head args
-
-runArg a =
- case a of
- "build" -> runProcess "ghc" ["--make", "-O2", "Main.hs"] Nothing Nothing Nothing Nothing Nothing >> return ()
- "run" -> runProcess "./Main" [] Nothing Nothing Nothing Nothing Nothing >> return ()
- appName -> createBirdApp appName
-
-createBirdApp a = do
- createDirectory a
- writeFile (a ++ "/" ++ a ++ ".hs") (routeFile a)
- writeFile (a ++ "/" ++ "Main.hs") (mainFile a)
-
-routeFile a =
- "module " ++ a ++ " where\n" ++
- "import Bird\n\n" ++
- "get, post, put, delete :: Request -> IO Reply\n" ++
- "get _ = return notFound_\n" ++
- "post _ = return notFound_\n" ++
- "put _ = return notFound_\n" ++
- "delete _ = return notFound_\n"
-
-mainFile a =
- "import Hack\n" ++
- "import Hack.Handler.Hyena\n" ++
- "import Bird\n" ++
- "import " ++ a ++ "\n" ++ "\n" ++
-
- "app :: Application\n" ++
- "app = \\e -> route e\n" ++ "\n" ++
-
- "route :: Env -> IO Response\n" ++
- "route e = response\n" ++
- " where \n" ++
- " r = envToRequest e\n" ++
- " response = do \n" ++
- " reply <- matchRequest r\n" ++
- " return $ replyToResponse reply\n" ++ "\n" ++
-
- "matchRequest r = \n" ++
- " case verb r of \n" ++
- " GET -> get r\n" ++
- " POST -> post r\n" ++
- " PUT -> put r\n" ++
- " DELETE -> delete r\n" ++
- " _ -> error \"not supported\"\n" ++ "\n" ++
-
- "main = run app\n"
View
@@ -0,0 +1,22 @@
+Name: bird
+Version: 0.0.1
+Build-type: Simple
+Synopsis: A simple, sinatra-inspired web framework.
+Description: Bird is a hack-compatible framework for simple websites.
+License: BSD3
+License-file: LICENSE
+Author: Parker, Matt
+Maintainer: Parker, Matt <moonmaster9000@gmail.com>
+Build-Depends: base
+Cabal-version: >= 1.2
+category: Web
+homepage: http://github.com/moonmaster9000/bird
+data-files: readme.markdown
+
+Executable bird
+ main-Is: bird.hs
+
+library
+ build-depends: haskell98, process, containers, bytestring, base >= 4.0 && < 5, hack >= 2009.10.30, hyena, data-default >= 0.2
+ exposed-modules: Bird, Bird.Request, Bird.Reply, Bird.Reply.Codes
+ hs-source-dirs: src/
View
@@ -0,0 +1,13 @@
+module Bird(
+ module Hack,
+ module Data.Default,
+ module Bird.Reply,
+ module Bird.Request,
+ module Bird.Reply.Codes
+) where
+
+import Hack
+import Data.Default
+import Bird.Reply
+import Bird.Request
+import Bird.Reply.Codes
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 384993e

Please sign in to comment.