diff options
Diffstat (limited to 'app/decorators')
-rw-r--r-- | app/decorators/controllers/refinery/pages_controller_decorator.rb | 13 | ||||
-rw-r--r-- | app/decorators/models/sidebar_post_decorator.rb | 18 |
2 files changed, 27 insertions, 4 deletions
diff --git a/app/decorators/controllers/refinery/pages_controller_decorator.rb b/app/decorators/controllers/refinery/pages_controller_decorator.rb index d86fe39..d49e194 100644 --- a/app/decorators/controllers/refinery/pages_controller_decorator.rb +++ b/app/decorators/controllers/refinery/pages_controller_decorator.rb @@ -5,10 +5,15 @@ ApplicationController.class_eval do protected def populate_sidebars - categories = Refinery::Blog::Category.all - @sidebar_contents = {} - categories.each do |c| - @sidebar_contents[c.title] = c.posts.limit(10) + @sidebar_modules = {:left => {}, :right => {}} + + Refinery::Blog::Category.all.each do |c| + mod = [] + c.posts.limit(5).each do |post| + mod << SidebarPostDecorator.new(post) + end + + @sidebar_modules[:left][c.title] = mod end end end diff --git a/app/decorators/models/sidebar_post_decorator.rb b/app/decorators/models/sidebar_post_decorator.rb new file mode 100644 index 0000000..14cbe7c --- /dev/null +++ b/app/decorators/models/sidebar_post_decorator.rb @@ -0,0 +1,18 @@ +require 'delegate' + +class SidebarPostDecorator < SimpleDelegator + include ActionView::Helpers::TagHelper + include ActionView::Helpers::TextHelper + + def initialize(post) + super(post) + end + + def title + content_tag(:h2, super) + end + + def body + content_tag(:div, sanitize(truncate(super, :length => 32, :separator => ' '))) + end +end |