diff options
author | Philip Arndt <parndt@gmail.com> | 2010-08-28 18:15:53 +1200 |
---|---|---|
committer | Philip Arndt <parndt@gmail.com> | 2010-08-28 18:15:53 +1200 |
commit | 21dca99ddf7eadb929bc9fe40a6b3f9fd90b2f41 (patch) | |
tree | 920043fe637f02bde2ca7a41b9c714e6fd7633f1 | |
parent | e6fead06dcc6c27e47df83533b53256beabc21a5 (diff) | |
download | refinerycms-blog-21dca99ddf7eadb929bc9fe40a6b3f9fd90b2f41.tar.gz refinerycms-blog-21dca99ddf7eadb929bc9fe40a6b3f9fd90b2f41.tar.bz2 refinerycms-blog-21dca99ddf7eadb929bc9fe40a6b3f9fd90b2f41.zip |
wrote rails engine for later, added ability to add comments and see ones already posted.
-rw-r--r-- | app/controllers/blog_posts_controller.rb | 21 | ||||
-rw-r--r-- | app/models/blog_comment.rb | 12 | ||||
-rw-r--r-- | app/views/admin/blog/comments/index.html.erb | 12 | ||||
-rw-r--r-- | app/views/blog_posts/show.html.erb | 37 | ||||
-rw-r--r-- | config/locales/en.yml | 1 | ||||
-rw-r--r-- | config/routes.rb | 39 | ||||
-rw-r--r-- | lib/refinerycms-blog.rb | 18 | ||||
-rw-r--r-- | public/stylesheets/refinerycms-blog.css | 3 |
8 files changed, 120 insertions, 23 deletions
diff --git a/app/controllers/blog_posts_controller.rb b/app/controllers/blog_posts_controller.rb index 7ddb7b8..caaa336 100644 --- a/app/controllers/blog_posts_controller.rb +++ b/app/controllers/blog_posts_controller.rb @@ -2,6 +2,7 @@ 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) @@ -10,15 +11,33 @@ class BlogPostsController < ApplicationController end def show - @blog_post = BlogPost.live.find(params[:id]) + @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 = BlogComment.create(params[:blog_comment])).valid? + if BlogComment::Moderation.enabled? + flash[:notice] = t('.thank_you_moderated') + redirect_back_or_default blog_post_url(params[:id]) + else + 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 diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index 28139e7..cc890fa 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -1,8 +1,18 @@ class BlogComment < ActiveRecord::Base + filters_spam :author_field => :name, + :email_field => :email, + :message_field => :message + belongs_to :post, :class_name => 'BlogPost' - acts_as_indexed :fields => [:name, :email, :body] + acts_as_indexed :fields => [:name, :email, :message] + + alias_attribute :message, :body + + validates_presence_of :name, :message + validates_format_of :email, + :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i named_scope :unmoderated, :conditions => {:state => nil} named_scope :approved, :conditions => {:state => 'approved'} diff --git a/app/views/admin/blog/comments/index.html.erb b/app/views/admin/blog/comments/index.html.erb index c5e911b..940ba47 100644 --- a/app/views/admin/blog/comments/index.html.erb +++ b/app/views/admin/blog/comments/index.html.erb @@ -3,24 +3,28 @@ <% if searching? %> <h2><%= t('shared.admin.search.results_for', :query => params[:search]) %></h2> <% if @blog_comments.any? %> - <%= will_paginate @blog_comments %> + <%=# will_paginate @blog_comments + %> <ul> <%= render :partial => "blog_comments", :collection => @blog_comments %> </ul> - <%= will_paginate @blog_comments %> + <%=# will_paginate @blog_comments + %> <% else %> <p><%= t('admin.search_no_results') %></p> <% end %> <% else %> <% if @blog_comments.any? %> - <%= will_paginate @blog_comments %> + <%=# will_paginate @blog_comments + %> <%= render :partial => "sortable_list" %> - <%= will_paginate @blog_comments %> + <%=# will_paginate @blog_comments + %> <% else %> <h3> <%= t('.no_items_yet', diff --git a/app/views/blog_posts/show.html.erb b/app/views/blog_posts/show.html.erb index 2a6fa12..cf51e0c 100644 --- a/app/views/blog_posts/show.html.erb +++ b/app/views/blog_posts/show.html.erb @@ -3,6 +3,8 @@ <% content_for :body_content_left do %> <%= @blog_post.body %> + <hr /> + <% if (categories = @blog_post.categories).any? %> <div class='post_categories'> <span class='filed_in'><%= t('.filed_in') %></span> @@ -15,6 +17,41 @@ </ul> </div> <% end %> + + <hr /> + <% if (comments = @blog_post.comments.approved).any? %> + <h2><%= t('.comments') %></h2> + <% comments.each do |comment| %> + <div class='blog_comment_message'> + <p> + <%= comment.message.to_s.gsub("\r\n\r\n", "</p><p>").gsub("\r\n", "<br/>") %> + </p> + </div> + <p class='blog_comment_author'> + <%= t('.comment_by', :who => comment.name) %> + <%= ", #{time_ago_in_words(comment.created_at)}".html_safe %> + </p> + <% end %> + <hr /> + <% end %> + + <% form_for [:blog_post, @blog_comment] do |f| %> + <div class='field'> + <%= f.label :name %> + <%= f.text_field :name %> + </div> + <div class='field'> + <%= f.label :email %> + <%= f.text_field :email %> + </div> + <div class='field message_field'> + <%= f.label :message %> + <%= f.text_area :message, :rows => 6 %> + </div> + <div class='field form-actions'> + <%= f.submit t('.submit') %> + </div> + <% end %> <% end %> <% content_for :body_content_right do %> diff --git a/config/locales/en.yml b/config/locales/en.yml index c37ba53..c6d75e6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -59,3 +59,4 @@ en: filed_in: Filed in created_at_title: Publishing Date created_at: Posted on {{when}} + submit: Send comment diff --git a/config/routes.rb b/config/routes.rb index 36e80f9..fabb925 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,20 +1,25 @@ -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 +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(:admin, :path_prefix => 'refinery') do |admin| - admin.namespace :blog do |blog| - blog.resources :posts - blog.resources :categories - blog.resources :comments, :collection => { - :approved => :get, - :rejected => :get - } - blog.resources :settings, :collection => { - :notification_recipients => [:get, :post], - :moderation => :get - } + map.namespace(:admin, :path_prefix => 'refinery') do |admin| + admin.namespace :blog do |blog| + blog.resources :posts + blog.resources :categories + blog.resources :comments, :collection => { + :approved => :get, + :rejected => :get + } + blog.resources :settings, :collection => { + :notification_recipients => [:get, :post], + :moderation => :get + } + end end end -end +else + # route for rails3 here. +end
\ No newline at end of file diff --git a/lib/refinerycms-blog.rb b/lib/refinerycms-blog.rb index 461e75c..c322faf 100644 --- a/lib/refinerycms-blog.rb +++ b/lib/refinerycms-blog.rb @@ -2,6 +2,24 @@ require 'filters_spam' if defined?(Bundler) module Refinery module Blog + + class Engine < Rails::Engine + initializer 'blog serves assets' do + app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public" + end + + config.after_initialize do + Refinery::Plugin.register do |plugin| + plugin.name = "refinerycms_blog" + plugin.url = {:controller => '/admin/blog/posts', :action => 'index'} + plugin.menu_match = /^\/?(admin|refinery)\/blog\/?(posts|comments|categories)?/ + plugin.activity = { + :class => BlogPost + } + end + end + end if defined?(Rails::Engine) + class << self def version %q{0.9.8.0.rc1} diff --git a/public/stylesheets/refinerycms-blog.css b/public/stylesheets/refinerycms-blog.css index d961487..cef953a 100644 --- a/public/stylesheets/refinerycms-blog.css +++ b/public/stylesheets/refinerycms-blog.css @@ -10,4 +10,7 @@ margin: 0px; padding: 0px; display: inline; +} +.field.message_field label { + vertical-align: top; }
\ No newline at end of file |