bamboo 2009.6.9 → 2009.6.25
raw patch · 7 files changed
+134/−34 lines, 7 filesdep −cgidep ~hack-contribdep ~hcheatdep ~mps
Dependencies removed: cgi
Dependency ranges changed: hack-contrib, hcheat, mps
Files
- Nemesis +60/−0
- bamboo.cabal +5/−5
- changelog.md +7/−0
- readme.md +52/−18
- src/Bamboo/Controller/Comment.hs +2/−2
- src/Bamboo/Helper/StateHelper.hs +1/−2
- src/Bamboo/Model/Post.hs +7/−7
+ Nemesis view
@@ -0,0 +1,60 @@+-- template nemesis file++import System.Process++nemesis = do+ + clean+ [ "**/*.hi"+ , "**/*.o"+ , "manifest"+ , "**/*.pid"+ , "**/*.sock"+ , "**/*.fcgi"+ , "db/public/*.fcgi"+ , "**/cache"+ , "main"+ , "src/Runner/main"+ ]+ + desc "prepare cabal dist"+ task "dist" $ do+ sh "cabal clean"+ sh "cabal configure"+ sh "cabal sdist"++ desc "start console"+ task "i" (sh "ghci -isrc src/Main.hs")++ desc "put all .hs files in manifest"+ task "manifest" $ sh "find . | grep 'hs$' > manifest"+ + desc "kibro refresh"+ task "r" $ sh "kibro refresh"++ desc "kibro restart"+ task "rs" $ sh "kibro stop; kibro start"++ desc "kibro start"+ task "s" $ sh "kibro start"++ desc "kibro stop"+ task "st" $ sh "kibro stop"+ + desc "kill"+ task "kill" $ do+ kill "fcgi"+ kill "lighttpd"+ return ()+ + desc "run"+ task "run" $ do+ sh "ghc --make -Wall -fno-warn-orphans -isrc src/Main.hs -o main"+ sh "echo $ done"+ sh "./main"+ + desc "show sloc"+ task "stat" $ sh "cloc -match-f=hs$ --quiet ."+ +kill x = + system $ "ps -A | grep " ++ x ++ " | awk '{print $1}' | xargs kill -9"
bamboo.cabal view
@@ -1,5 +1,5 @@ Name: bamboo-Version: 2009.6.9+Version: 2009.6.25 Build-type: Simple Synopsis: A simple blog middleware on hack Description: A simple blog middleware on hack@@ -11,18 +11,18 @@ Cabal-version: >= 1.2 category: Web homepage: http://github.com/nfjinjing/bamboo/tree/master-data-files: readme.md, changelog.md+data-files: readme.md, changelog.md, Nemesis library ghc-options: -Wall -fno-warn-orphans build-depends: - base >= 4 && < 5, cgi, network, mtl, haskell98, old-locale, old-time+ base >= 4 && < 5, network, mtl, haskell98, old-locale, old-time , time, unix, bytestring, base64-string, zlib, directory, filepath , containers, process, parsedate >= 3000.0.0 , xhtml, utf8-string >= 0.3.3, pandoc, parsec >= 2, gravatar >= 0.3 , data-default >= 0.2- , mps >= 2009.5.13, hcheat >= 2009.5.13- , hack >= 2009.5.19, hack-contrib >= 2009.6.9+ , mps >= 2009.6.25, hcheat >= 2009.6.25+ , hack >= 2009.5.19, hack-contrib >= 2009.6.25 hs-source-dirs: src/ exposed-modules: Bamboo
changelog.md view
@@ -1,3 +1,10 @@+2009.6.25+---------++### Fix++* compatible with latest mps+ 2009.6.9 --------
readme.md view
@@ -36,6 +36,10 @@ * SCM for publishing / data managing ( not really a feature, but a design goal from the beginning ) * blindly follows the KISS principle from code to UI: be a simple blog, no more no less +### modular++By it's middleware nature, bamboo could be used with other hack middleware to achieve extensibility; Bamboo plugins are also middleware, so they can be used not only in bamboo, but any other CMS like web application.+ ## Demo ### blog@@ -54,38 +58,68 @@ ## Easy install in 3 steps -### 1. tokyo-cabinet (used for caching)+### 1. update cabal -#### Mac+ cabal update - port install tokyocabinet- -#### Arch+### 2. install bamboo - yaourt -S tokyocabinet+ cabal install happy+ cabal install bamboo-launcher -#### other distro+### 3. run++ mkdir myblog+ cd myblog+ bamboo++## Bird view architecture++ hack-interface :+ 1. bamboo-hack-compatible-layer -- bamboo-controller -- bamboo-theme+ 2. [ bamboo-plugins ]+ 3. [ hack-middleware-stack ]++## Customize++bamboo can be customized in 3 ways:++### Theme++Theme is separated from the bamboo's controller, connected through an interface and a state.++Though theme could be pure, it has the type of -Just find this tokyo-cabinet package and install it :)+ data Interface = + Index+ | IndexFeed+ | Post+ | Static+ | Tag+ | TagFeed+ | Search+ deriving (Show, Eq)+ + type Theme = Interface -> State -> IO Response -### 2. Bamboo Launcher+This makes theme creation an relatively complex task, since a theme author basically has to do everything: from html construction to model manipulation. But since state is passed purely and return type is in IO, it also provides the ultimate safety and flexibility to theme construction, something unmatched by any main stream web frameworks. Integrating twitter? no problem, do them in IO. -#### update cabal+### Plugin - cabal update+Plugin is a proper hack middleware, so it works on an upper layer of the blog engine. It has all the power of a middleware, i.e. intercept request and response, and also the limitation, e.g. no idea of the underlying data structure of the app. -#### install bamboo+Plugin can be used to to do customization on the env object, or transformation to the response body. An example plugin is [syntax highlighting](http://github.com/nfjinjing/bamboo-plugin-highlight), which could be done in the core, but would be more lightweight ( in terms of architecture design ) to be separated into a plugin. - cabal install happy- cabal install bamboo-launcher+You are hence not limited to use just bamboo-plugins to customize your blog, any hack-middleware which suite your need will do. -### 3. Run+### Javascript / CSS - mkdir myblog- cd myblog- bamboo+In `db/config/theme`, you can customize precisely which `js / css` files to use, this allows client side customization and also lightweight configuration without compilation. ## Links * [Hack](http://github.com/nfjinjing/hack) * [Hack Contrib](http://github.com/nfjinjing/hack-contrib)+* [bamboo-theme-blueprint](http://github.com/nfjinjing/bamboo-theme-blueprint)+* [bamboo-launcher](http://github.com/nfjinjing/bamboo-launcher)+* [bamboo-plugin-highlight](http://github.com/nfjinjing/bamboo-plugin-highlight)
src/Bamboo/Controller/Comment.hs view
@@ -6,7 +6,7 @@ import Bamboo.Controller.Env import Hack.Contrib.Response (redirect)-import Network.CGI (urlEncode)+import Hack.Contrib.Utils (unescape_uri) import System.FilePath (equalFilePath, takeDirectory) import qualified Bamboo.Model.Comment as Comment import qualified Bamboo.Model.Post as Post@@ -28,7 +28,7 @@ when ([checked, valid_path, exists].and) $ env.inputs.Comment.create_comment - return $ def.redirect ((uid.Post.id_to_uri.u2b).urlEncode) Nothing+ return $ def.redirect ((uid.Post.id_to_uri.u2b).unescape_uri) Nothing where get_input_data s = env.get_input (s.show_data)
src/Bamboo/Helper/StateHelper.hs view
@@ -8,7 +8,6 @@ import Bamboo.Env hiding (cut) import Hack import Hack.Contrib.Utils-import Network.CGI (urlDecode) import System.Time import System.Locale (defaultTimeLocale) import System.Time.Parse (parseCalendarTime)@@ -16,7 +15,7 @@ import qualified Data.ByteString.Char8 as S uri :: Env -> String-uri = path_info > urlDecode > tail > remove_trailing_slash > b2u+uri = path_info > unescape_uri > tail > remove_trailing_slash > b2u -- global parse_date :: String -> String -> Maybe CalendarTime
src/Bamboo/Model/Post.hs view
@@ -120,23 +120,23 @@ ext = id.take_known_extension uri_to_id :: SC-uri_to_id s = static_config.post_id / (d ++ " " ++ t)+uri_to_id s = static_config.post_id / (date' ++ " " ++ title') where- (raw_d, (_, title_with_sep)) = + (raw_date, (_, title_with_sep)) = s.MPS.match (static_config.url_date_matcher).fromJust.fst - raw_t = + raw_title = title_with_sep .drop (static_config.url_date_title_seperator.length) - t = + title' = static_config .url_title_subs .map (\(a,b) -> gsub b a)- .inject raw_t apply+ .inject raw_title apply - d = - raw_d+ date' = + raw_date .parse_date (static_config.url_date_format) .fromJust .format_time (static_config.post_date_format)