refinerycms-blog 0.9.8.0.rc2 → 1.0.rc10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/app/controllers/admin/blog/comments_controller.rb +18 -4
  2. data/app/controllers/admin/blog/settings_controller.rb +9 -2
  3. data/app/controllers/blog/categories_controller.rb +7 -0
  4. data/app/controllers/blog/posts_controller.rb +43 -0
  5. data/app/controllers/blog_controller.rb +15 -0
  6. data/app/models/blog_comment.rb +47 -13
  7. data/app/models/blog_post.rb +22 -1
  8. data/app/views/admin/blog/_submenu.html.erb +6 -1
  9. data/app/views/admin/blog/categories/_category.html.erb +4 -2
  10. data/app/views/admin/blog/categories/_form.html.erb +10 -2
  11. data/app/views/admin/blog/comments/_comment.html.erb +13 -10
  12. data/app/views/admin/blog/comments/index.html.erb +1 -1
  13. data/app/views/admin/blog/comments/show.html.erb +63 -0
  14. data/app/views/admin/blog/posts/_form.html.erb +9 -1
  15. data/app/views/admin/blog/posts/_post.html.erb +3 -1
  16. data/app/views/blog/categories/show.html.erb +20 -0
  17. data/app/views/blog/posts/_comment.html.erb +9 -0
  18. data/app/views/blog/posts/index.html.erb +17 -0
  19. data/app/views/blog/posts/index.rss.builder +17 -0
  20. data/app/views/blog/posts/show.html.erb +85 -0
  21. data/app/views/blog/shared/_categories.html.erb +8 -0
  22. data/app/views/blog/shared/_post.html.erb +22 -0
  23. data/app/views/blog/shared/_posts.html.erb +8 -0
  24. data/app/views/blog/shared/_rss_feed.html.erb +2 -0
  25. data/config/locales/en.yml +54 -18
  26. data/config/routes.rb +51 -5
  27. data/generators/refinery_blog/refinery_blog_generator.rb +15 -16
  28. data/generators/refinery_blog/templates/{migration.rb → db/migrate/migration.rb} +0 -0
  29. data/generators/refinery_blog/templates/{seed.rb → db/seeds/seed.rb} +0 -0
  30. data/lib/gemspec.rb +1 -1
  31. data/lib/generators/refinery_blog/templates/db/migrate/migration_number_create_singular_name.rb +26 -0
  32. data/lib/generators/refinery_blog/templates/db/seeds/seed.rb +16 -0
  33. data/lib/generators/refinery_blog_generator.rb +79 -0
  34. data/lib/refinerycms-blog.rb +23 -3
  35. data/public/images/refinerycms-blog/icons/down.gif +0 -0
  36. data/public/images/refinerycms-blog/icons/up.gif +0 -0
  37. data/public/images/refinerycms-blog/rss-feed.png +0 -0
  38. data/public/javascripts/refinery/refinerycms-blog.js +14 -4
  39. data/public/stylesheets/refinery/refinerycms-blog.css +18 -0
  40. data/public/stylesheets/refinerycms-blog.css +5 -0
  41. data/readme.md +24 -1
  42. metadata +27 -16
  43. data/app/controllers/blog_posts_controller.rb +0 -62
  44. data/app/views/blog_posts/_categories.html.erb +0 -0
  45. data/app/views/blog_posts/_comments.html.erb +0 -0
  46. data/app/views/blog_posts/_side_bar.html.erb +0 -8
  47. data/app/views/blog_posts/index.html.erb +0 -27
  48. data/app/views/blog_posts/show.html.erb +0 -76
@@ -10,13 +10,27 @@ class Admin::Blog::CommentsController < Admin::BaseController
10
10
  end
11
11
 
12
12
  def approved
13
- @blog_comments = BlogComment.approved
14
- render :action => 'index'
13
+ unless params[:id].present?
14
+ @blog_comments = BlogComment.approved
15
+ render :action => 'index'
16
+ else
17
+ @blog_comment = BlogComment.find(params[:id])
18
+ @blog_comment.approve!
19
+ flash[:notice] = t('admin.blog.comments.approved', :author => @blog_comment.name)
20
+ redirect_to :action => params[:return_to] || 'index'
21
+ end
15
22
  end
16
23
 
17
24
  def rejected
18
- @blog_comments = BlogComment.rejected
19
- render :action => 'index'
25
+ unless params[:id].present?
26
+ @blog_comments = BlogComment.rejected
27
+ render :action => 'index'
28
+ else
29
+ @blog_comment = BlogComment.find(params[:id])
30
+ @blog_comment.reject!
31
+ flash[:notice] = t('admin.blog.comments.rejected', :author => @blog_comment.name)
32
+ redirect_to :action => params[:return_to] || 'index'
33
+ end
20
34
  end
21
35
 
22
36
  end
@@ -4,12 +4,19 @@ class Admin::Blog::SettingsController < Admin::BaseController
4
4
  @recipients = BlogComment::Notification.recipients
5
5
 
6
6
  if request.post?
7
- BlogComment::Notification.recipients == params[:recipients]
7
+ BlogComment::Notification.recipients = params[:recipients]
8
+ flash[:notice] = t('admin.blog.settings.notification_recipients.updated',
9
+ :recipients => BlogComment::Notification.recipients)
10
+ unless request.xhr? or from_dialog?
11
+ redirect_back_or_default(admin_blog_posts_path)
12
+ else
13
+ render :text => "<script type='text/javascript'>parent.window.location = '#{admin_blog_posts_path}';</script>"
14
+ end
8
15
  end
9
16
  end
10
17
 
11
18
  def moderation
12
- enabled = BlogComment::Moderation.toggle
19
+ enabled = BlogComment::Moderation.toggle!
13
20
  unless request.xhr?
14
21
  redirect_back_or_default(admin_blog_posts_path)
15
22
  else
@@ -0,0 +1,7 @@
1
+ class Blog::CategoriesController < BlogController
2
+
3
+ def show
4
+ @category = BlogCategory.find(params[:id])
5
+ end
6
+
7
+ end
@@ -0,0 +1,43 @@
1
+ class Blog::PostsController < BlogController
2
+
3
+ before_filter :find_all_blog_posts
4
+ before_filter :find_blog_post, :only => [:show, :comment]
5
+
6
+ def index
7
+ respond_to do |format|
8
+ format.html
9
+ format.rss
10
+ end
11
+ end
12
+
13
+ def show
14
+ @blog_comment = BlogComment.new
15
+ present(@page)
16
+ end
17
+
18
+ def comment
19
+ if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid?
20
+ if BlogComment::Moderation.enabled?
21
+ flash[:notice] = t('blog.posts.comments.thank_you_moderated')
22
+ redirect_to blog_post_url(params[:id])
23
+ else
24
+ flash[:notice] = t('blog.posts.comments.thank_you')
25
+ redirect_to blog_post_url(params[:id],
26
+ :anchor => "comment-#{@blog_comment.to_param}")
27
+ end
28
+ else
29
+ render :action => 'show'
30
+ end
31
+ end
32
+
33
+ protected
34
+
35
+ def find_blog_post
36
+ @blog_post = BlogPost.live.find(params[:id])
37
+ end
38
+
39
+ def find_all_blog_posts
40
+ @blog_posts = BlogPost.live
41
+ end
42
+
43
+ end
@@ -0,0 +1,15 @@
1
+ class BlogController < ApplicationController
2
+
3
+ before_filter :find_page, :find_all_blog_categories
4
+
5
+ protected
6
+
7
+ def find_page
8
+ @page = Page.find_by_link_url("/blog")
9
+ end
10
+
11
+ def find_all_blog_categories
12
+ @blog_categories = BlogCategory.all
13
+ end
14
+
15
+ end
@@ -4,7 +4,7 @@ class BlogComment < ActiveRecord::Base
4
4
  :email_field => :email,
5
5
  :message_field => :body
6
6
 
7
- belongs_to :post, :class_name => 'BlogPost'
7
+ belongs_to :post, :class_name => 'BlogPost', :foreign_key => 'blog_post_id'
8
8
 
9
9
  acts_as_indexed :fields => [:name, :email, :message]
10
10
 
@@ -14,9 +14,35 @@ class BlogComment < ActiveRecord::Base
14
14
  validates_format_of :email,
15
15
  :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
16
16
 
17
- named_scope :unmoderated, :conditions => {:state => nil}
18
- named_scope :approved, :conditions => {:state => 'approved'}
19
- named_scope :rejected, :conditions => {:state => 'rejected'}
17
+ if Rails.version < '3.0.0'
18
+ named_scope :unmoderated, :conditions => {:state => nil}
19
+ named_scope :approved, :conditions => {:state => 'approved'}
20
+ named_scope :rejected, :conditions => {:state => 'rejected'}
21
+ else
22
+ scope :unmoderated, :conditions => {:state => nil}
23
+ scope :approved, :conditions => {:state => 'approved'}
24
+ scope :rejected, :conditions => {:state => 'rejected'}
25
+ end
26
+
27
+ def approve!
28
+ self.update_attribute(:state, 'approved')
29
+ end
30
+
31
+ def reject!
32
+ self.update_attribute(:state, 'rejected')
33
+ end
34
+
35
+ def rejected?
36
+ self.state == 'rejected'
37
+ end
38
+
39
+ def approved?
40
+ self.state == 'approved'
41
+ end
42
+
43
+ def unmoderated?
44
+ self.state.nil?
45
+ end
20
46
 
21
47
  before_create do |comment|
22
48
  unless BlogComment::Moderation.enabled?
@@ -28,14 +54,18 @@ class BlogComment < ActiveRecord::Base
28
54
  class << self
29
55
  def enabled?
30
56
  RefinerySetting.find_or_set(:comment_moderation, true, {
31
- :scoping => :blog
57
+ :scoping => :blog,
58
+ :restricted => false,
59
+ :callback_proc_as_string => nil
32
60
  })
33
61
  end
34
62
 
35
- def toggle
63
+ def toggle!
36
64
  RefinerySetting[:comment_moderation] = {
37
65
  :value => !self.enabled?,
38
- :scoping => :blog
66
+ :scoping => :blog,
67
+ :restricted => false,
68
+ :callback_proc_as_string => nil
39
69
  }
40
70
  end
41
71
  end
@@ -44,17 +74,21 @@ class BlogComment < ActiveRecord::Base
44
74
  module Notification
45
75
  class << self
46
76
  def recipients
47
- RefinerySetting.find_or_set(
48
- :comment_notification_recipients,
49
- (Role[:refinery].users.first.email rescue ''),
50
- {:scoping => :blog}
51
- )
77
+ RefinerySetting.find_or_set(:comment_notification_recipients,
78
+ (Role[:refinery].users.first.email rescue ''),
79
+ {
80
+ :scoping => :blog,
81
+ :restricted => false,
82
+ :callback_proc_as_string => nil
83
+ })
52
84
  end
53
85
 
54
86
  def recipients=(emails)
55
87
  RefinerySetting[:comment_notification_recipients] = {
56
88
  :value => emails,
57
- :scoping => :blog
89
+ :scoping => :blog,
90
+ :restricted => false,
91
+ :callback_proc_as_string => nil
58
92
  }
59
93
  end
60
94
  end
@@ -12,7 +12,11 @@ class BlogPost < ActiveRecord::Base
12
12
 
13
13
  default_scope :order => "created_at DESC"
14
14
 
15
- named_scope :live, :conditions => {:draft => false}
15
+ if Rails.version < '3.0.0'
16
+ named_scope :live, :conditions => {:draft => false}
17
+ else
18
+ scope :live, :conditions => {:draft => false}
19
+ end
16
20
 
17
21
  def category_ids=(ids)
18
22
  self.categories = ids.reject{|id| id.blank?}.collect {|c_id|
@@ -27,5 +31,22 @@ class BlogPost < ActiveRecord::Base
27
31
  })
28
32
  end
29
33
  end
34
+
35
+ module ShareThis
36
+ DEFAULT_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
37
+
38
+ class << self
39
+ def key
40
+ RefinerySetting.find_or_set(:share_this_key, BlogPost::ShareThis::DEFAULT_KEY, {
41
+ :scoping => :blog
42
+ })
43
+ end
44
+
45
+ def enabled?
46
+ key = BlogPost::ShareThis.key
47
+ key.present? and key != BlogPost::ShareThis::DEFAULT_KEY
48
+ end
49
+ end
50
+ end
30
51
 
31
52
  end
@@ -24,7 +24,12 @@
24
24
 
25
25
  <ul class='collapsible_menu'>
26
26
  <li>
27
- <%= link_to t('.comments.title'), '#',
27
+ <% if BlogComment.unmoderated.any? %>
28
+ <% title = t('.comments.title_with_count', :new_count => BlogComment.unmoderated.size) %>
29
+ <% else %>
30
+ <% title = t('.comments.title') %>
31
+ <% end %>
32
+ <%= link_to title, '#',
28
33
  :class => 'comments_icon' %>
29
34
  </li>
30
35
  <li>
@@ -4,11 +4,13 @@
4
4
  <span class="preview">&nbsp;</span>
5
5
  </span>
6
6
  <span class='actions'>
7
- <%= link_to refinery_icon_tag("application_edit.png"),
7
+ <%= link_to refinery_icon_tag("application_edit.png"),
8
8
  edit_admin_blog_category_path(category, :dialog => true, :height => 325),
9
9
  :title => t('.edit') %>
10
10
  <%= link_to refinery_icon_tag("delete.png"), admin_blog_category_path(category),
11
11
  :class => "cancel confirm-delete",
12
- :title => t('.delete') %>
12
+ :title => t('.delete'),
13
+ :'data-method' => 'delete',
14
+ :'data-confirm' => t('shared.admin.delete.message', :title => category.title) %>
13
15
  </span>
14
16
  </li>
@@ -1,6 +1,14 @@
1
1
  <% form_for [:admin, @blog_category] do |f| -%>
2
- <%= f.error_messages %>
3
-
2
+ <% if Rails.version < '3.0.0'%>
3
+ <%= f.error_messages %>
4
+ <% else %>
5
+ <%= render :partial => "/shared/admin/error_messages",
6
+ :locals => {
7
+ :object => f.object,
8
+ :include_object_name => true
9
+ } %>
10
+ <% end %>
11
+
4
12
  <div class='field'>
5
13
  <%= f.label :title -%>
6
14
  <%= f.text_field :title, :class => 'larger widest' -%>
@@ -1,17 +1,20 @@
1
- <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(comment) -%>">
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= "comment-#{comment.to_param}" -%>">
2
2
  <span class='title'>
3
3
  <%=h comment.name %>
4
4
  <span class="preview"> - <%= truncate(comment.message, :length => 75) %></span>
5
5
  </span>
6
6
  <span class='actions'>
7
- <%= link_to refinery_icon_tag("application_go.png"), blog_post_url(comment.post,
8
- :anchor => "comment-#{comment.to_param}"),
9
- :title => t('.view_live'),
10
- :target => "_blank" %>
11
- <%= link_to refinery_icon_tag("application_edit.png"), edit_admin_blog_comment_path(comment),
12
- :title => t('.edit') %>
13
- <%= link_to refinery_icon_tag("delete.png"), admin_blog_comment_path(comment),
14
- :class => "cancel confirm-delete",
15
- :title => t('.delete') %>
7
+ <%= link_to refinery_icon_tag("application_go.png"),
8
+ blog_post_url(comment.post, :anchor => "comment-#{comment.to_param}"),
9
+ :title => t('.view_live'),
10
+ :target => "_blank" unless comment.unmoderated? %>
11
+ <%= link_to refinery_icon_tag('zoom.png'), admin_blog_comment_path(comment),
12
+ :title => t('.read') %>
13
+ <%= link_to refinery_icon_tag("cross.png"),
14
+ rejected_admin_blog_comment_path(comment, :return_to => request.path.split('/').last.gsub(/^comments$/, 'index')),
15
+ :title => t('.reject') unless comment.rejected? %>
16
+ <%= link_to refinery_icon_tag("tick.png"),
17
+ approved_admin_blog_comment_path(comment, :return_to => request.path.split('/').last.gsub(/^comments$/, 'index')),
18
+ :title => t('.approve') unless comment.approved? %>
16
19
  </span>
17
20
  </li>
@@ -28,7 +28,7 @@
28
28
  <% else %>
29
29
  <h3>
30
30
  <%= t('.no_items_yet',
31
- :type => (t("admin.blog.submenu.comments.#{action_name}").downcase unless action_name == 'index')) %>
31
+ :type => t("admin.blog.submenu.comments.#{action_name.gsub('index', 'new')}").downcase) %>
32
32
  </h3>
33
33
  <% end %>
34
34
  <% end %>
@@ -0,0 +1,63 @@
1
+ <div id='actions'>
2
+ <h2><%= t('.details')%></h2>
3
+ <p>
4
+ <strong><%= t('.age') %>:</strong> <%= time_ago_in_words(@blog_comment.created_at) %>
5
+ </p>
6
+ <h2><%= t('.actions') %></h2>
7
+ <ul>
8
+ <li>
9
+ <%= link_to t('.back'), {:action => 'index'}, :class => "back_icon" %>
10
+ </li>
11
+ <li>
12
+ <%= link_to t('.reject'), rejected_admin_blog_comment_path(@blog_comment, :return_to => 'rejected'),
13
+ :class => 'comment_cross_icon' unless @blog_comment.rejected? %>
14
+ </li>
15
+ <li>
16
+ <%= link_to t('.approve'), approved_admin_blog_comment_path(@blog_comment, :return_to => 'approved'),
17
+ :class => 'comment_tick_icon' unless @blog_comment.approved? %>
18
+ </li>
19
+ </ul>
20
+ </div>
21
+ <div id='records'>
22
+ <h2><%= t('.comment') %></h2>
23
+ <table id='inquiry'>
24
+ <tr>
25
+ <td>
26
+ <strong><%= t('.blog_post') %></strong>
27
+ </td>
28
+ <td>
29
+ <%= link_to @blog_comment.post.title,
30
+ blog_post_url(@blog_comment.post, :anchor => "comment-#{@blog_comment.to_param}"),
31
+ :target => '_blank' %>
32
+ </td>
33
+ </tr>
34
+ <tr>
35
+ <td>
36
+ <strong><%= t('.from') %></strong>
37
+ </td>
38
+ <td>
39
+ <%= @blog_comment.name %> [<%= mail_to @blog_comment.email, @blog_comment.email, {:title => t('.click_to_email')} %>]
40
+ </td>
41
+ </tr>
42
+ <tr>
43
+ <td>
44
+ <strong><%= t('.date') %></strong>
45
+ </td>
46
+ <td>
47
+ <%= l(Date.parse(@blog_comment.created_at.to_s), :format => :long) %>
48
+ </td>
49
+ </tr>
50
+ <tr>
51
+ <td valign='top'>
52
+ <strong><%= t('.message') %></strong>
53
+ </td>
54
+ <td>
55
+ <p style='margin-top: 0px'>
56
+ <%= @blog_comment.message.gsub("\r\n\r\n", "\r\n").gsub("\r\n", "</p><p>") %>
57
+ </p>
58
+ </td>
59
+ </tr>
60
+ </table>
61
+ </div>
62
+
63
+ <% content_for :head, stylesheet_link_tag('refinery/refinerycms-blog') %>
@@ -1,5 +1,13 @@
1
1
  <% form_for [:admin, @blog_post] do |f| -%>
2
- <%= f.error_messages %>
2
+ <% if Rails.version < '3.0.0'%>
3
+ <%= f.error_messages %>
4
+ <% else %>
5
+ <%= render :partial => "/shared/admin/error_messages",
6
+ :locals => {
7
+ :object => f.object,
8
+ :include_object_name => true
9
+ } %>
10
+ <% end %>
3
11
 
4
12
  <div class='field'>
5
13
  <%= f.label :title -%>
@@ -11,6 +11,8 @@
11
11
  :title => t('.edit') %>
12
12
  <%= link_to refinery_icon_tag("delete.png"), admin_blog_post_path(post),
13
13
  :class => "cancel confirm-delete",
14
- :title => t('.delete') %>
14
+ :title => t('.delete'),
15
+ :'data-method' => 'delete',
16
+ :'data-confirm' => t('shared.admin.delete.message', :title => post.title) %>
15
17
  </span>
16
18
  </li>
@@ -0,0 +1,20 @@
1
+ <% content_for :body_content_title, @category.title %>
2
+
3
+ <% content_for :body_content_left do %>
4
+ <% if @category.posts.any? %>
5
+ <ul id="blog_posts">
6
+ <%= render :partial => "/blog/shared/post", :collection => @category.posts %>
7
+ </ul>
8
+ <% else %>
9
+ <p>
10
+ <%= t('.no_posts') %>
11
+ </p>
12
+ <% end %>
13
+ <% end %>
14
+
15
+ <% content_for :body_content_right do %>
16
+ <%= render :partial => "/blog/shared/categories" %>
17
+ <% end %>
18
+
19
+ <%= render :partial => "/shared/content_page" %>
20
+ <% content_for :head, stylesheet_link_tag('refinerycms-blog') %>