refactoring the frontend to use more partials, separate out the categories into it's own controller, namespace the blog into it's own folder and create a base blog controller for handling common front end tasks
This commit is contained in:
parent
6f342c1314
commit
bd50bdb415
17 changed files with 175 additions and 136 deletions
7
app/controllers/blog/categories_controller.rb
Normal file
7
app/controllers/blog/categories_controller.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
class Blog::CategoriesController < BlogController
|
||||||
|
|
||||||
|
def show
|
||||||
|
@category = BlogCategory.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -1,15 +1,8 @@
|
||||||
class BlogPostsController < ApplicationController
|
class Blog::PostsController < BlogController
|
||||||
|
|
||||||
before_filter :find_all_blog_posts, :find_all_blog_categories
|
before_filter :find_all_blog_posts
|
||||||
before_filter :find_page
|
|
||||||
before_filter :find_blog_post, :only => [:show, :comment]
|
before_filter :find_blog_post, :only => [:show, :comment]
|
||||||
|
|
||||||
def index
|
|
||||||
# you can use meta fields from your model instead (e.g. browser_title)
|
|
||||||
# by swapping @page for @blogs in the line below:
|
|
||||||
present(@page)
|
|
||||||
end
|
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@blog_comment = BlogComment.new
|
@blog_comment = BlogComment.new
|
||||||
|
|
||||||
|
@ -40,23 +33,7 @@ protected
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_all_blog_posts
|
def find_all_blog_posts
|
||||||
unless params[:category_id].present?
|
@blog_posts = BlogPost.live
|
||||||
@blog_posts = BlogPost.live
|
|
||||||
else
|
|
||||||
if (category = BlogCategory.find(params[:category_id])).present?
|
|
||||||
@blog_posts = category.posts
|
|
||||||
else
|
|
||||||
error_404
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_all_blog_categories
|
|
||||||
@blog_categories = BlogCategory.all
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_page
|
|
||||||
@page = Page.find_by_link_url("/blog")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
15
app/controllers/blog_controller.rb
Normal file
15
app/controllers/blog_controller.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
class BlogController < ApplicationController
|
||||||
|
|
||||||
|
before_filter :find_page, :find_all_blog_categories
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def find_page
|
||||||
|
@page = Page.find_by_link_url("/blog")
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_all_blog_categories
|
||||||
|
@blog_categories = BlogCategory.all
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -60,6 +60,4 @@
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% content_for :head do %>
|
<% content_for :head, stylesheet_link_tag('refinery/refinerycms-blog') %>
|
||||||
<%= stylesheet_link_tag 'refinery/refinerycms-blog' %>
|
|
||||||
<% end %>
|
|
20
app/views/blog/categories/show.html.erb
Normal file
20
app/views/blog/categories/show.html.erb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<% content_for :body_content_title, @category.title %>
|
||||||
|
|
||||||
|
<% content_for :body_content_left do %>
|
||||||
|
<% if @category.posts.any? %>
|
||||||
|
<ul id="blog_posts">
|
||||||
|
<%= render :partial => "/blog/shared/post", :collection => @category.posts %>
|
||||||
|
</ul>
|
||||||
|
<% else %>
|
||||||
|
<p>
|
||||||
|
<%= t('.no_posts') %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% content_for :body_content_right do %>
|
||||||
|
<%= render :partial => "/blog/shared/categories" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= render :partial => "/shared/content_page" %>
|
||||||
|
<% content_for :head, stylesheet_link_tag('refinerycms-blog') %>
|
9
app/views/blog/posts/_comment.html.erb
Normal file
9
app/views/blog/posts/_comment.html.erb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<div class='blog_comment_message' id='<%= "comment-#{comment.to_param}" %>'>
|
||||||
|
<p>
|
||||||
|
<%= comment.message.to_s.gsub("\r\n\r\n", "</p><p>").gsub("\r\n", "<br/>") %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<p class='blog_comment_author'>
|
||||||
|
<%= t('.by', :who => comment.name) %>
|
||||||
|
<%= t('.time_ago', :time => time_ago_in_words(comment.created_at)) %>
|
||||||
|
</p>
|
16
app/views/blog/posts/index.html.erb
Normal file
16
app/views/blog/posts/index.html.erb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<% content_for :body_content_left do %>
|
||||||
|
<%= @page[Page.default_parts.first.to_sym] %>
|
||||||
|
|
||||||
|
<ul id="blog_posts">
|
||||||
|
<%= render :partial => "/blog/shared/post", :collection => @blog_posts %>
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% content_for :body_content_right do %>
|
||||||
|
<%= @page[Page.default_parts.second.to_sym] %>
|
||||||
|
|
||||||
|
<%= render :partial => "/blog/shared/categories" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= render :partial => "/shared/content_page" %>
|
||||||
|
<% content_for :head, stylesheet_link_tag('refinerycms-blog') %>
|
|
@ -1,46 +1,38 @@
|
||||||
<% content_for :body_content_title, @blog_post.title %>
|
<% content_for :body_content_title, @blog_post.title %>
|
||||||
|
|
||||||
<% content_for :body_content_left do %>
|
<% content_for :body_content_left do %>
|
||||||
<%= t('.created_at', :when => @blog_post.created_at.strftime('%d %B %Y')) %>
|
<p class='posted_at'>
|
||||||
<%= @blog_post.body %>
|
<%= t('blog.shared.posts.created_at', :when => @blog_post.created_at.strftime('%d %B %Y')) %>.
|
||||||
|
|
||||||
<% if (categories = @blog_post.categories).any? %>
|
<% if (categories = @blog_post.categories).any? %>
|
||||||
<hr />
|
<span class='filed_in'>
|
||||||
<div class='post_categories'>
|
<%= t('.filed_in') %>
|
||||||
<span class='filed_in'><%= t('.filed_in') %></span>
|
|
||||||
<ul>
|
|
||||||
<% categories.each_with_index do |category, index| %>
|
<% categories.each_with_index do |category, index| %>
|
||||||
<li>
|
|
||||||
<%= link_to category.title, blog_category_url(category) -%><%= ',' if index < ((categories.length) - 1) %>
|
<%= link_to category.title, blog_category_url(category) -%><%= ',' if index < ((categories.length) - 1) %>
|
||||||
</li>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</span>
|
||||||
</div>
|
<% end %>
|
||||||
<% end %>
|
</p>
|
||||||
|
<%= @blog_post.body %>
|
||||||
<% if (comments = @blog_post.comments.approved).any? %>
|
|
||||||
<hr />
|
<% if BlogPost.comments_allowed? %>
|
||||||
<h2><%= t('.comments.title') %></h2>
|
<h2><%= t('.comments.title') %></h2>
|
||||||
<% comments.each do |comment| %>
|
|
||||||
<div class='blog_comment_message' id='<%= "comment-#{comment.to_param}" %>'>
|
<% if (comments = @blog_post.comments.approved).any? %>
|
||||||
<p>
|
<%= render :partial => "comment", :collection => comments %>
|
||||||
<%= comment.message.to_s.gsub("\r\n\r\n", "</p><p>").gsub("\r\n", "<br/>") %>
|
<% else %>
|
||||||
</p>
|
<p>
|
||||||
</div>
|
<%= t('blog.shared.comments.none') %>.
|
||||||
<p class='blog_comment_author'>
|
|
||||||
<%= t('.comments.by', :who => comment.name) %>
|
|
||||||
<%= t('.comments.time_ago', :time => time_ago_in_words(comment.created_at)) %>
|
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if BlogPost.comments_allowed? %>
|
|
||||||
<hr />
|
|
||||||
<% flash.each do |key, value| %>
|
<% flash.each do |key, value| %>
|
||||||
<div id='flash' class="flash flash_<%= key %>">
|
<div id='flash' class="flash flash_<%= key %>">
|
||||||
<%= value %>
|
<%= value %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<h2><%= t('.comments.add') %></h2>
|
||||||
<% form_for [:blog_post, @blog_comment] do |f| %>
|
<% form_for [:blog_post, @blog_comment] do |f| %>
|
||||||
<% if Rails.version < '3.0.0'%>
|
<% if Rails.version < '3.0.0'%>
|
||||||
<%= f.error_messages %>
|
<%= f.error_messages %>
|
||||||
|
@ -71,19 +63,9 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% content_for :body_content_right do %>
|
<% content_for :body_content_right do %>
|
||||||
<%= render :partial => "side_bar" %>
|
<%= render :partial => "/blog/shared/categories" %>
|
||||||
|
<%= render :partial => "/blog/shared/posts" %>
|
||||||
<h2><%= t('.other') %></h2>
|
|
||||||
<ul id="blog_posts">
|
|
||||||
<% @blog_posts.each do |blog_post| %>
|
|
||||||
<li>
|
|
||||||
<%= link_to blog_post.title, blog_post_url(blog_post) %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
</ul>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= render :partial => "/shared/content_page" %>
|
<%= render :partial => "/shared/content_page" %>
|
||||||
<% content_for :head do %>
|
<% content_for :head, stylesheet_link_tag('refinerycms-blog') %>
|
||||||
<%= stylesheet_link_tag 'refinerycms-blog' %>
|
|
||||||
<% end %>
|
|
8
app/views/blog/shared/_categories.html.erb
Normal file
8
app/views/blog/shared/_categories.html.erb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<h2><%= t('.title') %></h2>
|
||||||
|
<ul id='categories'>
|
||||||
|
<% @blog_categories.each do |category| %>
|
||||||
|
<li<%= " class='selected'" if @category.present? and @category.id == category.id %>>
|
||||||
|
<%= link_to "#{category.title} (#{category.posts.count})", blog_category_url(category) %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
20
app/views/blog/shared/_post.html.erb
Normal file
20
app/views/blog/shared/_post.html.erb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<li>
|
||||||
|
<h2><%= link_to post.title, blog_post_url(post) %></h2>
|
||||||
|
<p class='posted_at'>
|
||||||
|
<%= t('blog.shared.posts.created_at', :when => post.created_at.strftime('%d %B %Y')) %>
|
||||||
|
</p>
|
||||||
|
<%= truncate(post.body,
|
||||||
|
:length => RefinerySetting.find_or_set(:blog_post_teaser_length, 250),
|
||||||
|
:preserve_html_tags => true) %>
|
||||||
|
<p>
|
||||||
|
<%= link_to t('blog.shared.posts.read_more'), blog_post_url(post) %>
|
||||||
|
|
||||||
|
<span class='comment_count'>
|
||||||
|
<% if post.comments.any? %>
|
||||||
|
(<%= pluralize(post.comments.count, t('blog.shared.comments.singular')) %>)
|
||||||
|
<% else %>
|
||||||
|
(<%= t('blog.shared.comments.none') %>)
|
||||||
|
<% end %>
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
</li>
|
8
app/views/blog/shared/_posts.html.erb
Normal file
8
app/views/blog/shared/_posts.html.erb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<h2><%= t('.other') %></h2>
|
||||||
|
<ul id="blog_posts">
|
||||||
|
<% @blog_posts.each do |blog_post| %>
|
||||||
|
<li>
|
||||||
|
<%= link_to blog_post.title, blog_post_url(blog_post) %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
|
@ -1,8 +0,0 @@
|
||||||
<h2><%= t('.categories') %></h2>
|
|
||||||
<ul id='categories'>
|
|
||||||
<% @blog_categories.each do |category| %>
|
|
||||||
<li>
|
|
||||||
<%= link_to category.title, blog_category_url(category) %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
</ul>
|
|
|
@ -1,27 +0,0 @@
|
||||||
<% content_for :body_content_left do %>
|
|
||||||
<%= @page[Page.default_parts.first.to_sym] %>
|
|
||||||
|
|
||||||
<ul id="blog_posts">
|
|
||||||
<% @blog_posts.each do |blog_post| %>
|
|
||||||
<li>
|
|
||||||
<h2><%= link_to blog_post.title, blog_post_url(blog_post) %></h2>
|
|
||||||
<%= t('.created_at', :when => blog_post.created_at.strftime('%d %B %Y')) %>
|
|
||||||
<%= truncate(blog_post.body,
|
|
||||||
:length => RefinerySetting.find_or_set(:blog_post_teaser_length, 250),
|
|
||||||
:preserve_html_tags => true) %>
|
|
||||||
<%= link_to t('.read_more'), blog_post_url(blog_post) %>
|
|
||||||
</li>
|
|
||||||
<% end %>
|
|
||||||
</ul>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% content_for :body_content_right do %>
|
|
||||||
<%= @page[Page.default_parts.second.to_sym] %>
|
|
||||||
|
|
||||||
<%= render :partial => "side_bar" %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= render :partial => "/shared/content_page" %>
|
|
||||||
<% content_for :head do %>
|
|
||||||
<%= stylesheet_link_tag 'refinerycms-blog' %>
|
|
||||||
<% end %>
|
|
|
@ -9,17 +9,17 @@ en:
|
||||||
edit: Edit this category
|
edit: Edit this category
|
||||||
delete: Delete this category forever
|
delete: Delete this category forever
|
||||||
index:
|
index:
|
||||||
no_items_yet: There are no categories yet. Click "{{create}}" to add your first category.
|
no_items_yet: 'There are no categories yet. Click "{{create}}" to add your first category.'
|
||||||
comments:
|
comments:
|
||||||
approved: The comment from '{{author}}' has been approved.
|
approved: 'The comment from "{{author}}" has been approved.'
|
||||||
comment:
|
comment:
|
||||||
view_live: View this comment live <br/><em>(opens in a new window)</em>
|
view_live: View this comment live <br/><em>(opens in a new window)</em>
|
||||||
read: Read this comment
|
read: Read this comment
|
||||||
reject: Reject this comment
|
reject: Reject this comment
|
||||||
approve: Approve this comment
|
approve: Approve this comment
|
||||||
rejected: The comment from '{{author}}' has been rejected.
|
rejected: 'The comment from "{{author}}" has been rejected.'
|
||||||
index:
|
index:
|
||||||
no_items_yet: There are no {{type}} comments.
|
no_items_yet: 'There are no {{type}} comments.'
|
||||||
show:
|
show:
|
||||||
comment: Comment
|
comment: Comment
|
||||||
blog_post: Blog Post
|
blog_post: Blog Post
|
||||||
|
@ -38,7 +38,7 @@ en:
|
||||||
toggle_advanced_options: Click to access meta tag settings and menu options
|
toggle_advanced_options: Click to access meta tag settings and menu options
|
||||||
save_as_draft: Save as Draft
|
save_as_draft: Save as Draft
|
||||||
index:
|
index:
|
||||||
no_items_yet: There are no Blog Posts yet. Click "{{create}}" to add your first blog post.
|
no_items_yet: 'There are no Blog Posts yet. Click "{{create}}" to add your first blog post.'
|
||||||
post:
|
post:
|
||||||
view_live: View this blog post live <br/><em>(opens in a new window)</em>
|
view_live: View this blog post live <br/><em>(opens in a new window)</em>
|
||||||
edit: Edit this blog post
|
edit: Edit this blog post
|
||||||
|
@ -46,10 +46,10 @@ en:
|
||||||
settings:
|
settings:
|
||||||
notification_recipients:
|
notification_recipients:
|
||||||
value: Send notifications to
|
value: Send notifications to
|
||||||
explanation: Every time someone comments on a blog post, Refinery sends out an email to say there is a new comment.
|
explanation: 'Every time someone comments on a blog post, Refinery sends out an email to say there is a new comment.'
|
||||||
hint: When a new comment is added, Refinery will send an email notification to you.
|
hint: 'When a new comment is added, Refinery will send an email notification to you.'
|
||||||
example: "Enter your email address(es) like: jack@work.com, jill@office.com"
|
example: "Enter your email address(es) like: jack@work.com, jill@office.com"
|
||||||
updated: Notification recipients have been set to '{{recipients}}'
|
updated: 'Notification recipients have been set to "{{recipients}}"'
|
||||||
submenu:
|
submenu:
|
||||||
categories:
|
categories:
|
||||||
title: Categories
|
title: Categories
|
||||||
|
@ -69,20 +69,31 @@ en:
|
||||||
title: Settings
|
title: Settings
|
||||||
moderation: Moderation
|
moderation: Moderation
|
||||||
update_notified: Update who gets notified
|
update_notified: Update who gets notified
|
||||||
blog_posts:
|
blog:
|
||||||
side_bar:
|
shared:
|
||||||
categories: Categories
|
categories:
|
||||||
index:
|
title: Categories
|
||||||
read_more: Read more
|
posts:
|
||||||
show:
|
other: Other Posts
|
||||||
|
created_at: 'Posted on {{when}}'
|
||||||
|
read_more: Read more
|
||||||
comments:
|
comments:
|
||||||
title: Comments
|
singular: comment
|
||||||
by: Posted by {{who}}
|
none: no comments
|
||||||
|
categories:
|
||||||
|
show:
|
||||||
|
no_posts: There are no posts here yet.
|
||||||
|
posts:
|
||||||
|
comment: comment
|
||||||
|
comment:
|
||||||
|
by: 'Posted by {{who}}'
|
||||||
time_ago: '{{time}} ago'
|
time_ago: '{{time}} ago'
|
||||||
thank_you: 'Thank you for commenting.'
|
thank_you: 'Thank you for commenting.'
|
||||||
thank_you_moderated: 'Thank you for commenting. Your message has been placed in the moderation queue and will appear shortly.'
|
thank_you_moderated: 'Thank you for commenting. Your message has been placed in the moderation queue and will appear shortly.'
|
||||||
other: Other Blog Posts
|
show:
|
||||||
filed_in: Filed in
|
comments:
|
||||||
created_at_title: Publishing Date
|
title: Comments
|
||||||
created_at: Posted on {{when}}
|
add: Make a Comment
|
||||||
submit: Send comment
|
other: Other Blog Posts
|
||||||
|
filed_in: Filed in
|
||||||
|
submit: Send comment
|
|
@ -1,9 +1,11 @@
|
||||||
if Rails.version < '3.0.0'
|
if Rails.version < '3.0.0'
|
||||||
ActionController::Routing::Routes.draw do |map|
|
ActionController::Routing::Routes.draw do |map|
|
||||||
map.blog_post '/blog', :controller => :blog_posts, :action => :index
|
map.namespace(:blog) do |blog|
|
||||||
map.blog_post '/blog/:id', :controller => :blog_posts, :action => :show
|
blog.root :controller => "posts", :action => 'index'
|
||||||
map.blog_category '/blog/categories/:category_id', :controller => :blog_posts, :action => :index
|
blog.post '/blog/:id', :controller => "posts", :action => 'show'
|
||||||
map.blog_post_blog_comments '/blog/:id/comments', :controller => :blog_posts, :action => :comment
|
blog.category '/blog/categories/:id', :controller => "categories", :action => 'show'
|
||||||
|
blog.post_blog_comments '/blog/:id/comments', :controller => 'posts', :action => 'comment'
|
||||||
|
end
|
||||||
|
|
||||||
map.namespace(:admin, :path_prefix => 'refinery') do |admin|
|
map.namespace(:admin, :path_prefix => 'refinery') do |admin|
|
||||||
admin.namespace :blog do |blog|
|
admin.namespace :blog do |blog|
|
||||||
|
@ -28,11 +30,12 @@ if Rails.version < '3.0.0'
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Refinery::Application.routes.draw do
|
Refinery::Application.routes.draw do
|
||||||
match '/blog', :to => 'blog_posts#index', :as => 'blog_post'
|
scope(:path => 'blog') do
|
||||||
match '/blog/:id', :to => 'blog_posts#show', :as => 'blog_post'
|
root :to => 'posts#index'
|
||||||
|
match ':id', :to => 'posts#show', :as => 'post'
|
||||||
match '/blog/categories/:category_id', :to => 'blog_posts#index', :as => 'blog_category'
|
match 'categories/:id', :to => 'categories#show', :as => 'category'
|
||||||
match '/blog/:id/comments', :to => 'blog_posts#comment', :as => 'blog_post_blog_comments'
|
match ':id/comments', :to => 'posts#comment', :as => 'post_blog_comments'
|
||||||
|
end
|
||||||
|
|
||||||
scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
|
scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
|
||||||
scope(:path => 'blog', :name_prefix => 'admin', :as => 'blog', :module => 'blog') do
|
scope(:path => 'blog', :name_prefix => 'admin', :as => 'blog', :module => 'blog') do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue