diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2013-12-23 15:33:21 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2013-12-23 15:33:21 +0100 |
commit | 6ca3b3a6abfc9fb508b337d27e683bf8a76400c3 (patch) | |
tree | 4822ad5af4b4aecb72584da1f9ca8ae952857786 | |
parent | a959ac78e251f862251358ee2cf441b66c829ded (diff) | |
download | hmnoweb-6ca3b3a6abfc9fb508b337d27e683bf8a76400c3.tar.gz hmnoweb-6ca3b3a6abfc9fb508b337d27e683bf8a76400c3.tar.bz2 hmnoweb-6ca3b3a6abfc9fb508b337d27e683bf8a76400c3.zip |
Add sidebar_module partial and SidebarPostDecorator class.
Also did some code cleanup in
PagesControllerDecorator::populate_sidebars.
The controller will now populate left and right sidebars (only
left for now,) while the SidebarPostDecorator will provide the
markup for each post that is to be shown in a sidebar.
The plan is to further expand the system with other Sidebar-
Decorators, so each item can be rendered using the same in the
partial.
-rw-r--r-- | app/decorators/controllers/refinery/pages_controller_decorator.rb | 13 | ||||
-rw-r--r-- | app/decorators/models/sidebar_post_decorator.rb | 18 | ||||
-rw-r--r-- | app/views/common/_left_sidebar.html.erb | 9 | ||||
-rw-r--r-- | app/views/common/_sidebar_module.html.erb | 10 |
4 files changed, 38 insertions, 12 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 diff --git a/app/views/common/_left_sidebar.html.erb b/app/views/common/_left_sidebar.html.erb index bf3b3a8..968f1fa 100644 --- a/app/views/common/_left_sidebar.html.erb +++ b/app/views/common/_left_sidebar.html.erb @@ -1,10 +1,3 @@ <div id="left_sidebar"> - <% @sidebar_contents.keys.each do |c| -%> - <div class="sidebar_content"> - <h1><%= c %></h1> - <ul><%- @sidebar_contents[c].each do |p| %> - <li><%= p.title %></li> - <% end %></ul> - </div> - <% end -%> + <%= render "common/sidebar_module", :modules => @sidebar_modules[:left] %> </div> diff --git a/app/views/common/_sidebar_module.html.erb b/app/views/common/_sidebar_module.html.erb new file mode 100644 index 0000000..41f51e7 --- /dev/null +++ b/app/views/common/_sidebar_module.html.erb @@ -0,0 +1,10 @@ + <% modules.keys.each do |c| -%> + <div class="sidebar_content"> + <h1><%= c %></h1> + <%- modules[c].each do |entry| %> + <%= entry.title %> + <%= entry.body %> + <% end %> + </div> + <% end -%> + |