packages feed

loli 2009.10.13 → 2010.10.9

raw patch · 6 files changed

+82/−117 lines, 6 filesdep ~templatePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: template

API changes (from Hackage documentation)

Files

Nemesis view
@@ -54,6 +54,6 @@   where     ghci n x = task n - sh - "ghci -isrc src/" ++ x ++ ".hs"     bin n x = task n - do-      sh - "ghc --make -Wall -isrc src/" ++ x ++ ".hs -o .bin/" ++ n+      sh - "ghc --make -Wall -O1 -threaded -isrc src/" ++ x ++ ".hs -o .bin/" ++ n       sh - "echo done.."       sh - ".bin/" ++ n
changelog.md view
@@ -1,3 +1,10 @@+2010.10.9+---------++### Fix++* compile again ...+ 2009.10.13 ---------- 
loli.cabal view
@@ -1,5 +1,5 @@ Name:                 loli-Version:              2009.10.13+Version:              2010.10.9 Build-type:           Simple Synopsis:             A minimum web dev DSL in Haskell Description:@@ -8,17 +8,17 @@  License:              BSD3 License-file:         LICENSE-Author:               Wang, Jinjing-Maintainer:           Wang, Jinjing <nfjinjing@gmail.com>+Author:               Jinjing Wang+Maintainer:           Jinjing Wang <nfjinjing@gmail.com> Build-Depends:        base Cabal-version:        >= 1.2 category:             Web homepage:             http://github.com/nfjinjing/loli-data-files:           readme.md, changelog.md, Nemesis, known-issues.md, src/Test/Test.hs, views/layout.html+data-files:           readme.md, changelog.md, Nemesis, known-issues.md, src/Test/Test.hs, src/Test/Moe.hs, views/layout.html  library   ghc-options: -Wall-  build-depends: base > 4 && <= 5, data-default, hack >= 2009.7.15, hack-contrib >= 2009.8.18, utf8-string, mps >= 2009.9.18, mtl, containers, template, bytestring+  build-depends: base > 4 && <= 5, data-default, hack >= 2009.7.15, hack-contrib >= 2009.8.18, utf8-string, mps >= 2009.9.18, mtl, containers, template < 0.2, bytestring   hs-source-dirs: src/   exposed-modules:                         Network.Loli
readme.md view
@@ -4,44 +4,54 @@  ## Example -First app--    -- myapp.hs-         import Network.Loli     import Hack.Handler.Happstack-    import MPS.Light ((-))-    import Prelude hiding ((-))     -    main = run . loli - get "/" (text "loli power")+    main = run . loli $ get "/" (text "loli power") -Install and compile: +## Installation+     cabal update     cabal install loli     cabal install hack-handler-happstack     +    -- copy and paste the above example to myapp.hs+         ghc --make myapp.hs     ./myapp  check: <http://localhost:3000> +## Quick reference +<http://github.com/nfjinjing/loli/blob/master/src/Test/Test.hs>++ ## Routes  ### Verbs -    get "/" - do-      -- something for a get request+    -- use - instead of $ for clarity+    import MPS.Light ((-))+    import Prelude hiding ((-))+    +    import Network.Loli+    import Hack.Handler.Happstack+    +    main = run . loli - do -    post "/" - do-      -- for a post request+      get "/" - do+        -- something for a get request++      post "/" - do+        -- for a post request     -    put "/" - do-      -- put ..+      put "/" - do+        -- put ..     -    delete "/" - do-      -- ..+      delete "/" - do+        -- ..  ### Captures @@ -57,85 +67,6 @@     -- public serve, only allows `./src`     public (Just ".") ["/src"] -## Views root--    -- in `./views`, can be changed by-    views "template"--## Template--### Text Template--    import Network.Loli.Template.TextTemplate-    -    get "/hi/:user" - output (text_template "hello.html")-    -    -- in hello.html-    <html>-    <title>hello</title>-    <body>-      <p>hello $user</p>-    </body>-    </html>--### Local binding--    get "/local-binding" - do-      bind "user" "alice" - output (text_template "hello.html")--### Batched local bindings--    get "/batched-local-binding" - do-      context [("user", "alice"), ("password", "foo")] - -        text . show =<< locals--## Partials--Partials are treated the same as user supplied bindings, i.e. the rendered text is available to the rest of templates, referenced by user supplied keywords.--### with single partial--    import Network.Loli.Template.ConstTemplate--    get "/single-partial" - do-      partial "user" (const_template "const-user") - do-        text . show =<< template_locals--### with batched partials--    get "/group-partial" - do-      partials -        [ ("user", const_template "alex")-        , ("password", const_template "foo")-        ] - output (text_template "hello.html")--## Layout--### Local--    get "/with-layout" - do-      with_layout "layout.html" - do-        text "layout?"-    -    -- in layout.html-    <html>-    <body>-      <h1>using a layout</h1>-      $content-    </body>-    </html>--### Global--    layout "layout.html"--### By passed--    get "/no-layout" - do-      no_layout - do-        text "no-layout"-- ## Mime types      -- treat .hs extension as text/plain@@ -151,16 +82,12 @@     -- after takes that of type (Response -> IO Response)     after return -## On the fly router switcher--The router can be switched at any time, it will effect any route path that follows.-    -    router loli_router- ## Hack integration  ### Use hack middleware +    -- note both etag and lambda middleware are removed ... for somce ghc 7.0 compatability ><+         import Hack.Contrib.Middleware.ETag     import Hack.Contrib.Middleware.Lambda     @@ -173,14 +100,18 @@          loli :: Unit -> Application -## Note -use the git version ...--## [Wiki](http://wiki.github.com/nfjinjing/loli)--* [Style](http://wiki.github.com/nfjinjing/loli/style)+## Hints +* It's recommended to use your own html combinator / template engine, loli's template system is for completeness rather then usefulness... The author has removed the section on view from this readme. Examples can still be found in `src/Test/Test.hs`. Try DIY with, e.g. [moe](http://github.com/nfjinjing/moe). The template code will stay for, say, a few years, but will eventually fade away.+* [Example view using custom html combinator (moe in this case)](http://github.com/nfjinjing/loli/blob/master/src/Test/Moe.hs)+* When inspecting the request, use `ask` defined in `ReaderT` monad to get the `Hack.Environment`, then use helper method defined in `Hack.Contrib.Request` to query it.+* `Response` is in `StateT`, `html` and `text` are simply helper methods that update the state, i.e. setting the response body, content-type, etc.+* You do need to understand monad transformers to reach the full power of `loli`.+* For mac users, use `GHC 6.12.1` if you have trouble running the server.+     ## Reference  * loli is inspired by [Rack](http://rack.rubyforge.org), [Rails](http://rubyonrails.org), [Ramaze](http://ramaze.net), [Happstack](http://happstack.com/) and [Sinatra](http://www.sinatrarb.com/).++
+ src/Test/Moe.hs view
@@ -0,0 +1,27 @@+import qualified Network.Loli as Loli+import Network.Loli (get, loli)+import Hack.Handler.Happstack+import Text.HTML.Moe2++import Prelude hiding ((/), (-), head, (>), (.), div)+import MPS.Env ((-))+++hello_page :: String+hello_page = render -+  html - do+    head - do+      meta ! [http_equiv "Content-Type", content "text/html; charset-utf-8"] - (/)+      title - str "my title"++    body - do+      div ! [_class "container"] - do+        str "hello world"+        +        +main = do+  putStrLn - "server started..."+  +  run - loli - do+    get "/" - do+      Loli.html - hello_page
src/Test/Test.hs view
@@ -1,7 +1,7 @@-import Control.Monad.Reader+import "mtl" Control.Monad.Reader import Hack.Contrib.Response-import Hack.Handler.SimpleServer--- import Hack.Handler.Happstack+-- import Hack.Handler.SimpleServer+import Hack.Handler.Happstack import Network.Loli import Network.Loli.Engine import Network.Loli.Template.ConstTemplate (const_template)@@ -16,7 +16,7 @@ -- default on port 3000  main :: IO ()-main = run 3000 . loli - do+main = run . loli - do             before return