bird 0.0.13 → 0.0.14
raw patch · 3 files changed
+57/−42 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- bin/bird.hs +30/−17
- bird.cabal +1/−1
- readme.markdown +26/−24
bin/bird.hs view
@@ -6,49 +6,63 @@ main = do args <- getArgs- runArg $ head args+ runArg args -runArg a = - case a of - "nest" -> do+runArg arguments =+ case arguments of+ ["help"] -> printHelp+ ["--help"] -> printHelp+ ["nest"] -> do appModuleNamePath <- getCurrentDirectory- appModuleName <- return $ head . reverse $ split '/' appModuleNamePath + appModuleName <- return $ head . reverse $ split '/' appModuleNamePath partialRouteFile <- readFile $ appModuleName ++ ".bird.hs" writeFile (appModuleName ++ ".hs") ((appModulePrelude appModuleName)++ "\n" ++ partialRouteFile ++ "\n" ++ appModuleEpilogue) system "ghc --make -O2 Main.hs" files <- getDirectoryContents appModuleNamePath- system $ "rm *.o *.hi " ++ appModuleName ++ ".hs" + system $ "rm *.o *.hi " ++ appModuleName ++ ".hs" renameFile "Main" appModuleName return ()- "fly" -> do+ ["fly"] -> do appModuleNamePath <- getCurrentDirectory- appModuleName <- return $ head . reverse $ split '/' appModuleNamePath + appModuleName <- return $ head . reverse $ split '/' appModuleNamePath system $ "./" ++ appModuleName return ()- appName -> createBirdApp appName + ["hatch", appName] -> createBirdApp appName+ (action:_) -> do+ putStrLn $ "Unrecognized action: " ++ (show action) ++ "\n"+ printHelp+ [] -> printHelp -appModulePrelude appModuleName = +printHelp = do+ putStrLn $ "Usage: bird action [options]\n\n" +++ " Actions:\n" +++ " hatch -> create a new Bird app, takes the name as an argument, for example `bird hatch StarWars`\n" +++ " nest -> compile your Bird app\n" +++ " fly -> expose your Bird app to the world (on port 3000)\n"++appModulePrelude appModuleName = "--This file is generated by bird. It will be overwritten the next time you run 'bird nest'. Edit at your own peril.\n" ++ "module " ++ appModuleName ++ " where\n" ++- "import Bird\n\n" + "import Bird\n\n" -appModuleEpilogue = +appModuleEpilogue = "get _ = status 404\n" ++ "post _ = status 404\n" ++ "put _ = status 404\n" ++ "delete _ = status 404\n"- + createBirdApp a = do createDirectory a writeFile (a ++ "/" ++ a ++ ".bird.hs") (routeFile a) writeFile (a ++ "/" ++ "Main.hs") (mainFile a)+ putStrLn $ "A fresh Bird app has been created in " ++ a ++ "." routeFile a = "get [] = body \"Hello, Bird!\"" -mainFile a = +mainFile a = "import Hack\n" ++- "import qualified Hack as Hack\n" ++ + "import qualified Hack as Hack\n" ++ "import Hack.Handler.Happstack\n" ++ "import Bird\n" ++ "import qualified Bird as Bird\n" ++@@ -74,7 +88,7 @@ " Bird.POST -> post $ path r\n" ++ " Bird.PUT -> put $ path r\n" ++ " Bird.DELETE -> delete $ path r\n\n" ++- + "main = run app\n" split :: Char -> String -> [String]@@ -84,4 +98,3 @@ where (t, s'') = break (== d) findSep findSep = dropWhile (== d) s-
bird.cabal view
@@ -1,5 +1,5 @@ Name: bird-Version: 0.0.13+Version: 0.0.14 Build-type: Simple Synopsis: A simple, sinatra-inspired web framework. Description: Bird is a hack-compatible framework for simple websites.
readme.markdown view
@@ -1,11 +1,11 @@ # Bird -A sinatra-ish web framework written in haskell, riding on top of Hack. +A sinatra-ish web framework written in haskell, riding on top of Hack. ## Why? -Sinatra has a beautiful, simple, elegant syntax, but it's essentially an attempt to bring pattern matching to a language never intended for -pattern matching. Why not attempt something similar in a language with not just beautiful pattern matching, but with all the declarative +Sinatra has a beautiful, simple, elegant syntax, but it's essentially an attempt to bring pattern matching to a language never intended for+pattern matching. Why not attempt something similar in a language with not just beautiful pattern matching, but with all the declarative bells and whistles: lazy evaluation, first-class functions, currying, polymorphism? ## Install@@ -16,16 +16,16 @@ ## Create an app - λ bird StarWars + λ bird hatch StarWars ## Compile your app λ cd StarWars λ bird nest - [1 of 2] Compiling MyApp ( MyApp.hs, MyApp.o )- [2 of 2] Compiling Main ( Main.hs, Main.o )+ [1 of 2] Compiling StarWars ( StarWars.hs, StarWars.o )+ [2 of 2] Compiling Main ( Main.hs, Main.o ) Linking Main ...- λ + λ ## Start your app (runs on port 3000)@@ -33,38 +33,36 @@ λ bird fly ## Try it out- + λ curl http://localhost:3000 Hello, Bird!- + λ curl http://localhost:3000?name=Luke Hello, Luke -- ## Improvise!- + -- StarWars.bird.hs import Data.String.Utils (join)- + get ["droids"] = do body "These aren't the droids you're looking for. Move along." status 404 - get ("force":xs) = do + get ("force":xs) = do body $ "May the force be with you " ++ (join ", " xs) ++ "!"- + get [] = do name <- param "name" body $ "Greetings, " ++ (maybe "Jedi!" id name) now recompile your app and start it flying: - λ bird nest - λ bird fly & - + λ bird nest+ λ bird fly &+ λ curl -i http://localhost:3000/force/Han/Chewie- + HTTP/1.1 200 OK Connection: close Content-Type: text/html@@ -74,7 +72,7 @@ May the force be with you Han, Chewie! λ curl -i http://localhost:3000/droids- + HTTP/1.1 404 Not Found Connection: close Content-Type: text/html@@ -86,12 +84,12 @@ ## API -You have four functions to implement: get, post, put, and delete. They each accept a Bird Request. +You have four functions to implement: get, post, put, and delete. They each accept a Bird Request. -Inside the function body, you can use the following methods (don't worry, this list will grow): - +Inside the function body, you can use the following methods (don't worry, this list will grow):+ param :: String -> Maybe String- -- ex: for the request GET /droids?name=c3po, + -- ex: for the request GET /droids?name=c3po, -- then `p <- param "name"' would bind the value `Just "c3po"' to the variable "p" body :: String -> BirdResponder ()@@ -113,4 +111,8 @@ This project is *still* in its infancy. Coming features: * logging+* post/put/delete http param processing+* helpers for popular html generation solutions (Hamlet, HStringTemplate, HAXML, BlazeHTML, etc.)+* WAI support+* static asset serving * support for sending files