tb_blog 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Readme.md +1 -15
- data/app/controllers/admin/posts_controller.rb +26 -2
- data/app/controllers/concerns/blog_url_helpers.rb +1 -10
- data/app/controllers/posts_controller.rb +0 -31
- data/app/helpers/admin/posts_helper.rb +12 -1
- data/app/helpers/blog_helper.rb +5 -0
- data/app/models/spud/spud_post_model.rb +18 -5
- data/app/views/admin/posts/_form.html.erb +6 -1
- data/app/views/admin/posts/index.html.erb +15 -7
- data/app/views/posts/_disqus.html.erb +18 -0
- data/app/views/posts/index.html.erb +8 -1
- data/app/views/posts/show.html.erb +4 -18
- data/config/routes.rb +1 -11
- data/db/migrate/20151015151133_add_custom_author_to_post.rb +5 -0
- data/db/migrate/20160216144708_add_identifier_to_spud_posts.rb +6 -0
- data/db/optional/20160216153113_drop_spud_post_comments.rb +29 -0
- data/lib/spud_blog/configuration.rb +3 -6
- data/lib/spud_blog/engine.rb +4 -12
- data/lib/spud_blog/version.rb +1 -1
- data/spec/controllers/admin/posts_controller_spec.rb +23 -1
- data/spec/controllers/posts_controller_spec.rb +0 -26
- data/spec/dummy/config/application.rb +5 -0
- data/spec/dummy/db/migrate/20151015154040_add_custom_author_to_post.tb_blog.rb +6 -0
- data/spec/dummy/db/migrate/20160215174632_add_requires_password_change_to_spud_users.tb_core.rb +6 -0
- data/spec/dummy/db/migrate/20160215174633_create_tb_redirects.tb_redirects.rb +15 -0
- data/spec/dummy/db/migrate/20160216150847_add_identifier_to_spud_posts.tb_blog.rb +7 -0
- data/spec/dummy/db/migrate/20160216153113_drop_spud_post_comments.rb +29 -0
- data/spec/dummy/db/schema.rb +37 -40
- data/spec/helpers/admin/posts_helper_spec.rb +15 -0
- data/spec/helpers/blog_helper_spec.rb +13 -0
- data/spec/models/spud_post_spec.rb +19 -0
- data/spec/rails_helper.rb +1 -1
- metadata +33 -25
- data/app/assets/javascripts/admin/blog/post_comments.js +0 -37
- data/app/controllers/admin/post_comments_controller.rb +0 -80
- data/app/helpers/admin/post_comments_helper.rb +0 -3
- data/app/models/spud_post_comment.rb +0 -42
- data/app/views/admin/post_comments/index.html.erb +0 -60
- data/db/migrate/20120125181359_create_spud_post_comments.rb +0 -13
- data/db/migrate/20120413020437_add_comments_counter_to_spud_posts.rb +0 -12
- data/db/migrate/20120825142547_add_spam_fields_to_spud_post_comments.rb +0 -8
- data/db/migrate/20120825144506_add_permalink_to_spud_post_comments.rb +0 -5
- data/db/migrate/20140811152252_add_blog_key_to_spud_post_comments.rb +0 -6
- data/spec/factories/spud_user_factories.rb +0 -31
- /data/app/assets/images/{spud/admin → admin}/news_thumb.png +0 -0
- /data/app/assets/images/{spud/admin → admin}/posts_thumb.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c07afcec9d3eb4f9a2038a5dc331496148f6c40
|
4
|
+
data.tar.gz: 5921d46580058b1faf06f56f81c2b700b48e2a27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 971e90879dde94f36ed70c28019f57c50610a4b8d829b93348a72e9af54d0e01d0f109aa35803d72f2cdf4290411b3fe3eaa11630ddf09179f30311073f59750
|
7
|
+
data.tar.gz: 78244e37a50fcfbbd516554e8554047d9f9dbf01dfa6da0d887c0160ce0098613a429f4fa649358b8630f04b2acb817873a6efbb08157f52685493da2ce32e20
|
data/Readme.md
CHANGED
@@ -28,7 +28,7 @@ TB Blog current accepts the following configuration options.
|
|
28
28
|
config.blog_path = 'blog'
|
29
29
|
config.news_path = 'news'
|
30
30
|
config.posts_per_page = 5
|
31
|
-
|
31
|
+
config.disqus_shortname = ''
|
32
32
|
end
|
33
33
|
|
34
34
|
## Customizing Views
|
@@ -120,20 +120,6 @@ That's it! You may now begin customizing the post class.
|
|
120
120
|
p = SpudPost.first
|
121
121
|
puts p.hello_world # outputs "Hello, World!"
|
122
122
|
|
123
|
-
## Akismet Support
|
124
|
-
|
125
|
-
TB Blog Engine now supports spam comment filtering using akismet. All you have to do is configure the rakismet gem and enable_rakismet in the spud_blog configuration. Add the following to your application.rb file
|
126
|
-
|
127
|
-
Spud::Blog.configure do |config|
|
128
|
-
config.enable_rakismet = true
|
129
|
-
end
|
130
|
-
config.rakismet.key = "your key here"
|
131
|
-
config.rakismet.url = 'http://yourdomain.com/'
|
132
|
-
|
133
|
-
Also make sure to add the rakismet gem to your gemfile
|
134
|
-
|
135
|
-
gem 'rakismet'
|
136
|
-
|
137
123
|
Testing
|
138
124
|
-----------------
|
139
125
|
|
@@ -4,6 +4,7 @@ class Admin::PostsController < Admin::ApplicationController
|
|
4
4
|
respond_to :html, :xml, :json
|
5
5
|
before_action :load_blog
|
6
6
|
before_action :find_post, :only => [:show, :edit, :update, :destroy]
|
7
|
+
around_action :create_redirect_if_necessary, :only => :update
|
7
8
|
|
8
9
|
def index
|
9
10
|
@posts = SpudPost.for_blog(params[:blog_key]).ordered.paginate(:page => params[:page], :per_page => 15)
|
@@ -58,7 +59,7 @@ private
|
|
58
59
|
end
|
59
60
|
|
60
61
|
def post_params
|
61
|
-
permitted = [:published_at, :title, :content, :spud_user_id, :url_name, :visible, :comments_enabled, :meta_keywords, :meta_description, :content_format, :category_ids => []]
|
62
|
+
permitted = [:published_at, :title, :content, :spud_user_id, :url_name, :visible, :comments_enabled, :meta_keywords, :meta_description, :content_format, :custom_author, :category_ids => []]
|
62
63
|
if Spud::Blog.permitted_attributes.present?
|
63
64
|
permitted = permitted + Spud::Blog.permitted_attributes
|
64
65
|
end
|
@@ -73,8 +74,31 @@ private
|
|
73
74
|
redirect_to admin_root_path
|
74
75
|
return false
|
75
76
|
else
|
76
|
-
|
77
|
+
act_as_app "#{@config.name} Posts".parameterize.underscore.to_sym
|
77
78
|
add_breadcrumb "#{@config.name} Posts", admin_posts_path(blog_key: @config.key)
|
78
79
|
end
|
79
80
|
end
|
81
|
+
|
82
|
+
# Create a redirect if the post URL has changed
|
83
|
+
#
|
84
|
+
# Normally this sort of thing might belong in a model after_update hook, but the model
|
85
|
+
# layer has no knowledge of URL helpers.
|
86
|
+
#
|
87
|
+
def create_redirect_if_necessary
|
88
|
+
@_redirect_source = post_path(@post.url_name, :blog_key => @post.blog_key, :only_path => true)
|
89
|
+
yield
|
90
|
+
ensure
|
91
|
+
if @post.errors.empty?
|
92
|
+
@_redirect_destination = post_path(@post.url_name, :blog_key => @post.blog_key, :only_path => true)
|
93
|
+
if @_redirect_source != @_redirect_destination
|
94
|
+
TbRedirect.create_smart({
|
95
|
+
:source => @_redirect_source,
|
96
|
+
:destination => @_redirect_destination,
|
97
|
+
:created_by => 'blog',
|
98
|
+
:owner => @post
|
99
|
+
})
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
80
104
|
end
|
@@ -3,7 +3,7 @@ module BlogUrlHelpers
|
|
3
3
|
|
4
4
|
included do
|
5
5
|
helper_method :posts_path, :post_path, :post_category_path, :post_archive_path,
|
6
|
-
:admin_posts_path, :admin_post_path, :new_admin_post_path, :edit_admin_post_path
|
6
|
+
:admin_posts_path, :admin_post_path, :new_admin_post_path, :edit_admin_post_path
|
7
7
|
end
|
8
8
|
|
9
9
|
def posts_path(opts={})
|
@@ -48,13 +48,4 @@ module BlogUrlHelpers
|
|
48
48
|
url_for :controller => '/admin/posts', :action => 'edit', :id => post.id, :blog_key => post.blog_key
|
49
49
|
end
|
50
50
|
|
51
|
-
def admin_post_comments_path(blog_key: nil)
|
52
|
-
blog_key ||= params[:blog_key]
|
53
|
-
url_for :controller => '/admin/post_comments', :action => 'index', :blog_key => blog_key
|
54
|
-
end
|
55
|
-
|
56
|
-
def admin_post_post_comments_path(post)
|
57
|
-
url_for :controller => '/admin/post_comments', :action => 'index', :post_id => post.id, :blog_key => post.blog_key
|
58
|
-
end
|
59
|
-
|
60
51
|
end
|
@@ -52,38 +52,11 @@ class PostsController < ApplicationController
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def show
|
55
|
-
if @post.comments_enabled
|
56
|
-
@comment = SpudPostComment.new()
|
57
|
-
end
|
58
55
|
respond_with @post do |format|
|
59
56
|
format.html { render view_for_action 'show' }
|
60
57
|
end
|
61
58
|
end
|
62
59
|
|
63
|
-
def create_comment
|
64
|
-
unless params[:comment_validation].blank? # trap spam bots
|
65
|
-
render :nothing => true
|
66
|
-
return
|
67
|
-
end
|
68
|
-
@comment = @post.comments.new(comment_params)
|
69
|
-
@comment.user_agent = request.env["HTTP_USER_AGENT"]
|
70
|
-
@comment.user_ip = request.remote_ip
|
71
|
-
@comment.referrer = request.referrer
|
72
|
-
@comment.approved = Spud::Blog.default_comment_approval
|
73
|
-
@comment.permalink = post_path(@post.url_name)
|
74
|
-
if @comment.save
|
75
|
-
if @comment.approved?
|
76
|
-
flash[:notice] = 'Your comment has been posted.'
|
77
|
-
else
|
78
|
-
flash[:notice] = 'Your comment has been saved and will appear after being reviewed by an administrator.'
|
79
|
-
end
|
80
|
-
@comment = SpudPostComment.new()
|
81
|
-
end
|
82
|
-
respond_with @comment do |format|
|
83
|
-
format.html { render view_for_action 'show' }
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
60
|
private
|
88
61
|
|
89
62
|
def find_post
|
@@ -93,10 +66,6 @@ private
|
|
93
66
|
end
|
94
67
|
end
|
95
68
|
|
96
|
-
def comment_params
|
97
|
-
params.require(:spud_post_comment).permit(:author, :content)
|
98
|
-
end
|
99
|
-
|
100
69
|
def load_page_number
|
101
70
|
page = 1
|
102
71
|
if params[:page].present?
|
@@ -11,4 +11,15 @@ module Admin::PostsHelper
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
def link_to_disqus_comment_count(post)
|
15
|
+
# TODO: It would be great to link directly to the thread
|
16
|
+
# ie: https://myblog.disqus.com/admin/moderate/#/all/search/thread:4584301535
|
17
|
+
#
|
18
|
+
# However, we do not know the thread ID at this time. We may be able to fetch it
|
19
|
+
# via the Disqus JavaScript API.
|
20
|
+
#
|
21
|
+
return link_to 'Comments', "https://#{Spud::Blog.disqus_shortname}.disqus.com/admin/moderate/#/all", :target => :blank, :class => 'disqus-comment-count',
|
22
|
+
:data => {:disqus_identifier => post.identifier}
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/app/helpers/blog_helper.rb
CHANGED
@@ -22,4 +22,9 @@ module BlogHelper
|
|
22
22
|
return tag :link, :rel => 'alternate', :type => 'application/rss+xml', :title => "#{Spud::Core.site_name} Blog RSS", :href => posts_path(:format => :rss)
|
23
23
|
end
|
24
24
|
|
25
|
+
def disqus_comment_count_for_post(post)
|
26
|
+
return content_tag :span, 'Comments', :class => 'disqus-comment-count',
|
27
|
+
:data => {:disqus_identifier => post.identifier}
|
28
|
+
end
|
29
|
+
|
25
30
|
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
class Spud::SpudPostModel < ActiveRecord::Base
|
2
|
+
include TbRedirects::HasRedirects
|
3
|
+
|
2
4
|
self.table_name = 'spud_posts'
|
3
5
|
|
4
6
|
spud_searchable
|
@@ -10,11 +12,6 @@ class Spud::SpudPostModel < ActiveRecord::Base
|
|
10
12
|
:source => :spud_post_category
|
11
13
|
|
12
14
|
belongs_to :author, :class_name => 'SpudUser', :foreign_key => 'spud_user_id'
|
13
|
-
has_many :comments, :class_name => 'SpudPostComment', :inverse_of => :post, :foreign_key => 'spud_post_id'
|
14
|
-
has_many :pending_comments, ->{ where(:spam => [nil, false], :approved => false) }, :class_name => "SpudPostComment", :foreign_key => 'spud_post_id'
|
15
|
-
has_many :visible_comments, ->{ where(:spam => [nil,false], :approved => true) }, :class_name => 'SpudPostComment', :foreign_key => 'spud_post_id'
|
16
|
-
has_many :spam_comments, ->{ where(:spam => true) }, :class_name => "SpudPostComment", :foreign_key => 'spud_post_id'
|
17
|
-
has_many :spud_permalinks, :as => :attachment
|
18
15
|
|
19
16
|
scope :blog_posts, ->{ for_blog('blog') }
|
20
17
|
scope :news_posts, ->{ for_blog('news') }
|
@@ -35,6 +32,7 @@ class Spud::SpudPostModel < ActiveRecord::Base
|
|
35
32
|
validates :url_name, :presence => true, :uniqueness => true, :format => {:with => /\A[\w\-]+\z/, :message => 'must contain only letters, numbers, and dashes'}
|
36
33
|
validates_uniqueness_of :url_name
|
37
34
|
before_validation :set_url_name
|
35
|
+
before_validation :set_identifier
|
38
36
|
|
39
37
|
acts_as_tb_liquid_content
|
40
38
|
|
@@ -112,6 +110,14 @@ class Spud::SpudPostModel < ActiveRecord::Base
|
|
112
110
|
return self.categories.collect{ |c| c.name }.join(', ')
|
113
111
|
end
|
114
112
|
|
113
|
+
def author_name
|
114
|
+
if self.custom_author.present?
|
115
|
+
self.custom_author
|
116
|
+
else
|
117
|
+
self.author.full_name
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
115
121
|
private
|
116
122
|
|
117
123
|
def set_url_name
|
@@ -120,4 +126,11 @@ private
|
|
120
126
|
end
|
121
127
|
end
|
122
128
|
|
129
|
+
def set_identifier
|
130
|
+
if identifier.blank?
|
131
|
+
self.identifier = SecureRandom.uuid
|
132
|
+
end
|
133
|
+
return true
|
134
|
+
end
|
135
|
+
|
123
136
|
end
|
@@ -26,7 +26,12 @@
|
|
26
26
|
<% else %>
|
27
27
|
<%= f.hidden_field :spud_user_id %>
|
28
28
|
<% end %>
|
29
|
-
|
29
|
+
<div class="form-group">
|
30
|
+
<%= f.label :custom_author, 'Custom Author Display', :class => "col-sm-2 control-label" %>
|
31
|
+
<div class="col-sm-10">
|
32
|
+
<%= f.text_field :custom_author, :class=>'form-control', :placeholder => 'Author Display' %>
|
33
|
+
</div>
|
34
|
+
</div>
|
30
35
|
<div class="form-group">
|
31
36
|
<%= f.label :visible, :class => 'col-sm-2 control-label' %>
|
32
37
|
<div class="col-sm-10">
|
@@ -13,7 +13,9 @@
|
|
13
13
|
</div>
|
14
14
|
<div class="form-group">
|
15
15
|
<%= link_to "Manage Categories", admin_post_categories_path, :class => 'btn btn-default spud-blog-manage-categories', :title => 'Manage Categories' %>
|
16
|
-
|
16
|
+
<% if Spud::Blog.disqus_shortname %>
|
17
|
+
<%= link_to "Manage Comments", "https://#{Spud::Blog.disqus_shortname}.disqus.com/admin/moderate/#/all", :target => :blank, :class => 'btn btn-default', :title => 'Manage Comments' %>
|
18
|
+
<% end %>
|
17
19
|
<%= link_to "New Post", new_admin_post_path, :class => "btn btn-primary", :title => "New Post" %>
|
18
20
|
</div>
|
19
21
|
<% end %>
|
@@ -27,7 +29,9 @@
|
|
27
29
|
<th>Title</th>
|
28
30
|
<th>Author</th>
|
29
31
|
<th>Published At</th>
|
30
|
-
|
32
|
+
<% if Spud::Blog.disqus_shortname %>
|
33
|
+
<th>Comments</th>
|
34
|
+
<% end %>
|
31
35
|
<th> </th>
|
32
36
|
</tr>
|
33
37
|
</thead>
|
@@ -42,12 +46,13 @@
|
|
42
46
|
<span class="badge">Draft</span>
|
43
47
|
<% end %>
|
44
48
|
</td>
|
45
|
-
<td><%= post.
|
49
|
+
<td><%= post.author_name %></td>
|
46
50
|
<td><%= post.published_at.strftime('%m/%d/%Y') %></td>
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
+
<% if Spud::Blog.disqus_shortname %>
|
52
|
+
<td>
|
53
|
+
<%= link_to_disqus_comment_count(post) %>
|
54
|
+
</td>
|
55
|
+
<% end %>
|
51
56
|
<td class="table-actions">
|
52
57
|
<%= link_to 'Edit', edit_admin_post_path(post), :class => 'btn btn-sm btn-default' %>
|
53
58
|
<%= link_to 'Delete', admin_post_path(post), :method => :delete, :data => {:confirm => 'Are you sure you want to delete this post?'}, :class => 'btn btn-sm btn-danger' %>
|
@@ -64,4 +69,7 @@
|
|
64
69
|
<script>
|
65
70
|
$(document).ready(spud.admin.post_categories.init);
|
66
71
|
</script>
|
72
|
+
<% if Spud::Blog.disqus_shortname %>
|
73
|
+
<%= javascript_include_tag "//#{Spud::Blog.disqus_shortname}.disqus.com/count.js", :id => 'dsq-count-scr', :async => true %>
|
74
|
+
<% end %>
|
67
75
|
<%end%>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<div id="disqus_thread"></div>
|
2
|
+
<script>
|
3
|
+
/**
|
4
|
+
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
|
5
|
+
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables
|
6
|
+
*/
|
7
|
+
var disqus_config = function () {
|
8
|
+
this.page.url = '<%= post_path(@post.url_name) %>'; // Replace PAGE_URL with your page's canonical URL variable
|
9
|
+
this.page.identifier = '<%= @post.identifier %>'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
|
10
|
+
};
|
11
|
+
(function() { // REQUIRED CONFIGURATION VARIABLE: EDIT THE SHORTNAME BELOW
|
12
|
+
var d = document, s = d.createElement('script');
|
13
|
+
s.src = '//<%= Spud::Blog.disqus_shortname %>.disqus.com/embed.js'; // IMPORTANT: Replace EXAMPLE with your forum shortname!
|
14
|
+
s.setAttribute('data-timestamp', +new Date());
|
15
|
+
(d.head || d.body).appendChild(s);
|
16
|
+
})();
|
17
|
+
</script>
|
18
|
+
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
|
@@ -30,7 +30,10 @@
|
|
30
30
|
<% cache(post) do %>
|
31
31
|
<div class="blog-post blog-post-partial">
|
32
32
|
<h3 class="blog-post-title"><%= link_to post.title, post_path(post.url_name) %></h3>
|
33
|
-
<h4 class="blog-post-author">Posted by <%= post.
|
33
|
+
<h4 class="blog-post-author">Posted by <%= post.author_name %> on <%= post.display_date %></h4>
|
34
|
+
<% if Spud::Blog.disqus_shortname %>
|
35
|
+
<p><%= disqus_comment_count_for_post(post) %></p>
|
36
|
+
<% end %>
|
34
37
|
<div class="blog-post-content">
|
35
38
|
<%= truncate_html post.content_processed.html_safe, :length => 250 %>
|
36
39
|
</div>
|
@@ -54,4 +57,8 @@
|
|
54
57
|
|
55
58
|
</div>
|
56
59
|
|
60
|
+
<% if Spud::Blog.disqus_shortname %>
|
61
|
+
<%= javascript_include_tag "//#{Spud::Blog.disqus_shortname}.disqus.com/count.js", :id => 'dsq-count-scr', :async => true %>
|
62
|
+
<% end %>
|
63
|
+
|
57
64
|
<% end %>
|
@@ -17,7 +17,7 @@
|
|
17
17
|
<div class="col-sm-12">
|
18
18
|
<div class="blog-post blog-post-partial">
|
19
19
|
<h1 class="blog-post-title"><%= @post.title %></h1>
|
20
|
-
|
20
|
+
<h4 class="blog-post-author">Posted by <%= @post.author_name %> on <%= @post.display_date %></h4>
|
21
21
|
<% if @post.categories.any? %>
|
22
22
|
<p class="blog-post-categories">
|
23
23
|
<span>Filed under</span>
|
@@ -32,26 +32,12 @@
|
|
32
32
|
</div>
|
33
33
|
</div>
|
34
34
|
|
35
|
-
<% if @post.comments_enabled %>
|
35
|
+
<% if @post.comments_enabled? && Spud::Blog.disqus_shortname %>
|
36
36
|
<div class="row">
|
37
37
|
<div class="col-sm-12">
|
38
|
-
|
39
|
-
<h5>Post a Comment:</h5>
|
40
|
-
<%= render 'comment_form' %>
|
41
|
-
</div>
|
42
|
-
<% cache(cache_key_for_spud_collection(@post.visible_comments, key:'comments')) do %>
|
43
|
-
<ul id="blog-post-comments">
|
44
|
-
<% @post.visible_comments.each do |comment| %>
|
45
|
-
<% cache(comment) do %>
|
46
|
-
<li>
|
47
|
-
<h6>Posted by: <%= comment.author %></h6>
|
48
|
-
<p><%= comment.content %></p>
|
49
|
-
</li>
|
50
|
-
<% end %>
|
51
|
-
<% end %>
|
52
|
-
</ul>
|
53
|
-
<% end %>
|
38
|
+
<%= render '/posts/disqus' %>
|
54
39
|
</div>
|
55
40
|
</div>
|
56
41
|
<% end %>
|
42
|
+
|
57
43
|
<% end %>
|
data/config/routes.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
|
3
3
|
namespace :admin do
|
4
|
-
resources :post_comments, :only => :destroy do
|
5
|
-
member do
|
6
|
-
get 'approve'
|
7
|
-
get 'spam'
|
8
|
-
end
|
9
|
-
end
|
10
4
|
resources :post_categories
|
11
5
|
end
|
12
6
|
|
@@ -14,10 +8,7 @@ Rails.application.routes.draw do
|
|
14
8
|
blog_key = config.key
|
15
9
|
|
16
10
|
namespace :admin do
|
17
|
-
resources :posts, :path => blog_key, :blog_key => blog_key
|
18
|
-
get 'comments' => 'post_comments#index', :path => 'comments', :on => :collection
|
19
|
-
resources :post_comments, :path => 'comments', :only => :index
|
20
|
-
end
|
11
|
+
resources :posts, :path => blog_key, :blog_key => blog_key
|
21
12
|
end
|
22
13
|
|
23
14
|
scope config.path do
|
@@ -52,7 +43,6 @@ Rails.application.routes.draw do
|
|
52
43
|
:defaults => {:page => 1}
|
53
44
|
|
54
45
|
get ':id' => 'posts#show', :as => "#{blog_key}_post", :blog_key => blog_key
|
55
|
-
post ':id' => 'posts#create_comment', :blog_key => blog_key
|
56
46
|
end
|
57
47
|
end
|
58
48
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# This migration will drop spud_post_comments from your database. It has been excluded
|
2
|
+
# from the migrations directory to avoid accidential data loss on upgrading.
|
3
|
+
#
|
4
|
+
# If you wish to completely remove spud_post_comments from your app, simply copy this file
|
5
|
+
# into your db/migrations directory and run db:migrate.
|
6
|
+
#
|
7
|
+
|
8
|
+
class DropSpudPostComments < ActiveRecord::Migration
|
9
|
+
def up
|
10
|
+
drop_table :spud_post_comments
|
11
|
+
remove_column :spud_posts, :comments_count
|
12
|
+
end
|
13
|
+
def down
|
14
|
+
create_table :spud_post_comments do |t|
|
15
|
+
t.integer :spud_post_id
|
16
|
+
t.string :author
|
17
|
+
t.text :content
|
18
|
+
t.boolean :approved, :default => false
|
19
|
+
t.boolean :spam
|
20
|
+
t.string :user_ip
|
21
|
+
t.string :user_agent
|
22
|
+
t.string :referrer
|
23
|
+
t.string :permalink
|
24
|
+
t.string :blog_key
|
25
|
+
t.timestamps
|
26
|
+
end
|
27
|
+
add_column :spud_posts, :comments_count, :integer
|
28
|
+
end
|
29
|
+
end
|
@@ -2,10 +2,9 @@ module Spud
|
|
2
2
|
module Blog
|
3
3
|
include ActiveSupport::Configurable
|
4
4
|
config_accessor(
|
5
|
-
:base_layout, :news_layout, :blogs, :news_enabled, :blog_enabled, :blog_path, :news_path,
|
6
|
-
:posts_per_page, :has_custom_fields,
|
5
|
+
:base_layout, :news_layout, :blogs, :news_enabled, :blog_enabled, :blog_path, :news_path, :posts_per_page,
|
7
6
|
:permitted_attributes, :query_for_user,
|
8
|
-
:
|
7
|
+
:disqus_shortname
|
9
8
|
)
|
10
9
|
self.base_layout = 'application'
|
11
10
|
self.posts_per_page = 5
|
@@ -16,11 +15,9 @@ module Spud
|
|
16
15
|
self.blog_path = '/blog'
|
17
16
|
self.news_path = '/news'
|
18
17
|
|
19
|
-
self.has_custom_fields = false
|
20
|
-
self.enable_rakismet = false
|
21
|
-
self.default_comment_approval = true
|
22
18
|
self.permitted_attributes = []
|
23
19
|
self.query_for_user = nil
|
20
|
+
self.disqus_shortname = nil
|
24
21
|
|
25
22
|
self.blogs = []
|
26
23
|
end
|
data/lib/spud_blog/engine.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'tb_core'
|
2
|
-
require '
|
2
|
+
require 'tb_redirects'
|
3
3
|
require 'tb_liquid'
|
4
4
|
require 'truncate_html'
|
5
5
|
|
@@ -48,18 +48,16 @@ module Spud
|
|
48
48
|
blog_app = {
|
49
49
|
:name => "#{config.name} Posts",
|
50
50
|
:url => "admin/#{config.key}",
|
51
|
-
:thumbnail => '
|
52
|
-
:badge => ->(user){
|
53
|
-
SpudPostComment.for_blog(config.key).pending_approval.count()
|
54
|
-
}
|
51
|
+
:thumbnail => 'admin/posts_thumb.png'
|
55
52
|
}
|
56
53
|
Spud::Core.config.admin_applications += [blog_app]
|
57
54
|
end
|
58
55
|
end
|
59
56
|
|
60
|
-
initializer
|
57
|
+
initializer 'tb_blog.assets' do
|
61
58
|
Spud::Core.append_admin_javascripts('admin/blog/application')
|
62
59
|
Spud::Core.append_admin_stylesheets('admin/blog/application')
|
60
|
+
Rails.application.config.assets.precompile += ['admin/posts_thumb.png', 'admin/news_thumb.png']
|
63
61
|
end
|
64
62
|
|
65
63
|
# Triggers a I18n.enforce_available_locales deprecation warning. Why?
|
@@ -68,12 +66,6 @@ module Spud
|
|
68
66
|
# has_many :posts, :class_name => 'SpudPost'
|
69
67
|
# end
|
70
68
|
# end
|
71
|
-
|
72
|
-
initializer :rakismet do
|
73
|
-
if Spud::Blog.enable_rakismet
|
74
|
-
require 'rakismet'
|
75
|
-
end
|
76
|
-
end
|
77
69
|
end
|
78
70
|
end
|
79
71
|
end
|
data/lib/spud_blog/version.rb
CHANGED
@@ -2,4 +2,26 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
describe Admin::PostsController, :type => :controller do
|
4
4
|
|
5
|
-
|
5
|
+
before(:each) do
|
6
|
+
activate_session(admin: true)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#create_redirect_if_necessary' do
|
10
|
+
before(:each) do
|
11
|
+
@post = FactoryGirl.create(:spud_post)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should create a redirect' do
|
15
|
+
expect{
|
16
|
+
put :update, :id => @post.id, :spud_post => {:url_name => 'new-url'}, :blog_key => 'blog'
|
17
|
+
}.to change(@post.tb_redirects, :count).by(1)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should not create a redirect' do
|
21
|
+
expect{
|
22
|
+
put :update, :id => @post.id, :spud_post => {:title => 'Hello World'}, :blog_key => 'blog'
|
23
|
+
}.to_not change(@post.tb_redirects, :count)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -27,30 +27,4 @@ describe PostsController, :type => :controller do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe 'create_comment' do
|
31
|
-
it "should create a comment" do
|
32
|
-
@post = FactoryGirl.create(:spud_post)
|
33
|
-
post :create_comment, :blog_key => 'blog', :id => @post.url_name, :spud_post_comment => {:author => "Test User", :content => "Lorem Ipsum"}
|
34
|
-
expect(@post.comments.length).to be > 0
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should approve a comment by default if default_comment_approval is true" do
|
38
|
-
Spud::Blog.configure do |config|
|
39
|
-
config.default_comment_approval = true
|
40
|
-
end
|
41
|
-
@post = FactoryGirl.create(:spud_post)
|
42
|
-
post :create_comment, :blog_key => 'blog', :id => @post.url_name, :spud_post_comment => {:author => "Test User", :content => "Lorem Ipsum"}
|
43
|
-
expect(@post.comments.first.approved).to eq(true)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should not approve a comment by default if default_comment_approval is false" do
|
47
|
-
Spud::Blog.configure do |config|
|
48
|
-
config.default_comment_approval = false
|
49
|
-
end
|
50
|
-
@post = FactoryGirl.create(:spud_post)
|
51
|
-
post :create_comment, :blog_key => 'blog', :id => @post.url_name, :spud_post_comment => {:author => "Test User", :content => "Lorem Ipsum"}
|
52
|
-
expect(@post.comments.first.approved).to eq(false)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
30
|
end
|
@@ -7,6 +7,11 @@ require "tb_blog"
|
|
7
7
|
|
8
8
|
module Dummy
|
9
9
|
class Application < Rails::Application
|
10
|
+
|
11
|
+
Spud::Blog.configure do |c|
|
12
|
+
c.disqus_shortname = 'testblog'
|
13
|
+
end
|
14
|
+
|
10
15
|
# Settings in config/environments/* take precedence over those specified here.
|
11
16
|
# Application configuration should go into files in config/initializers
|
12
17
|
# -- all .rb files in that directory are automatically loaded.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# This migration comes from tb_redirects (originally 20160211162513)
|
2
|
+
class CreateTbRedirects < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :tb_redirects do |t|
|
5
|
+
t.string :owner_type
|
6
|
+
t.integer :owner_id
|
7
|
+
t.string :source, :null => false
|
8
|
+
t.string :destination, :null => false
|
9
|
+
t.string :created_by
|
10
|
+
t.timestamps null: false
|
11
|
+
end
|
12
|
+
add_index :tb_redirects, [:owner_type, :owner_id]
|
13
|
+
add_index :tb_redirects, :source, :unique => true
|
14
|
+
end
|
15
|
+
end
|