refinerycms-blog 1.0.rc16 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/blog/categories_controller.rb +2 -2
- data/app/controllers/blog/posts_controller.rb +23 -13
- data/app/controllers/blog_controller.rb +3 -2
- data/app/helpers/blog_posts_helper.rb +28 -0
- data/app/models/blog/comment_mailer.rb +1 -1
- data/app/models/blog_category.rb +4 -4
- data/app/models/blog_comment.rb +29 -20
- data/app/models/blog_post.rb +21 -12
- data/app/views/admin/blog/_submenu.html.erb +9 -4
- data/app/views/admin/blog/categories/_form.html.erb +3 -11
- data/app/views/admin/blog/categories/edit.html.erb +1 -1
- data/app/views/admin/blog/categories/index.html.erb +1 -1
- data/app/views/admin/blog/categories/new.html.erb +1 -1
- data/app/views/admin/blog/comments/_comment.html.erb +2 -2
- data/app/views/admin/blog/comments/index.html.erb +5 -5
- data/app/views/admin/blog/comments/show.html.erb +5 -2
- data/app/views/admin/blog/posts/_form.css.erb +7 -0
- data/app/views/admin/blog/posts/_form.html.erb +10 -30
- data/app/views/admin/blog/posts/_form.js.erb +13 -0
- data/app/views/admin/blog/posts/index.html.erb +1 -1
- data/app/views/blog/categories/show.html.erb +1 -1
- data/app/views/blog/posts/_nav.html.erb +13 -0
- data/app/views/blog/posts/_post.html.erb +34 -0
- data/app/views/blog/posts/archive.html.erb +19 -0
- data/app/views/blog/posts/index.html.erb +4 -1
- data/app/views/blog/posts/show.html.erb +28 -47
- data/app/views/blog/shared/_categories.html.erb +1 -1
- data/app/views/blog/shared/_post.html.erb +16 -6
- data/app/views/blog/shared/_posts.html.erb +1 -1
- data/app/views/blog/shared/_rss_feed.html.erb +1 -1
- data/config/routes.rb +26 -64
- data/{spec → features/support}/factories/blog_categories.rb +2 -2
- data/{spec → features/support}/factories/blog_comments.rb +1 -1
- data/{spec → features/support}/factories/blog_posts.rb +1 -1
- data/features/support/paths.rb +24 -0
- data/generators/{refinery_blog/refinery_blog_generator.rb → refinerycms_blog/refinerycms_blog_generator.rb} +4 -4
- data/generators/{refinery_blog → refinerycms_blog}/templates/db/migrate/migration.rb +0 -0
- data/generators/{refinery_blog → refinerycms_blog}/templates/db/seeds/seed.rb +0 -0
- data/lib/gemspec.rb +2 -2
- data/lib/generators/{refinery_blog → refinerycms_blog}/templates/db/migrate/migration_number_create_singular_name.rb +0 -0
- data/lib/generators/{refinery_blog → refinerycms_blog}/templates/db/seeds/seed.rb +0 -0
- data/lib/generators/{refinery_blog_generator.rb → refinerycms_blog_generator.rb} +3 -3
- data/lib/refinerycms-blog.rb +2 -2
- data/public/javascripts/refinerycms-blog.js +25 -0
- data/public/stylesheets/refinerycms-blog.css +72 -1
- data/readme.md +18 -8
- data/spec/models/blog_categories_spec.rb +7 -6
- data/spec/models/blog_comments_spec.rb +7 -6
- data/spec/models/blog_posts_spec.rb +2 -1
- metadata +25 -24
@@ -1,29 +1,23 @@
|
|
1
1
|
class Blog::PostsController < BlogController
|
2
2
|
|
3
|
-
before_filter :find_all_blog_posts
|
4
|
-
before_filter :find_blog_post, :only => [:show, :comment]
|
3
|
+
before_filter :find_all_blog_posts, :except => [:archive]
|
4
|
+
before_filter :find_blog_post, :only => [:show, :comment, :update_nav]
|
5
5
|
|
6
6
|
def index
|
7
|
-
respond_to
|
8
|
-
format.html
|
9
|
-
format.rss
|
10
|
-
end
|
7
|
+
# TODO: respond_to block
|
11
8
|
end
|
12
9
|
|
13
10
|
def show
|
14
11
|
@blog_comment = BlogComment.new
|
15
|
-
|
12
|
+
|
13
|
+
# TODO: respond_to block
|
16
14
|
end
|
17
15
|
|
18
16
|
def comment
|
19
17
|
if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid?
|
20
18
|
if BlogComment::Moderation.enabled? or @blog_comment.ham?
|
21
19
|
begin
|
22
|
-
|
23
|
-
Blog::CommentMailer.deliver_notification(@blog_comment, request)
|
24
|
-
else
|
25
|
-
Blog::CommentMailer.notification(@blog_comment, request).deliver
|
26
|
-
end
|
20
|
+
Blog::CommentMailer.deliver_notification(@blog_comment, request)
|
27
21
|
rescue
|
28
22
|
logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n"
|
29
23
|
end
|
@@ -42,10 +36,26 @@ class Blog::PostsController < BlogController
|
|
42
36
|
end
|
43
37
|
end
|
44
38
|
|
39
|
+
def archive
|
40
|
+
date = "#{params[:month]}/#{params[:year]}"
|
41
|
+
@archive_date = Time.parse(date)
|
42
|
+
@blog_posts = BlogPost.live.by_archive(@archive_date).paginate({
|
43
|
+
:page => params[:page],
|
44
|
+
:per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10)
|
45
|
+
})
|
46
|
+
# TODO: respond_to block
|
47
|
+
end
|
48
|
+
|
45
49
|
protected
|
46
50
|
|
47
51
|
def find_blog_post
|
48
|
-
@blog_post = BlogPost.
|
52
|
+
unless (@blog_post = BlogPost.find(params[:id])).try(:live?)
|
53
|
+
if refinery_user? and current_user.authorized_plugins.include?("refinerycms_blog")
|
54
|
+
@blog_post = BlogPost.find(params[:id])
|
55
|
+
else
|
56
|
+
error_404
|
57
|
+
end
|
58
|
+
end
|
49
59
|
end
|
50
60
|
|
51
61
|
def find_all_blog_posts
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module BlogPostsHelper
|
2
|
+
def blog_archive_list
|
3
|
+
posts = BlogPost.select('published_at').all_previous
|
4
|
+
return nil if posts.blank?
|
5
|
+
html = '<section id="blog_archive_list"><h2>Archives</h2><nav><ul>'
|
6
|
+
links = []
|
7
|
+
|
8
|
+
posts.each do |e|
|
9
|
+
links << e.published_at.strftime('%m/%Y')
|
10
|
+
end
|
11
|
+
links.uniq!
|
12
|
+
links.each do |l|
|
13
|
+
year = l.split('/')[1]
|
14
|
+
month = l.split('/')[0]
|
15
|
+
count = BlogPost.by_archive(Time.parse(l)).size
|
16
|
+
text = "#{Date::MONTHNAMES[month.to_i]} #{year} (#{count})"
|
17
|
+
html += "<li>"
|
18
|
+
html += link_to(text, archive_blog_posts_path(:year => year, :month => month))
|
19
|
+
html += "</li>"
|
20
|
+
end
|
21
|
+
html += '</ul></nav></section>'
|
22
|
+
html.html_safe
|
23
|
+
end
|
24
|
+
|
25
|
+
def next_or_previous?(post)
|
26
|
+
post.next.present? or post.prev.present?
|
27
|
+
end
|
28
|
+
end
|
@@ -1 +1 @@
|
|
1
|
-
require File.expand_path('../../../mailers/blog/comment_mailer', __FILE__)
|
1
|
+
require File.expand_path('../../../mailers/blog/comment_mailer', __FILE__)
|
data/app/models/blog_category.rb
CHANGED
@@ -8,16 +8,16 @@ class BlogCategory < ActiveRecord::Base
|
|
8
8
|
validates_uniqueness_of :title
|
9
9
|
|
10
10
|
has_friendly_id :title, :use_slug => true
|
11
|
-
|
11
|
+
|
12
12
|
# this might be able to be optimised a little more
|
13
13
|
def post_count
|
14
14
|
count = 0
|
15
|
-
|
15
|
+
|
16
16
|
self.posts.each do |p|
|
17
17
|
count += 1 if p.live?
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
count
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
end
|
data/app/models/blog_comment.rb
CHANGED
@@ -14,15 +14,9 @@ class BlogComment < ActiveRecord::Base
|
|
14
14
|
validates_format_of :email,
|
15
15
|
:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
17
|
+
named_scope :unmoderated, :conditions => {:state => nil}
|
18
|
+
named_scope :approved, :conditions => {:state => 'approved'}
|
19
|
+
named_scope :rejected, :conditions => {:state => 'rejected'}
|
26
20
|
|
27
21
|
def approve!
|
28
22
|
self.update_attribute(:state, 'approved')
|
@@ -54,17 +48,22 @@ class BlogComment < ActiveRecord::Base
|
|
54
48
|
class << self
|
55
49
|
def enabled?
|
56
50
|
RefinerySetting.find_or_set(:comment_moderation, true, {
|
57
|
-
:scoping =>
|
51
|
+
:scoping => 'blog',
|
58
52
|
:restricted => false
|
59
53
|
})
|
60
54
|
end
|
61
55
|
|
62
56
|
def toggle!
|
63
|
-
|
64
|
-
:value => !
|
65
|
-
:scoping =>
|
57
|
+
new_value = {
|
58
|
+
:value => !BlogComment::Moderation.enabled?,
|
59
|
+
:scoping => 'blog',
|
66
60
|
:restricted => false
|
67
61
|
}
|
62
|
+
if RefinerySetting.respond_to?(:set)
|
63
|
+
RefinerySetting.set(:comment_moderation, new_value)
|
64
|
+
else
|
65
|
+
RefinerySetting[:comment_moderation] = new_value
|
66
|
+
end
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
@@ -74,34 +73,44 @@ class BlogComment < ActiveRecord::Base
|
|
74
73
|
def recipients
|
75
74
|
RefinerySetting.find_or_set(:comment_notification_recipients, (Role[:refinery].users.first.email rescue ''),
|
76
75
|
{
|
77
|
-
:scoping =>
|
76
|
+
:scoping => 'blog',
|
78
77
|
:restricted => false
|
79
78
|
})
|
80
79
|
end
|
81
80
|
|
82
81
|
def recipients=(emails)
|
83
|
-
|
82
|
+
new_value = {
|
84
83
|
:value => emails,
|
85
|
-
:scoping =>
|
84
|
+
:scoping => 'blog',
|
86
85
|
:restricted => false
|
87
86
|
}
|
87
|
+
if RefinerySetting.respond_to?(:set)
|
88
|
+
RefinerySetting.set(:comment_notification_recipients, new_value)
|
89
|
+
else
|
90
|
+
RefinerySetting[:comment_notification_recipients] = new_value
|
91
|
+
end
|
88
92
|
end
|
89
93
|
|
90
94
|
def subject
|
91
95
|
RefinerySetting.find_or_set(:comment_notification_subject, "New inquiry from your website", {
|
92
|
-
:scoping =>
|
96
|
+
:scoping => 'blog',
|
93
97
|
:restricted => false
|
94
98
|
})
|
95
99
|
end
|
96
100
|
|
97
101
|
def subject=(subject_line)
|
98
|
-
|
102
|
+
new_value = {
|
99
103
|
:value => subject_line,
|
100
|
-
:scoping =>
|
104
|
+
:scoping => 'blog',
|
101
105
|
:restricted => false
|
102
106
|
}
|
107
|
+
if RefinerySetting.respond_to?(:set)
|
108
|
+
RefinerySetting.set(:comment_notification_subject, new_value)
|
109
|
+
else
|
110
|
+
RefinerySetting[:comment_notification_subject] = new_value
|
111
|
+
end
|
103
112
|
end
|
104
113
|
end
|
105
114
|
end
|
106
115
|
|
107
|
-
end
|
116
|
+
end
|
data/app/models/blog_post.rb
CHANGED
@@ -10,18 +10,27 @@ class BlogPost < ActiveRecord::Base
|
|
10
10
|
|
11
11
|
has_friendly_id :title, :use_slug => true
|
12
12
|
|
13
|
-
|
13
|
+
named_scope :by_archive, lambda { |archive_date| {:conditions => ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month], :order => "published_at DESC"} }
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
named_scope :all_previous, :conditions => ['published_at <= ?', Time.now.beginning_of_month], :order => "published_at DESC"
|
16
|
+
|
17
|
+
named_scope :live, lambda { {:conditions => ["published_at < ? and draft = ?", Time.now, false], :order => "published_at DESC"} }
|
18
|
+
|
19
|
+
named_scope :previous, lambda { |i| { :conditions => ["published_at < ?", i.published_at], :order => "published_at DESC", :limit => 1 } }
|
20
|
+
named_scope :next, lambda { |i| { :condtions => ["published_at > ?", i.published_at], :order => "published_at ASC", :limit => 1 } }
|
21
|
+
|
22
|
+
def next
|
23
|
+
self.class.next(self).first
|
24
|
+
end
|
25
|
+
|
26
|
+
def prev
|
27
|
+
self.class.previous(self).first
|
19
28
|
end
|
20
|
-
|
29
|
+
|
21
30
|
def live?
|
22
31
|
!draft and published_at <= Time.now
|
23
32
|
end
|
24
|
-
|
33
|
+
|
25
34
|
def category_ids=(ids)
|
26
35
|
self.categories = ids.reject{|id| id.blank?}.collect {|c_id|
|
27
36
|
BlogCategory.find(c_id.to_i) rescue nil
|
@@ -31,21 +40,21 @@ class BlogPost < ActiveRecord::Base
|
|
31
40
|
class << self
|
32
41
|
def comments_allowed?
|
33
42
|
RefinerySetting.find_or_set(:comments_allowed, true, {
|
34
|
-
:scoping =>
|
43
|
+
:scoping => 'blog'
|
35
44
|
})
|
36
45
|
end
|
37
46
|
end
|
38
|
-
|
47
|
+
|
39
48
|
module ShareThis
|
40
49
|
DEFAULT_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
41
|
-
|
50
|
+
|
42
51
|
class << self
|
43
52
|
def key
|
44
53
|
RefinerySetting.find_or_set(:share_this_key, BlogPost::ShareThis::DEFAULT_KEY, {
|
45
|
-
:scoping =>
|
54
|
+
:scoping => 'blog'
|
46
55
|
})
|
47
56
|
end
|
48
|
-
|
57
|
+
|
49
58
|
def enabled?
|
50
59
|
key = BlogPost::ShareThis.key
|
51
60
|
key.present? and key != BlogPost::ShareThis::DEFAULT_KEY
|
@@ -78,7 +78,12 @@
|
|
78
78
|
</ul>
|
79
79
|
|
80
80
|
</nav>
|
81
|
-
<%
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
<% if Refinery.version < '0.9.9' %>
|
82
|
+
<% content_for :head do %>
|
83
|
+
<%= stylesheet_link_tag('refinery/refinerycms-blog') %>
|
84
|
+
<%# this javascript is not even required in >= 0.9.9 because we made this sort of menu core. %>
|
85
|
+
<%= javascript_include_tag('refinery/refinerycms-blog') %>
|
86
|
+
<% end %>
|
87
|
+
<% else %>
|
88
|
+
<% content_for :stylesheets, stylesheet_link_tag('refinery/refinerycms-blog')%>
|
89
|
+
<% end %>
|
@@ -1,14 +1,6 @@
|
|
1
1
|
<% form_for [:admin, @blog_category] do |f| -%>
|
2
|
-
|
3
|
-
|
4
|
-
<% else %>
|
5
|
-
<%= render :partial => "/shared/admin/error_messages",
|
6
|
-
:locals => {
|
7
|
-
:object => f.object,
|
8
|
-
:include_object_name => true
|
9
|
-
} %>
|
10
|
-
<% end %>
|
11
|
-
|
2
|
+
<%= f.error_messages %>
|
3
|
+
|
12
4
|
<div class='field'>
|
13
5
|
<%= f.label :title -%>
|
14
6
|
<%= f.text_field :title, :class => 'larger widest' -%>
|
@@ -20,4 +12,4 @@
|
|
20
12
|
:continue_editing => false,
|
21
13
|
:delete_title => t('admin.blog.categories.category.delete')
|
22
14
|
} %>
|
23
|
-
<% end %>
|
15
|
+
<% end %>
|
@@ -1 +1 @@
|
|
1
|
-
<%= render :partial => "form" %>
|
1
|
+
<%= render :partial => "form" %>
|
@@ -1 +1 @@
|
|
1
|
-
<%= render :partial => "form" %>
|
1
|
+
<%= render :partial => "form" %>
|
@@ -10,10 +10,10 @@
|
|
10
10
|
:target => "_blank" unless comment.unmoderated? %>
|
11
11
|
<%= link_to refinery_icon_tag('zoom.png'), admin_blog_comment_path(comment),
|
12
12
|
:title => t('.read') %>
|
13
|
-
<%= link_to refinery_icon_tag("cross.png"),
|
13
|
+
<%= link_to refinery_icon_tag("cross.png"),
|
14
14
|
rejected_admin_blog_comment_path(comment, :return_to => request.path.split('/').last.gsub(/^comments$/, 'index')),
|
15
15
|
:title => t('.reject') unless comment.rejected? %>
|
16
|
-
<%= link_to refinery_icon_tag("tick.png"),
|
16
|
+
<%= link_to refinery_icon_tag("tick.png"),
|
17
17
|
approved_admin_blog_comment_path(comment, :return_to => request.path.split('/').last.gsub(/^comments$/, 'index')),
|
18
18
|
:title => t('.approve') unless comment.approved? %>
|
19
19
|
</span>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
<% if searching? %>
|
4
4
|
<h2><%= t('shared.admin.search.results_for', :query => params[:search]) %></h2>
|
5
5
|
<% if @blog_comments.any? %>
|
6
|
-
<%=# will_paginate @blog_comments
|
6
|
+
<%=# will_paginate @blog_comments
|
7
7
|
%>
|
8
8
|
|
9
9
|
<ul>
|
@@ -11,19 +11,19 @@
|
|
11
11
|
:collection => @blog_comments %>
|
12
12
|
</ul>
|
13
13
|
|
14
|
-
<%=# will_paginate @blog_comments
|
14
|
+
<%=# will_paginate @blog_comments
|
15
15
|
%>
|
16
16
|
<% else %>
|
17
17
|
<p><%= t('admin.search_no_results') %></p>
|
18
18
|
<% end %>
|
19
19
|
<% else %>
|
20
20
|
<% if @blog_comments.any? %>
|
21
|
-
<%=# will_paginate @blog_comments
|
21
|
+
<%=# will_paginate @blog_comments
|
22
22
|
%>
|
23
23
|
|
24
24
|
<%= render :partial => "sortable_list" %>
|
25
25
|
|
26
|
-
<%=# will_paginate @blog_comments
|
26
|
+
<%=# will_paginate @blog_comments
|
27
27
|
%>
|
28
28
|
<% else %>
|
29
29
|
<h3>
|
@@ -32,4 +32,4 @@
|
|
32
32
|
</h3>
|
33
33
|
<% end %>
|
34
34
|
<% end %>
|
35
|
-
</div>
|
35
|
+
</div>
|
@@ -59,5 +59,8 @@
|
|
59
59
|
</tr>
|
60
60
|
</table>
|
61
61
|
</div>
|
62
|
-
|
63
|
-
<% content_for :head, stylesheet_link_tag('refinery/refinerycms-blog') %>
|
62
|
+
<% if Refinery.version < '0.9.9' %>
|
63
|
+
<% content_for :head, stylesheet_link_tag('refinery/refinerycms-blog') %>
|
64
|
+
<% else %>
|
65
|
+
<% content_for :stylesheets, stylesheet_link_tag('refinery/refinerycms-blog') %>
|
66
|
+
<% end %>
|
@@ -1,13 +1,5 @@
|
|
1
1
|
<% form_for [:admin, @blog_post] do |f| -%>
|
2
|
-
|
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 %>
|
2
|
+
<%= f.error_messages %>
|
11
3
|
|
12
4
|
<div class='field'>
|
13
5
|
<%= f.label :title -%>
|
@@ -57,25 +49,13 @@
|
|
57
49
|
:delete_title => t('admin.blog.posts.post.delete')
|
58
50
|
} %>
|
59
51
|
<% end -%>
|
60
|
-
<% content_for :head do %>
|
61
|
-
<style type='text/css'>
|
62
|
-
ul.blog_categories, ul.blog_categories li {
|
63
|
-
list-style: none;
|
64
|
-
margin: 0px;
|
65
|
-
padding: 0px;
|
66
|
-
}
|
67
|
-
</style>
|
68
|
-
<script type='text/javascript'>
|
69
|
-
$(document).ready(function(){
|
70
|
-
$('#toggle_advanced_options').click(function(e){
|
71
|
-
e.preventDefault();
|
72
|
-
|
73
|
-
$('#more_options').animate({opacity: 'toggle', height: 'toggle'}, 250);
|
74
52
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
<%
|
53
|
+
<% if Refinery.version < '0.9.9' %>
|
54
|
+
<% content_for :head do %>
|
55
|
+
<%= render :partial => 'form.css' %>
|
56
|
+
<%= render :partial => 'form.js' %>
|
57
|
+
<% end %>
|
58
|
+
<% else %>
|
59
|
+
<% content_for :stylesheets, render(:partial => 'form.css') -%>
|
60
|
+
<% content_for :javascripts, render(:partial => 'form.js') -%>
|
61
|
+
<% end %>
|