From bd50bdb415346329e772a90f26828376a6a1cffb Mon Sep 17 00:00:00 2001 From: djones Date: Mon, 6 Sep 2010 16:22:13 +1200 Subject: 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 --- app/controllers/blog/categories_controller.rb | 7 +++ app/controllers/blog/posts_controller.rb | 39 ++++++++++++ app/controllers/blog_controller.rb | 15 +++++ app/controllers/blog_posts_controller.rb | 62 ------------------- app/views/admin/blog/comments/show.html.erb | 4 +- app/views/blog/categories/show.html.erb | 20 ++++++ app/views/blog/posts/_comment.html.erb | 9 +++ app/views/blog/posts/index.html.erb | 16 +++++ app/views/blog/posts/show.html.erb | 71 +++++++++++++++++++++ app/views/blog/shared/_categories.html.erb | 8 +++ app/views/blog/shared/_post.html.erb | 20 ++++++ app/views/blog/shared/_posts.html.erb | 8 +++ app/views/blog_posts/_categories.html.erb | 0 app/views/blog_posts/_comments.html.erb | 0 app/views/blog_posts/_side_bar.html.erb | 8 --- app/views/blog_posts/index.html.erb | 27 -------- app/views/blog_posts/show.html.erb | 89 --------------------------- config/locales/en.yml | 53 +++++++++------- config/routes.rb | 21 ++++--- 19 files changed, 258 insertions(+), 219 deletions(-) create mode 100644 app/controllers/blog/categories_controller.rb create mode 100644 app/controllers/blog/posts_controller.rb create mode 100644 app/controllers/blog_controller.rb delete mode 100644 app/controllers/blog_posts_controller.rb create mode 100644 app/views/blog/categories/show.html.erb create mode 100644 app/views/blog/posts/_comment.html.erb create mode 100644 app/views/blog/posts/index.html.erb create mode 100644 app/views/blog/posts/show.html.erb create mode 100644 app/views/blog/shared/_categories.html.erb create mode 100644 app/views/blog/shared/_post.html.erb create mode 100644 app/views/blog/shared/_posts.html.erb delete mode 100644 app/views/blog_posts/_categories.html.erb delete mode 100644 app/views/blog_posts/_comments.html.erb delete mode 100644 app/views/blog_posts/_side_bar.html.erb delete mode 100644 app/views/blog_posts/index.html.erb delete mode 100644 app/views/blog_posts/show.html.erb diff --git a/app/controllers/blog/categories_controller.rb b/app/controllers/blog/categories_controller.rb new file mode 100644 index 0000000..71ceec1 --- /dev/null +++ b/app/controllers/blog/categories_controller.rb @@ -0,0 +1,7 @@ +class Blog::CategoriesController < BlogController + + def show + @category = BlogCategory.find(params[:id]) + end + +end \ No newline at end of file diff --git a/app/controllers/blog/posts_controller.rb b/app/controllers/blog/posts_controller.rb new file mode 100644 index 0000000..8a10604 --- /dev/null +++ b/app/controllers/blog/posts_controller.rb @@ -0,0 +1,39 @@ +class Blog::PostsController < BlogController + + before_filter :find_all_blog_posts + before_filter :find_blog_post, :only => [:show, :comment] + + def show + @blog_comment = BlogComment.new + + # 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 comment + if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid? + if BlogComment::Moderation.enabled? + flash[:notice] = t('blog_posts.show.comments.thank_you_moderated') + redirect_to blog_post_url(params[:id]) + else + flash[:notice] = t('blog_posts.show.comments.thank_you') + redirect_to blog_post_url(params[:id], + :anchor => "comment-#{@blog_comment.to_param}") + end + else + render :action => 'show' + end + end + +protected + + def find_blog_post + @blog_post = BlogPost.live.find(params[:id]) + end + + def find_all_blog_posts + @blog_posts = BlogPost.live + end + +end diff --git a/app/controllers/blog_controller.rb b/app/controllers/blog_controller.rb new file mode 100644 index 0000000..0931cbd --- /dev/null +++ b/app/controllers/blog_controller.rb @@ -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 \ No newline at end of file diff --git a/app/controllers/blog_posts_controller.rb b/app/controllers/blog_posts_controller.rb deleted file mode 100644 index 73b9dfa..0000000 --- a/app/controllers/blog_posts_controller.rb +++ /dev/null @@ -1,62 +0,0 @@ -class BlogPostsController < ApplicationController - - before_filter :find_all_blog_posts, :find_all_blog_categories - before_filter :find_page - 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 - @blog_comment = BlogComment.new - - # 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 comment - if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid? - if BlogComment::Moderation.enabled? - flash[:notice] = t('blog_posts.show.comments.thank_you_moderated') - redirect_to blog_post_url(params[:id]) - else - flash[:notice] = t('blog_posts.show.comments.thank_you') - redirect_to blog_post_url(params[:id], - :anchor => "comment-#{@blog_comment.to_param}") - end - else - render :action => 'show' - end - end - -protected - - def find_blog_post - @blog_post = BlogPost.live.find(params[:id]) - end - - def find_all_blog_posts - unless params[:category_id].present? - @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 diff --git a/app/views/admin/blog/comments/show.html.erb b/app/views/admin/blog/comments/show.html.erb index 7dbe519..1cc29bb 100644 --- a/app/views/admin/blog/comments/show.html.erb +++ b/app/views/admin/blog/comments/show.html.erb @@ -60,6 +60,4 @@ -<% content_for :head do %> - <%= stylesheet_link_tag 'refinery/refinerycms-blog' %> -<% end %> \ No newline at end of file +<% content_for :head, stylesheet_link_tag('refinery/refinerycms-blog') %> \ No newline at end of file diff --git a/app/views/blog/categories/show.html.erb b/app/views/blog/categories/show.html.erb new file mode 100644 index 0000000..bd9f863 --- /dev/null +++ b/app/views/blog/categories/show.html.erb @@ -0,0 +1,20 @@ +<% content_for :body_content_title, @category.title %> + +<% content_for :body_content_left do %> + <% if @category.posts.any? %> + + <% else %> +

+ <%= t('.no_posts') %> +

+ <% 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') %> \ No newline at end of file diff --git a/app/views/blog/posts/_comment.html.erb b/app/views/blog/posts/_comment.html.erb new file mode 100644 index 0000000..559757b --- /dev/null +++ b/app/views/blog/posts/_comment.html.erb @@ -0,0 +1,9 @@ +
+

+ <%= comment.message.to_s.gsub("\r\n\r\n", "

").gsub("\r\n", "
") %> +

+
+

+ <%= t('.by', :who => comment.name) %> + <%= t('.time_ago', :time => time_ago_in_words(comment.created_at)) %> +

\ No newline at end of file diff --git a/app/views/blog/posts/index.html.erb b/app/views/blog/posts/index.html.erb new file mode 100644 index 0000000..f2ccbd8 --- /dev/null +++ b/app/views/blog/posts/index.html.erb @@ -0,0 +1,16 @@ +<% content_for :body_content_left do %> + <%= @page[Page.default_parts.first.to_sym] %> + + +<% 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') %> \ No newline at end of file diff --git a/app/views/blog/posts/show.html.erb b/app/views/blog/posts/show.html.erb new file mode 100644 index 0000000..5b897ad --- /dev/null +++ b/app/views/blog/posts/show.html.erb @@ -0,0 +1,71 @@ +<% content_for :body_content_title, @blog_post.title %> + +<% content_for :body_content_left do %> +

+ <%= t('blog.shared.posts.created_at', :when => @blog_post.created_at.strftime('%d %B %Y')) %>. + + <% if (categories = @blog_post.categories).any? %> + + <%= t('.filed_in') %> + <% categories.each_with_index do |category, index| %> + <%= link_to category.title, blog_category_url(category) -%><%= ',' if index < ((categories.length) - 1) %> + <% end %> + + <% end %> +

+ <%= @blog_post.body %> + + <% if BlogPost.comments_allowed? %> +

<%= t('.comments.title') %>

+ + <% if (comments = @blog_post.comments.approved).any? %> + <%= render :partial => "comment", :collection => comments %> + <% else %> +

+ <%= t('blog.shared.comments.none') %>. +

+ <% end %> + + <% flash.each do |key, value| %> +
+ <%= value %> +
+ <% end %> + +

<%= t('.comments.add') %>

+ <% form_for [:blog_post, @blog_comment] do |f| %> + <% if Rails.version < '3.0.0'%> + <%= f.error_messages %> + <% else %> + <%= render :partial => "/shared/admin/error_messages", + :locals => { + :object => f.object, + :include_object_name => true + } %> + <% end %> +
+ <%= f.label :name %> + <%= f.text_field :name %> +
+
+ <%= f.label :email %> + <%= f.text_field :email %> +
+
+ <%= f.label :message %> + <%= f.text_area :message, :rows => 6 %> +
+
+ <%= f.submit t('.submit') %> +
+ <% end %> + <% end %> +<% end %> + +<% content_for :body_content_right do %> + <%= render :partial => "/blog/shared/categories" %> + <%= render :partial => "/blog/shared/posts" %> +<% end %> + +<%= render :partial => "/shared/content_page" %> +<% content_for :head, stylesheet_link_tag('refinerycms-blog') %> \ No newline at end of file diff --git a/app/views/blog/shared/_categories.html.erb b/app/views/blog/shared/_categories.html.erb new file mode 100644 index 0000000..fa26ceb --- /dev/null +++ b/app/views/blog/shared/_categories.html.erb @@ -0,0 +1,8 @@ +

<%= t('.title') %>

+ \ No newline at end of file diff --git a/app/views/blog/shared/_post.html.erb b/app/views/blog/shared/_post.html.erb new file mode 100644 index 0000000..d8194d3 --- /dev/null +++ b/app/views/blog/shared/_post.html.erb @@ -0,0 +1,20 @@ +
  • +

    <%= link_to post.title, blog_post_url(post) %>

    +

    + <%= t('blog.shared.posts.created_at', :when => post.created_at.strftime('%d %B %Y')) %> +

    + <%= truncate(post.body, + :length => RefinerySetting.find_or_set(:blog_post_teaser_length, 250), + :preserve_html_tags => true) %> +

    + <%= link_to t('blog.shared.posts.read_more'), blog_post_url(post) %> + + + <% if post.comments.any? %> + (<%= pluralize(post.comments.count, t('blog.shared.comments.singular')) %>) + <% else %> + (<%= t('blog.shared.comments.none') %>) + <% end %> + +

    +
  • \ No newline at end of file diff --git a/app/views/blog/shared/_posts.html.erb b/app/views/blog/shared/_posts.html.erb new file mode 100644 index 0000000..4a78334 --- /dev/null +++ b/app/views/blog/shared/_posts.html.erb @@ -0,0 +1,8 @@ +

    <%= t('.other') %>

    + \ No newline at end of file diff --git a/app/views/blog_posts/_categories.html.erb b/app/views/blog_posts/_categories.html.erb deleted file mode 100644 index e69de29..0000000 diff --git a/app/views/blog_posts/_comments.html.erb b/app/views/blog_posts/_comments.html.erb deleted file mode 100644 index e69de29..0000000 diff --git a/app/views/blog_posts/_side_bar.html.erb b/app/views/blog_posts/_side_bar.html.erb deleted file mode 100644 index dfdfaa2..0000000 --- a/app/views/blog_posts/_side_bar.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -

    <%= t('.categories') %>

    - \ No newline at end of file diff --git a/app/views/blog_posts/index.html.erb b/app/views/blog_posts/index.html.erb deleted file mode 100644 index c97ca61..0000000 --- a/app/views/blog_posts/index.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -<% content_for :body_content_left do %> - <%= @page[Page.default_parts.first.to_sym] %> - - -<% 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 %> \ No newline at end of file diff --git a/app/views/blog_posts/show.html.erb b/app/views/blog_posts/show.html.erb deleted file mode 100644 index e13a442..0000000 --- a/app/views/blog_posts/show.html.erb +++ /dev/null @@ -1,89 +0,0 @@ -<% content_for :body_content_title, @blog_post.title %> - -<% content_for :body_content_left do %> - <%= t('.created_at', :when => @blog_post.created_at.strftime('%d %B %Y')) %> - <%= @blog_post.body %> - - <% if (categories = @blog_post.categories).any? %> -
    -
    - <%= t('.filed_in') %> - -
    - <% end %> - - <% if (comments = @blog_post.comments.approved).any? %> -
    -

    <%= t('.comments.title') %>

    - <% comments.each do |comment| %> -
    -

    - <%= comment.message.to_s.gsub("\r\n\r\n", "

    ").gsub("\r\n", "
    ") %> -

    -
    -

    - <%= t('.comments.by', :who => comment.name) %> - <%= t('.comments.time_ago', :time => time_ago_in_words(comment.created_at)) %> -

    - <% end %> - <% end %> - - <% if BlogPost.comments_allowed? %> -
    - <% flash.each do |key, value| %> -
    - <%= value %> -
    - <% end %> - <% form_for [:blog_post, @blog_comment] do |f| %> - <% if Rails.version < '3.0.0'%> - <%= f.error_messages %> - <% else %> - <%= render :partial => "/shared/admin/error_messages", - :locals => { - :object => f.object, - :include_object_name => true - } %> - <% end %> -
    - <%= f.label :name %> - <%= f.text_field :name %> -
    -
    - <%= f.label :email %> - <%= f.text_field :email %> -
    -
    - <%= f.label :message %> - <%= f.text_area :message, :rows => 6 %> -
    -
    - <%= f.submit t('.submit') %> -
    - <% end %> - <% end %> -<% end %> - -<% content_for :body_content_right do %> - <%= render :partial => "side_bar" %> - -

    <%= t('.other') %>

    - -<% end %> - -<%= render :partial => "/shared/content_page" %> -<% content_for :head do %> - <%= stylesheet_link_tag 'refinerycms-blog' %> -<% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 2cd53dc..9d562d7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -9,17 +9,17 @@ en: edit: Edit this category delete: Delete this category forever 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: - approved: The comment from '{{author}}' has been approved. + approved: 'The comment from "{{author}}" has been approved.' comment: view_live: View this comment live
    (opens in a new window) read: Read this comment reject: Reject this comment approve: Approve this comment - rejected: The comment from '{{author}}' has been rejected. + rejected: 'The comment from "{{author}}" has been rejected.' index: - no_items_yet: There are no {{type}} comments. + no_items_yet: 'There are no {{type}} comments.' show: comment: Comment blog_post: Blog Post @@ -38,7 +38,7 @@ en: toggle_advanced_options: Click to access meta tag settings and menu options save_as_draft: Save as Draft 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: view_live: View this blog post live
    (opens in a new window) edit: Edit this blog post @@ -46,10 +46,10 @@ en: settings: notification_recipients: 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. - hint: When a new comment is added, Refinery will send an email notification to you. + 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.' 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: categories: title: Categories @@ -69,20 +69,31 @@ en: title: Settings moderation: Moderation update_notified: Update who gets notified - blog_posts: - side_bar: - categories: Categories - index: - read_more: Read more - show: + blog: + shared: + categories: + title: Categories + posts: + other: Other Posts + created_at: 'Posted on {{when}}' + read_more: Read more comments: - title: Comments - by: Posted by {{who}} + singular: comment + 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' 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.' - other: Other Blog Posts - filed_in: Filed in - created_at_title: Publishing Date - created_at: Posted on {{when}} - submit: Send comment + show: + comments: + title: Comments + add: Make a Comment + other: Other Blog Posts + filed_in: Filed in + submit: Send comment \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 70406de..f21fbba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,11 @@ if Rails.version < '3.0.0' ActionController::Routing::Routes.draw do |map| - map.blog_post '/blog', :controller => :blog_posts, :action => :index - map.blog_post '/blog/:id', :controller => :blog_posts, :action => :show - map.blog_category '/blog/categories/:category_id', :controller => :blog_posts, :action => :index - map.blog_post_blog_comments '/blog/:id/comments', :controller => :blog_posts, :action => :comment + map.namespace(:blog) do |blog| + blog.root :controller => "posts", :action => 'index' + blog.post '/blog/:id', :controller => "posts", :action => 'show' + 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| admin.namespace :blog do |blog| @@ -28,11 +30,12 @@ if Rails.version < '3.0.0' end else Refinery::Application.routes.draw do - match '/blog', :to => 'blog_posts#index', :as => 'blog_post' - match '/blog/:id', :to => 'blog_posts#show', :as => 'blog_post' - - match '/blog/categories/:category_id', :to => 'blog_posts#index', :as => 'blog_category' - match '/blog/:id/comments', :to => 'blog_posts#comment', :as => 'blog_post_blog_comments' + scope(:path => 'blog') do + root :to => 'posts#index' + match ':id', :to => 'posts#show', :as => 'post' + match 'categories/:id', :to => 'categories#show', :as => 'category' + match ':id/comments', :to => 'posts#comment', :as => 'post_blog_comments' + end scope(:path => 'refinery', :as => 'admin', :module => 'admin') do scope(:path => 'blog', :name_prefix => 'admin', :as => 'blog', :module => 'blog') do -- cgit v1.2.3