Navigation Menu

Skip to content

Commit

Permalink
Move ControllerHelper functionality to BlogController
Browse files Browse the repository at this point in the history
This both removes the need to even have the controller helper,
and makes more sense in terms of where it should live.

Now everything that inherits from BlogController can act like a
Blog Controller!
  • Loading branch information
parndt committed Nov 26, 2016
1 parent 3cbf658 commit 2434ae2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 62 deletions.
32 changes: 29 additions & 3 deletions app/controllers/refinery/blog/blog_controller.rb
Expand Up @@ -2,16 +2,42 @@ module Refinery
module Blog
class BlogController < ::ApplicationController

include ControllerHelper

helper :'refinery/blog/posts'
before_filter :find_page, :find_all_blog_categories
before_action :find_page, :find_all_blog_categories

protected

def find_all_blog_categories
@categories = Refinery::Blog::Category.translated
end

def find_blog_post
unless (@post = post_finder_scope.with_globalize.friendly.find(params[:id])).try(:live?)
if current_refinery_user && current_refinery_user.has_plugin?("refinerycms_blog")
@post = post_finder_scope.friendly.find(params[:id])
else
error_404
end
end
end

def find_all_blog_posts
@posts = post_finder_scope.live.includes(
:comments, :categories, :translations
).with_globalize.newest_first.page(params[:page])
end

def find_page
@page = Refinery::Page.find_by(:link_url => Refinery::Blog.page_url)
end

def find_tags
@tags = post_finder_scope.live.tag_counts_on(:tags)
end

def post_finder_scope
Refinery::Blog::Post
end
end
end
end
30 changes: 1 addition & 29 deletions app/helpers/refinery/blog/controller_helper.rb
Expand Up @@ -2,35 +2,7 @@ module Refinery
module Blog
module ControllerHelper

protected

def find_blog_post
unless (@post = Refinery::Blog::Post.with_globalize.friendly.find(params[:id])).try(:live?)
if current_refinery_user && current_refinery_user.has_plugin?("refinerycms_blog")
@post = Refinery::Blog::Post.friendly.find(params[:id])
else
error_404
end
end
end

def find_all_blog_posts
@posts = post_finder_scope.live.includes(
:comments, :categories, :translations
).with_globalize.newest_first.page(params[:page])
end

def find_tags
@tags = Refinery::Blog::Post.live.tag_counts_on(:tags)
end

def find_all_blog_categories
@categories = Refinery::Blog::Category.translated
end

def post_finder_scope
Refinery::Blog::Post
end

end
end
end
6 changes: 3 additions & 3 deletions app/views/refinery/blog/shared/_categories.html.erb
@@ -1,10 +1,10 @@
<% if @categories.any? %>
<h2><%= t('.title') %></h2>
<ul id='categories'>
<ul id="categories">
<% @categories.each do |category| %>
<li<%= " class='selected'" if @category.present? and @category.id == category.id %>>
<li<%= " class='selected'" if @category.present? && @category.id == category.id %>>
<%= link_to "#{category.title} (#{category.post_count})", refinery.blog_category_path(category) %>
</li>
<% end %>
</ul>
<% end %>
<% end %>
27 changes: 0 additions & 27 deletions spec/helpers/refinery/blog/controller_helper_spec.rb

This file was deleted.

0 comments on commit 2434ae2

Please sign in to comment.