packages feed

bamboo-2009.6.6: src/Bamboo/Controller/Index.hs

-- the controller is the most complex module for a reason:
-- models are made as simple and small as possible
-- views are pure functions.

-- a note on encoding:
-- uniform utf-8 enforced by custom io wrapper

{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NamedFieldPuns #-}

module Bamboo.Controller.Index where

import Bamboo.Controller.Env
import qualified Bamboo.View.Control.Post as PostV
import qualified Bamboo.View.Widget.RSS as RSSV


index_controller :: Controller
index_controller = do
  init_state
  
  (posts, pager) <- list.io >>= (mapM init_post_meta_data) >>= paged
  
  let nav_location = if pager.current == 1 then home_nav else no_navigation
  
  s <- get
  put s 
    { uid = s.config.post_id
    , pager
    , nav_location
    , posts }
  

index_view :: View
index_view = PostV.list > output_html

index :: Application
index = run index_controller index_view

index_feed_controller :: Controller
index_feed_controller = do
  s <- get
  posts <- list .io ^ take (s.config.number_of_latest_posts)
  put s { posts }

index_feed_view :: View
index_feed_view s = RSSV.rss s "" "" .render_rss .to_sb .output_plain_rss

index_feed :: Application
index_feed = run index_feed_controller index_feed_view