tb_blog 1.3.5 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/app/assets/javascripts/admin/blog/posts.js +1 -1
- data/app/controllers/admin/post_categories_controller.rb +3 -3
- data/app/controllers/admin/posts_controller.rb +4 -13
- data/app/controllers/concerns/render_post_action.rb +7 -0
- data/app/controllers/posts_controller.rb +10 -11
- data/app/helpers/admin/posts_helper.rb +1 -1
- data/app/helpers/blog_helper.rb +1 -1
- data/app/models/spud_post.rb +1 -1
- data/app/models/spud_post_category.rb +0 -1
- data/app/models/spud_post_site.rb +1 -1
- data/app/models/{spud → tb_core}/spud_post_model.rb +20 -17
- data/app/views/posts/index.html.erb +1 -1
- data/app/views/posts/index.rss.builder +5 -5
- data/app/views/posts/show.html.erb +1 -1
- data/lib/generators/spud/blog/random_posts_generator.rb +1 -1
- data/lib/spud_blog/engine.rb +8 -9
- data/lib/spud_blog/version.rb +1 -1
- data/spec/controllers/admin/posts_controller_spec.rb +6 -9
- data/spec/controllers/posts_controller_spec.rb +11 -3
- data/spec/dummy/app/controllers/application_controller.rb +1 -1
- data/spec/dummy/config/environments/development.rb +0 -7
- data/spec/dummy/config/environments/production.rb +0 -4
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/config/initializers/secret_token.rb +1 -1
- data/spec/dummy/db/migrate/20180730141254_create_active_storage_tables.active_storage.rb +26 -0
- data/spec/dummy/db/schema.rb +112 -110
- data/spec/factories/spud_post_factories.rb +3 -3
- data/spec/helpers/admin/posts_helper_spec.rb +1 -1
- data/spec/helpers/blog_helper_spec.rb +1 -1
- data/spec/models/spud_post_spec.rb +2 -2
- data/spec/rails_helper.rb +9 -2
- metadata +95 -95
- data/app/controllers/concerns/post_view_for_action.rb +0 -11
- data/spec/dummy/db/migrate/20161020155436_create_tb_liquid_spud_liquid_tags.tb_liquid.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c8bb8dfa74cf36c2c41159cb5a6aa995a3499a3
|
4
|
+
data.tar.gz: 43a7bc493de1c0a89b8c1d460a3767c9343d789e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1f8027428d3d63313405febe56b4ebc7662284199914b313e3d789f485cb024c33df767e33f464b50d44b17a2ba6a428c2752a6e5a68a185e634bd5d252e218
|
7
|
+
data.tar.gz: b31bfe914eda56b33f4f77486865e903fa92a8905afa4d68fed4097ccb21f4c58ce5276a0b782ad600844194a6d1a74f113a14034fa6d0b460d903b0a19927cb
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
21
|
end
|
22
22
|
|
23
|
-
APP_RAKEFILE = File.expand_path('
|
23
|
+
APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
|
24
24
|
load 'rails/tasks/engine.rake'
|
25
25
|
|
26
26
|
Bundler::GemHelper.install_tasks
|
@@ -120,7 +120,7 @@ var clickedPreviewButton = function(e){
|
|
120
120
|
// Cross site scripting tag
|
121
121
|
var csrf = document.createElement('input');
|
122
122
|
csrf.name = 'authenticity_token';
|
123
|
-
csrf.value =
|
123
|
+
csrf.value = Rails.csrfToken();
|
124
124
|
$previewForm.append(csrf);
|
125
125
|
|
126
126
|
// Submit it
|
@@ -15,11 +15,11 @@ class Admin::PostCategoriesController < Admin::ApplicationController
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def update
|
18
|
-
if @post_category.
|
18
|
+
if @post_category.update(category_params)
|
19
19
|
flash.now[:notice] = 'Post Category was successfully updated'
|
20
20
|
respond_with @post_category, location: admin_post_categories_path
|
21
21
|
else
|
22
|
-
render 'new', status:
|
22
|
+
render 'new', status: :unprocessable_entity
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -34,7 +34,7 @@ class Admin::PostCategoriesController < Admin::ApplicationController
|
|
34
34
|
flash.now[:notice] = 'Post Category was successfully created'
|
35
35
|
respond_with @post_category, location: admin_post_categories_path
|
36
36
|
else
|
37
|
-
render 'new', status:
|
37
|
+
render 'new', status: :unprocessable_entity
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Admin::PostsController < Admin::ApplicationController
|
2
2
|
include BlogUrlHelpers
|
3
|
-
include
|
3
|
+
include RenderPostAction
|
4
4
|
|
5
5
|
respond_to :html, :xml, :json
|
6
6
|
before_action :load_blog
|
@@ -21,9 +21,7 @@ class Admin::PostsController < Admin::ApplicationController
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def update
|
24
|
-
if @post.
|
25
|
-
flash[:notice] = 'Post was successfully updated.'
|
26
|
-
end
|
24
|
+
flash[:notice] = 'Post was successfully updated.' if @post.update(post_params)
|
27
25
|
respond_with @post, location: admin_posts_path
|
28
26
|
end
|
29
27
|
|
@@ -51,12 +49,7 @@ class Admin::PostsController < Admin::ApplicationController
|
|
51
49
|
SpudPost.new
|
52
50
|
end
|
53
51
|
@post.assign_attributes(post_params)
|
54
|
-
@
|
55
|
-
render template: post_view_for_action(:show), controller: :posts, layout: @config.layout
|
56
|
-
end
|
57
|
-
|
58
|
-
def render_preview
|
59
|
-
render template: post_view_for_action(:show), controller: :posts, layout: @config.layout
|
52
|
+
render_post_action :show, controller: :posts, layout: @config.layout
|
60
53
|
end
|
61
54
|
|
62
55
|
private
|
@@ -71,9 +64,7 @@ class Admin::PostsController < Admin::ApplicationController
|
|
71
64
|
|
72
65
|
def post_params
|
73
66
|
permitted = [:published_at, :title, :content, :spud_user_id, :url_name, :visible, :comments_enabled, :meta_keywords, :meta_description, :content_format, :custom_author, category_ids: []]
|
74
|
-
if Spud::Blog.permitted_attributes.present?
|
75
|
-
permitted += Spud::Blog.permitted_attributes
|
76
|
-
end
|
67
|
+
permitted += Spud::Blog.permitted_attributes if Spud::Blog.permitted_attributes.present?
|
77
68
|
p = params.require(:spud_post).permit(permitted)
|
78
69
|
p[:updated_at] = DateTime.now
|
79
70
|
return p
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class PostsController < ApplicationController
|
2
2
|
include BlogUrlHelpers
|
3
|
-
include
|
3
|
+
include RenderPostAction
|
4
4
|
|
5
5
|
respond_to :html, :json, :rss
|
6
6
|
|
@@ -13,18 +13,18 @@ class PostsController < ApplicationController
|
|
13
13
|
@posts = @posts.search(params[:search]) if params[:search]
|
14
14
|
respond_with @posts do |format|
|
15
15
|
format.html do
|
16
|
-
|
16
|
+
render_post_action :index
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
# The sole purpose of this action is to redirect from a POST to an seo-friendly url
|
22
22
|
def filter
|
23
|
-
if
|
23
|
+
if params[:category_url_name].present? && params[:archive_date].present?
|
24
24
|
redirect_to post_category_archive_path(params[:category_url_name], params[:archive_date])
|
25
|
-
elsif
|
25
|
+
elsif params[:category_url_name].present?
|
26
26
|
redirect_to post_category_path(params[:category_url_name])
|
27
|
-
elsif
|
27
|
+
elsif params[:archive_date].present?
|
28
28
|
redirect_to post_archive_path(params[:archive_date])
|
29
29
|
else
|
30
30
|
redirect_to posts_path
|
@@ -39,20 +39,20 @@ class PostsController < ApplicationController
|
|
39
39
|
return
|
40
40
|
end
|
41
41
|
respond_with @posts do |format|
|
42
|
-
format.html {
|
42
|
+
format.html { render_post_action :index }
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def archive
|
47
47
|
@posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).from_archive(params[:archive_date]).paginate(page: @page_number, per_page: Spud::Blog.config.posts_per_page)
|
48
48
|
respond_with @posts do |format|
|
49
|
-
format.html {
|
49
|
+
format.html { render_post_action :index }
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
def show
|
54
54
|
respond_with @post do |format|
|
55
|
-
format.html {
|
55
|
+
format.html { render_post_action :show }
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -60,7 +60,7 @@ class PostsController < ApplicationController
|
|
60
60
|
|
61
61
|
def find_post
|
62
62
|
@post = SpudPost.for_user(current_user).for_blog(params[:blog_key]).where(url_name: params[:id]).first
|
63
|
-
raise
|
63
|
+
raise TbCore::NotFoundError, item: 'post' if @post.blank? || @post.is_private?
|
64
64
|
end
|
65
65
|
|
66
66
|
def load_page_number
|
@@ -81,8 +81,7 @@ class PostsController < ApplicationController
|
|
81
81
|
def load_blog
|
82
82
|
@config = SpudBlogConfig.find(params[:blog_key])
|
83
83
|
if @config.blank?
|
84
|
-
raise
|
85
|
-
return false
|
84
|
+
raise TbCore::NotFoundError(item: 'blog')
|
86
85
|
else
|
87
86
|
self.class.layout(@config.layout)
|
88
87
|
end
|
@@ -13,7 +13,7 @@ module Admin::PostsHelper
|
|
13
13
|
|
14
14
|
def link_to_disqus_comment_count(post)
|
15
15
|
# TODO: It would be great to link directly to the thread
|
16
|
-
#
|
16
|
+
# ie: https://myblog.disqus.com/admin/moderate/#/all/search/thread:4584301535
|
17
17
|
#
|
18
18
|
# However, we do not know the thread ID at this time. We may be able to fetch it
|
19
19
|
# via the Disqus JavaScript API.
|
data/app/helpers/blog_helper.rb
CHANGED
@@ -19,7 +19,7 @@ module BlogHelper
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def spud_blog_rss_link
|
22
|
-
return tag :link, rel: 'alternate', type: 'application/rss+xml', title: "#{
|
22
|
+
return tag :link, rel: 'alternate', type: 'application/rss+xml', title: "#{TbCore.site_name} Blog RSS", href: posts_path(format: :rss)
|
23
23
|
end
|
24
24
|
|
25
25
|
def disqus_comment_count_for_post(post)
|
data/app/models/spud_post.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
class
|
1
|
+
class TbCore::SpudPostModel < ActiveRecord::Base
|
2
2
|
include TbRedirects::HasRedirects
|
3
3
|
|
4
4
|
self.table_name = 'spud_posts'
|
5
5
|
|
6
|
-
spud_searchable
|
7
|
-
|
8
6
|
has_many :spud_post_categories_posts, foreign_key: 'spud_post_id'
|
9
7
|
has_many :categories,
|
10
8
|
class_name: 'SpudPostCategory',
|
@@ -34,8 +32,6 @@ class Spud::SpudPostModel < ActiveRecord::Base
|
|
34
32
|
before_validation :set_url_name
|
35
33
|
before_validation :set_identifier
|
36
34
|
|
37
|
-
acts_as_tb_liquid_content
|
38
|
-
|
39
35
|
def self.for_spud_site(_spud_site_id)
|
40
36
|
ActiveSupport::Deprecation.warn 'SpudBlog.for_spud_site is deprecated and will be removed in the future'
|
41
37
|
return all()
|
@@ -56,7 +52,7 @@ class Spud::SpudPostModel < ActiveRecord::Base
|
|
56
52
|
def self.from_archive(date_string)
|
57
53
|
date = Date.strptime(date_string, '%Y-%b')
|
58
54
|
return where(published_at: date..date.end_of_month)
|
59
|
-
rescue
|
55
|
+
rescue StandardError
|
60
56
|
logger.debug 'fallback'
|
61
57
|
return where('')
|
62
58
|
end
|
@@ -76,18 +72,23 @@ class Spud::SpudPostModel < ActiveRecord::Base
|
|
76
72
|
end
|
77
73
|
end
|
78
74
|
|
79
|
-
def postprocess_content
|
80
|
-
|
81
|
-
|
82
|
-
end
|
75
|
+
# def postprocess_content
|
76
|
+
# template = Liquid::Template.parse(content)
|
77
|
+
# self.content_processed = template.render()
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# def content_processed
|
81
|
+
# postprocess_content if self[:content_processed].blank?
|
82
|
+
# self[:content_processed]
|
83
|
+
# end
|
83
84
|
|
84
|
-
def content_processed
|
85
|
-
|
86
|
-
|
87
|
-
end
|
85
|
+
# def content_processed=(content)
|
86
|
+
# self[:content_processed] = content
|
87
|
+
# end
|
88
88
|
|
89
|
-
def content_processed
|
90
|
-
|
89
|
+
def content_processed
|
90
|
+
ActiveSupport::Deprecation.warn '#content_processed is deprecated. Use #content instead.'
|
91
|
+
content
|
91
92
|
end
|
92
93
|
|
93
94
|
def display_date
|
@@ -109,8 +110,10 @@ class Spud::SpudPostModel < ActiveRecord::Base
|
|
109
110
|
def author_name
|
110
111
|
if custom_author.present?
|
111
112
|
custom_author
|
112
|
-
|
113
|
+
elsif author.present?
|
113
114
|
author.full_name
|
115
|
+
else
|
116
|
+
''
|
114
117
|
end
|
115
118
|
end
|
116
119
|
|
@@ -35,7 +35,7 @@
|
|
35
35
|
<p><%= disqus_comment_count_for_post(post) %></p>
|
36
36
|
<% end %>
|
37
37
|
<div class="blog-post-content">
|
38
|
-
<%= truncate_html post.
|
38
|
+
<%= truncate_html post.content.html_safe, :length => 250 %>
|
39
39
|
</div>
|
40
40
|
</div>
|
41
41
|
<% end %>
|
@@ -1,9 +1,9 @@
|
|
1
|
-
xml.instruct! :xml, :
|
2
|
-
xml.rss :
|
1
|
+
xml.instruct! :xml, version: '1.0'
|
2
|
+
xml.rss version: '2.0' do
|
3
3
|
xml.channel do
|
4
|
-
xml.title "#{
|
5
|
-
xml.description "Blog articles for #{
|
6
|
-
xml.link posts_path(:
|
4
|
+
xml.title "#{TbCore.site_name} Blog Articles"
|
5
|
+
xml.description "Blog articles for #{TbCore.site_name}"
|
6
|
+
xml.link posts_path(format: :rss)
|
7
7
|
|
8
8
|
for article in @posts
|
9
9
|
xml.item do
|
data/lib/spud_blog/engine.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'tb_core'
|
2
2
|
require 'tb_redirects'
|
3
|
-
require 'tb_liquid'
|
4
3
|
require 'truncate_html'
|
5
4
|
|
6
5
|
module Spud
|
@@ -46,22 +45,22 @@ module Spud
|
|
46
45
|
url: "admin/#{config.key}",
|
47
46
|
thumbnail: 'admin/posts_thumb.png'
|
48
47
|
}
|
49
|
-
|
48
|
+
TbCore.config.admin_applications += [blog_app]
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
53
52
|
initializer 'tb_blog.assets' do
|
54
|
-
|
55
|
-
|
53
|
+
TbCore.append_admin_javascripts('admin/blog/application')
|
54
|
+
TbCore.append_admin_stylesheets('admin/blog/application')
|
56
55
|
Rails.application.config.assets.precompile += ['admin/posts_thumb.png', 'admin/news_thumb.png']
|
57
56
|
end
|
58
57
|
|
59
58
|
# Triggers a I18n.enforce_available_locales deprecation warning. Why?
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
59
|
+
initializer 'tb_blog.user_association', after: 'tb_core.model_overrides' do
|
60
|
+
SpudUser.class_eval do
|
61
|
+
has_many :posts, class_name: 'SpudPost', dependent: :nullify
|
62
|
+
end
|
63
|
+
end
|
65
64
|
end
|
66
65
|
end
|
67
66
|
end
|
data/lib/spud_blog/version.rb
CHANGED
@@ -8,18 +8,18 @@ describe Admin::PostsController, type: :controller do
|
|
8
8
|
|
9
9
|
describe '#create_redirect_if_necessary' do
|
10
10
|
before(:each) do
|
11
|
-
@post =
|
11
|
+
@post = FactoryBot.create(:spud_post)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should create a redirect' do
|
15
15
|
expect do
|
16
|
-
put :update, id: @post.id, spud_post: { url_name: 'new-url' }, blog_key: 'blog'
|
16
|
+
put :update, params: { id: @post.id, spud_post: { url_name: 'new-url' }, blog_key: 'blog' }
|
17
17
|
end.to change(@post.tb_redirects, :count).by(1)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should not create a redirect' do
|
21
21
|
expect do
|
22
|
-
put :update, id: @post.id, spud_post: { title: 'Hello World' }, blog_key: 'blog'
|
22
|
+
put :update, params: { id: @post.id, spud_post: { title: 'Hello World' }, blog_key: 'blog' }
|
23
23
|
end.to_not change(@post.tb_redirects, :count)
|
24
24
|
end
|
25
25
|
end
|
@@ -28,18 +28,15 @@ describe Admin::PostsController, type: :controller do
|
|
28
28
|
context 'with a new post' do
|
29
29
|
it 'should set the attributes without saving' do
|
30
30
|
expect do
|
31
|
-
post :preview, blog_key: 'blog', post_id: nil, spud_post: { title: 'Hello World' }
|
31
|
+
post :preview, params: { blog_key: 'blog', post_id: nil, spud_post: { title: 'Hello World' } }
|
32
32
|
end.to_not change(SpudPost, :count)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
context 'with an existing post' do
|
36
36
|
it 'should set the attributes without saving' do
|
37
|
-
@post =
|
37
|
+
@post = FactoryBot.create(:spud_post)
|
38
38
|
expect do
|
39
|
-
post :preview,
|
40
|
-
blog_key: @post.blog_key,
|
41
|
-
post_id: @post.id,
|
42
|
-
spud_post: { title: 'Hello World' }
|
39
|
+
post :preview, params: { blog_key: @post.blog_key, post_id: @post.id, spud_post: { title: 'Hello World' } }
|
43
40
|
@post.reload
|
44
41
|
end.to_not change(@post, :title)
|
45
42
|
end
|
@@ -8,8 +8,8 @@ describe PostsController, type: :controller do
|
|
8
8
|
|
9
9
|
describe 'index' do
|
10
10
|
it 'should display a list of posts' do
|
11
|
-
2.times { |_i|
|
12
|
-
get :index, blog_key: 'blog'
|
11
|
+
2.times { |_i| FactoryBot.create(:spud_post) }
|
12
|
+
get :index, params: { blog_key: 'blog' }
|
13
13
|
expect(assigns(:posts).count).to be > 1
|
14
14
|
end
|
15
15
|
|
@@ -21,10 +21,18 @@ describe PostsController, type: :controller do
|
|
21
21
|
{}
|
22
22
|
end
|
23
23
|
}
|
24
|
-
get :index, blog_key: 'blog'
|
24
|
+
get :index, params: { blog_key: 'blog' }
|
25
25
|
expect(assigns(:posts).count).to be 0
|
26
26
|
Spud::Blog.config.query_for_user = nil
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
describe 'show' do
|
31
|
+
it 'renders the post' do
|
32
|
+
post = FactoryBot.create(:spud_post)
|
33
|
+
get :show, params: { blog_key: post.blog_key, id: post.url_name }
|
34
|
+
expect(response).to have_http_status(:success)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
30
38
|
end
|