diff options
-rw-r--r-- | app/decorators/controllers/refinery/pages_controller_decorator.rb | 13 | ||||
-rw-r--r-- | app/models/sidebar_blog_category.rb | 12 | ||||
-rw-r--r-- | app/models/sidebar_module.rb | 13 | ||||
-rw-r--r-- | app/views/common/_left_sidebar.html.erb | 2 | ||||
-rw-r--r-- | app/views/common/_right_sidebar.html.erb | 2 | ||||
-rw-r--r-- | app/views/common/_sidebar_module.html.erb | 17 | ||||
-rw-r--r-- | app/views/refinery/sidebar_modules/_sidebar_blog_category.html.erb | 8 |
7 files changed, 42 insertions, 25 deletions
diff --git a/app/decorators/controllers/refinery/pages_controller_decorator.rb b/app/decorators/controllers/refinery/pages_controller_decorator.rb index 034939c..cc30030 100644 --- a/app/decorators/controllers/refinery/pages_controller_decorator.rb +++ b/app/decorators/controllers/refinery/pages_controller_decorator.rb @@ -7,19 +7,10 @@ ApplicationController.class_eval do protected def populate_sidebars - @sidebar_modules = {} + @sidebar_modules = [] Refinery::Blog::Category.all.each do |c| - pos = c.sidebar_position - unless pos == 0 - mod = [] - c.posts.limit(5).each do |post| - mod << SidebarPostDecorator.new(post) - end - - @sidebar_modules[pos] = {} unless @sidebar_modules[pos] - @sidebar_modules[pos][c.title] = mod - end + @sidebar_modules << SidebarBlogCategory.new(c) end end diff --git a/app/models/sidebar_blog_category.rb b/app/models/sidebar_blog_category.rb new file mode 100644 index 0000000..53d15af --- /dev/null +++ b/app/models/sidebar_blog_category.rb @@ -0,0 +1,12 @@ +class SidebarBlogCategory < SidebarModule + def initialize(category) + @title = category.title + @position = category.sidebar_position + @posts = category.posts.recent(5) + end + + def body + @posts + end + +end diff --git a/app/models/sidebar_module.rb b/app/models/sidebar_module.rb new file mode 100644 index 0000000..1e9bde1 --- /dev/null +++ b/app/models/sidebar_module.rb @@ -0,0 +1,13 @@ +class SidebarModule + attr_reader :title, :body, :position + + def initialize(title, body, pos) + @title = title + @body = body + @position = pos + end + + def to_partial_path + "sidebar_modules/#{self.class.to_s.underscore}" + end +end diff --git a/app/views/common/_left_sidebar.html.erb b/app/views/common/_left_sidebar.html.erb index 37f8ccf..1a55f7e 100644 --- a/app/views/common/_left_sidebar.html.erb +++ b/app/views/common/_left_sidebar.html.erb @@ -1,3 +1,3 @@ <div id="left_sidebar"> - <%= render "common/sidebar_module", :modules => @sidebar_modules[1] %> + <%= render @sidebar_modules.select {|m| m.position == 1} %> </div> diff --git a/app/views/common/_right_sidebar.html.erb b/app/views/common/_right_sidebar.html.erb index c9a3ca6..9a40a11 100644 --- a/app/views/common/_right_sidebar.html.erb +++ b/app/views/common/_right_sidebar.html.erb @@ -1,3 +1,3 @@ <div id="right_sidebar"> - <%= render "common/sidebar_module", :modules => @sidebar_modules[2] %> + <%= render @sidebar_modules.select {|m| m.position == 2} %> </div> diff --git a/app/views/common/_sidebar_module.html.erb b/app/views/common/_sidebar_module.html.erb index 07eba16..c7a24e9 100644 --- a/app/views/common/_sidebar_module.html.erb +++ b/app/views/common/_sidebar_module.html.erb @@ -1,12 +1,5 @@ -<% unless modules.nil? %> - <% modules.keys.each do |c| -%> - <div class="sidebar_content"> - <h1><%= c %></h1> - <%- modules[c].each do |item| %> - <h2><%= link_to(item.title, item.friendly_id) %></h2> - <div><%= item.body %></div> - <div><%= link_to(t('read_more'), item.friendly_id) %></div> - <% end %> - </div> - <% end -%> -<% end -%> +<div id="sidebar_module_<%= sidebar_module.title %>" class="sidebar_module"> + <h1><%= sidebar_module.title %></h1> + <div><%= content_for "sidebar_module_#{sidebar_module.title}_body" %></div> +</div> + diff --git a/app/views/refinery/sidebar_modules/_sidebar_blog_category.html.erb b/app/views/refinery/sidebar_modules/_sidebar_blog_category.html.erb new file mode 100644 index 0000000..c1d80f1 --- /dev/null +++ b/app/views/refinery/sidebar_modules/_sidebar_blog_category.html.erb @@ -0,0 +1,8 @@ +<% content_for "sidebar_module_#{sidebar_blog_category.title}_body" do %> + <% sidebar_blog_category.body.each do |post| %> + <%= content_tag :div, :class => :sidebar_blog_headline do %> + <%= link_to post.title, blog_post_path(post) %> + <% end %> + <% end %> +<% end %> +<%= render 'common/sidebar_module', :sidebar_module => sidebar_blog_category %> |