tb_blog 1.3.3 → 1.3.4
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/Rakefile +1 -2
- data/app/assets/javascripts/admin/blog/posts.js +42 -0
- data/app/controllers/admin/post_categories_controller.rb +57 -57
- data/app/controllers/admin/posts_controller.rb +110 -101
- data/app/controllers/concerns/blog_url_helpers.rb +22 -18
- data/app/controllers/concerns/post_view_for_action.rb +11 -0
- data/app/controllers/posts_controller.rb +23 -34
- data/app/helpers/admin/posts_helper.rb +20 -20
- data/app/helpers/blog_helper.rb +21 -21
- data/app/models/spud/spud_post_model.rb +43 -51
- data/app/models/spud_blog_config.rb +2 -2
- data/app/models/spud_post.rb +1 -1
- data/app/models/spud_post_categories_post.rb +1 -1
- data/app/models/spud_post_category.rb +18 -20
- data/app/models/spud_post_site.rb +1 -1
- data/app/views/admin/posts/_form.html.erb +4 -3
- data/app/views/admin/posts/edit.html.erb +10 -2
- data/app/views/admin/posts/new.html.erb +9 -1
- data/app/views/admin/posts/show.html.erb +0 -0
- data/config/routes.rb +3 -1
- data/lib/generators/spud/blog/blog_generator.rb +5 -5
- data/lib/generators/spud/blog/random_posts_generator.rb +12 -14
- data/lib/generators/spud/blog/views_generator.rb +1 -1
- data/lib/spud_blog/configuration.rb +1 -2
- data/lib/spud_blog/engine.rb +12 -16
- data/lib/spud_blog/version.rb +3 -3
- data/lib/tasks/spud_blog_tasks.rake +1 -1
- data/lib/tb_blog.rb +2 -2
- data/spec/controllers/admin/posts_controller_spec.rb +28 -7
- data/spec/controllers/posts_controller_spec.rb +7 -7
- data/spec/dummy/config/application.rb +2 -3
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environment.rb +2 -2
- data/spec/dummy/config/environments/test.rb +3 -3
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/dummy/config.ru +1 -1
- data/spec/dummy/db/migrate/{20120610130206_create_spud_admin_permissions.spud_core.rb → 20161020155425_create_spud_admin_permissions.tb_core.rb} +1 -1
- data/spec/dummy/db/migrate/20161020155426_create_spud_users.tb_core.rb +30 -0
- data/spec/dummy/db/migrate/{20120610130208_add_time_zone_to_spud_user.spud_core.rb → 20161020155427_add_time_zone_to_spud_user.tb_core.rb} +1 -2
- data/spec/dummy/db/migrate/{20120610130209_add_scope_to_spud_admin_permissions.spud_core.rb → 20161020155428_add_scope_to_spud_admin_permissions.tb_core.rb} +1 -2
- data/spec/dummy/db/migrate/{20120610130210_create_spud_user_settings.spud_core.rb → 20161020155429_create_spud_user_settings.tb_core.rb} +1 -1
- data/spec/dummy/db/migrate/{20140110180411_create_spud_roles.tb_core.rb → 20161020155430_create_spud_roles.tb_core.rb} +0 -0
- data/spec/dummy/db/migrate/{20140110180412_create_spud_permissions.tb_core.rb → 20161020155431_create_spud_permissions.tb_core.rb} +3 -3
- data/spec/dummy/db/migrate/{20140110180413_create_spud_role_permissions.tb_core.rb → 20161020155432_create_spud_role_permissions.tb_core.rb} +2 -2
- data/spec/dummy/db/migrate/{20140110180414_drop_spud_admin_permissions.tb_core.rb → 20161020155433_drop_spud_admin_permissions.tb_core.rb} +0 -0
- data/spec/dummy/db/migrate/{20160215174632_add_requires_password_change_to_spud_users.tb_core.rb → 20161020155434_add_requires_password_change_to_spud_users.tb_core.rb} +1 -1
- data/spec/dummy/db/migrate/{20160215174633_create_tb_redirects.tb_redirects.rb → 20161020155435_create_tb_redirects.tb_redirects.rb} +3 -3
- data/spec/dummy/db/migrate/{20140113162805_create_tb_liquid_spud_liquid_tags.tb_liquid.rb → 20161020155436_create_tb_liquid_spud_liquid_tags.tb_liquid.rb} +0 -0
- data/spec/dummy/db/migrate/{20140110180418_create_spud_posts.tb_blog.rb → 20161020155437_create_spud_posts.tb_blog.rb} +3 -3
- data/spec/dummy/db/migrate/{20140110180419_create_spud_post_categories.tb_blog.rb → 20161020155438_create_spud_post_categories.tb_blog.rb} +4 -4
- data/spec/dummy/db/migrate/{20140110180421_add_url_to_spud_posts.tb_blog.rb → 20161020155439_add_url_to_spud_posts.tb_blog.rb} +2 -2
- data/spec/dummy/db/migrate/20161020155440_add_url_to_spud_post_categories.tb_blog.rb +9 -0
- data/spec/dummy/db/migrate/{20140110180423_add_is_news_to_spud_posts.tb_blog.rb → 20161020155441_add_is_news_to_spud_posts.tb_blog.rb} +2 -2
- data/spec/dummy/db/migrate/{20140110180424_add_meta_to_posts.tb_blog.rb → 20161020155442_add_meta_to_posts.tb_blog.rb} +0 -0
- data/spec/dummy/db/migrate/{20140110180426_create_spud_post_sites.tb_blog.rb → 20161020155443_create_spud_post_sites.tb_blog.rb} +3 -3
- data/spec/dummy/db/migrate/{20140110180429_add_nested_set_to_post_categories.tb_blog.rb → 20161020155444_add_nested_set_to_post_categories.tb_blog.rb} +1 -5
- data/spec/dummy/db/migrate/{20140110180430_add_content_format_to_spud_posts.tb_blog.rb → 20161020155445_add_content_format_to_spud_posts.tb_blog.rb} +1 -1
- data/spec/dummy/db/migrate/{20140110180431_add_content_processed_to_spud_post.tb_blog.rb → 20161020155446_add_content_processed_to_spud_post.tb_blog.rb} +0 -0
- data/spec/dummy/db/migrate/{20140730131549_add_primary_key_to_spud_post_categories_posts.tb_blog.rb → 20161020155447_add_primary_key_to_spud_post_categories_posts.tb_blog.rb} +0 -0
- data/spec/dummy/db/migrate/{20140730131550_remove_awesome_nested_set_columns_from_spud_post_categories.tb_blog.rb → 20161020155448_remove_awesome_nested_set_columns_from_spud_post_categories.tb_blog.rb} +2 -1
- data/spec/dummy/db/migrate/{20140811161502_add_blog_key_to_spud_posts.tb_blog.rb → 20161020155449_add_blog_key_to_spud_posts.tb_blog.rb} +0 -0
- data/spec/dummy/db/migrate/{20150116195007_drop_spud_post_sites.tb_blog.rb → 20161020155450_drop_spud_post_sites.tb_blog.rb} +4 -3
- data/spec/dummy/db/migrate/{20151015154040_add_custom_author_to_post.tb_blog.rb → 20161020155451_add_custom_author_to_post.tb_blog.rb} +1 -1
- data/spec/dummy/db/migrate/{20160216150847_add_identifier_to_spud_posts.tb_blog.rb → 20161020155452_add_identifier_to_spud_posts.tb_blog.rb} +1 -1
- data/spec/dummy/db/schema.rb +106 -118
- data/spec/dummy/script/rails +2 -2
- data/spec/factories/spud_post_factories.rb +2 -2
- data/spec/helpers/admin/posts_helper_spec.rb +1 -1
- data/spec/models/spud_post_spec.rb +4 -4
- data/spec/rails_helper.rb +5 -5
- data/spec/spec_helper.rb +42 -44
- metadata +77 -79
- data/spec/dummy/db/migrate/20120610130207_create_spud_users.spud_core.rb +0 -30
- data/spec/dummy/db/migrate/20140110180415_create_spud_permalinks.tb_permalinks.rb +0 -12
- data/spec/dummy/db/migrate/20140110180416_add_site_id_to_spud_permalinks.tb_permalinks.rb +0 -7
- data/spec/dummy/db/migrate/20140110180417_modify_site_id_for_spud_permalinks.tb_permalinks.rb +0 -12
- data/spec/dummy/db/migrate/20140110180420_create_spud_post_comments.tb_blog.rb +0 -14
- data/spec/dummy/db/migrate/20140110180422_add_url_to_spud_post_categories.tb_blog.rb +0 -9
- data/spec/dummy/db/migrate/20140110180425_add_comments_counter_to_spud_posts.tb_blog.rb +0 -13
- data/spec/dummy/db/migrate/20140110180427_add_spam_fields_to_spud_post_comments.tb_blog.rb +0 -9
- data/spec/dummy/db/migrate/20140110180428_add_permalink_to_spud_post_comments.tb_blog.rb +0 -6
- data/spec/dummy/db/migrate/20140811161503_add_blog_key_to_spud_post_comments.tb_blog.rb +0 -7
- data/spec/dummy/db/migrate/20160216153113_drop_spud_post_comments.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ea87e773003046128ce6898ed2d3503f4c3c356
|
4
|
+
data.tar.gz: f8ef87cc40c3c462b7b40078e66a916fc63c49c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f86f21e95dc402fc6d73df5f3caaf2cf6b550ce3473e51753d2192b310615cba3202cd9c764c2af8534c6765c72e3be1c4d222b314b10a29efb9248f4fa7dd9
|
7
|
+
data.tar.gz: 14d0eee6497a0ffc52d8d94f38ea820989ef477d777200c04e0d8ecdc78b46084efce791ea37a3270bb0491777e7f15b15e5b975a7e5017754b9a8adf136ba86
|
data/Rakefile
CHANGED
@@ -20,10 +20,9 @@ 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', __FILE__)
|
24
24
|
load 'rails/tasks/engine.rake'
|
25
25
|
|
26
26
|
Bundler::GemHelper.install_tasks
|
27
27
|
|
28
28
|
require 'rake'
|
29
|
-
|
@@ -6,6 +6,7 @@ spud.admin.posts = {
|
|
6
6
|
$('body').on('submit', '.spud-post-category-form', submittedPostCategoryForm);
|
7
7
|
$('body').on('blur', '.spud-post-title', blurredPostTitle);
|
8
8
|
$('body').on('click', '.spud-post-url-name-regen', clickedUrlNameRegen);
|
9
|
+
$(".btn-preview").on('click', clickedPreviewButton);
|
9
10
|
}
|
10
11
|
};
|
11
12
|
|
@@ -91,4 +92,45 @@ var encodeTitleForUrlName = function(title){
|
|
91
92
|
return string;
|
92
93
|
};
|
93
94
|
|
95
|
+
var clickedPreviewButton = function(e){
|
96
|
+
e.preventDefault();
|
97
|
+
var $button = $(this);
|
98
|
+
var $form = $button.parents('form');
|
99
|
+
|
100
|
+
// Build a temporary form
|
101
|
+
$previewForm = $('<form />', {
|
102
|
+
action: $form.data('previewAction'),
|
103
|
+
target: '_blank',
|
104
|
+
method: 'POST',
|
105
|
+
css: { display: 'none' }
|
106
|
+
});
|
107
|
+
$('body').append($previewForm);
|
108
|
+
|
109
|
+
// Tell tinymce to write out to the textarea
|
110
|
+
tinyMCE.triggerSave();
|
111
|
+
|
112
|
+
// Copy fields into our temp form
|
113
|
+
$form.find('input, select, textarea').each(function(i, el){
|
114
|
+
var input = document.createElement('input');
|
115
|
+
input.name = el.name;
|
116
|
+
input.value = el.value;
|
117
|
+
$previewForm.append(input);
|
118
|
+
});
|
119
|
+
|
120
|
+
// Cross site scripting tag
|
121
|
+
var csrf = document.createElement('input');
|
122
|
+
csrf.name = 'authenticity_token';
|
123
|
+
csrf.value = tb.util.getCsrfToken();
|
124
|
+
$previewForm.append(csrf);
|
125
|
+
|
126
|
+
// Submit it
|
127
|
+
$button.button('loading');
|
128
|
+
$previewForm.submit();
|
129
|
+
|
130
|
+
setTimeout(function(){
|
131
|
+
$previewForm.remove();
|
132
|
+
$button.button('reset');
|
133
|
+
}, 2000);
|
134
|
+
};
|
135
|
+
|
94
136
|
})();
|
@@ -1,61 +1,61 @@
|
|
1
1
|
class Admin::PostCategoriesController < Admin::ApplicationController
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
3
|
+
layout false
|
4
|
+
respond_to :html, :json
|
5
|
+
|
6
|
+
before_action :find_category, only: [:show, :edit, :update, :destroy]
|
7
|
+
|
8
|
+
def index
|
9
|
+
@post_categories = SpudPostCategory.ordered
|
10
|
+
respond_with @post_categories
|
11
|
+
end
|
12
|
+
|
13
|
+
def edit
|
14
|
+
respond_with @post_category
|
15
|
+
end
|
16
|
+
|
17
|
+
def update
|
18
|
+
if @post_category.update_attributes(category_params)
|
19
|
+
flash.now[:notice] = 'Post Category was successfully updated'
|
20
|
+
respond_with @post_category, location: admin_post_categories_path
|
21
|
+
else
|
22
|
+
render 'new', status: 422
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def new
|
27
|
+
@post_category = SpudPostCategory.new
|
28
|
+
respond_with @post_category
|
29
|
+
end
|
30
|
+
|
31
|
+
def create
|
32
|
+
@post_category = SpudPostCategory.new(category_params)
|
33
|
+
if @post_category.save
|
34
|
+
flash.now[:notice] = 'Post Category was successfully created'
|
35
|
+
respond_with @post_category, location: admin_post_categories_path
|
36
|
+
else
|
37
|
+
render 'new', status: 422
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy
|
42
|
+
if @post_category.destroy
|
43
|
+
flash.now[:notice] = 'Post Category was successfully deleted'
|
44
|
+
@post_categories = SpudPostCategory.ordered
|
45
|
+
render 'index'
|
46
|
+
else
|
47
|
+
respond_with @post_category, location: admin_post_categories_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def find_category
|
54
|
+
@post_category = SpudPostCategory.find(params[:id])
|
55
|
+
end
|
56
|
+
|
57
|
+
def category_params
|
58
|
+
params.require(:spud_post_category).permit(:name)
|
59
|
+
end
|
60
60
|
|
61
61
|
end
|
@@ -1,104 +1,113 @@
|
|
1
1
|
class Admin::PostsController < Admin::ApplicationController
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
2
|
+
include BlogUrlHelpers
|
3
|
+
include PostViewForAction
|
4
|
+
|
5
|
+
respond_to :html, :xml, :json
|
6
|
+
before_action :load_blog
|
7
|
+
before_action :find_post, only: [:edit, :update, :destroy]
|
8
|
+
around_action :create_redirect_if_necessary, only: :update
|
9
|
+
|
10
|
+
def index
|
11
|
+
@posts = SpudPost.for_blog(params[:blog_key]).ordered.paginate(page: params[:page], per_page: 15)
|
12
|
+
@posts = @posts.search(params[:search]) if params[:search]
|
13
|
+
respond_with @posts
|
14
|
+
end
|
15
|
+
|
16
|
+
def edit
|
17
|
+
respond_with @post
|
18
|
+
end
|
19
|
+
|
20
|
+
def show
|
21
|
+
end
|
22
|
+
|
23
|
+
def update
|
24
|
+
if @post.update_attributes(post_params)
|
25
|
+
flash[:notice] = 'Post was successfully updated.'
|
26
|
+
end
|
27
|
+
respond_with @post, location: admin_posts_path
|
28
|
+
end
|
29
|
+
|
30
|
+
def new
|
31
|
+
@post = SpudPost.new(published_at: Time.zone.now, spud_user_id: current_user.id)
|
32
|
+
respond_with @post
|
33
|
+
end
|
34
|
+
|
35
|
+
def create
|
36
|
+
@post = SpudPost.new(post_params)
|
37
|
+
@post.blog_key = params[:blog_key]
|
38
|
+
flash[:notice] = 'Post was successfully created.' if @post.save
|
39
|
+
respond_with @post, location: admin_posts_path
|
40
|
+
end
|
41
|
+
|
42
|
+
def destroy
|
43
|
+
flash[:notice] = 'Post was successfully deleted.' if @post.destroy
|
44
|
+
respond_with @post, location: admin_posts_path
|
45
|
+
end
|
46
|
+
|
47
|
+
def preview
|
48
|
+
@post = if params[:post_id]
|
49
|
+
SpudPost.find_by!(id: params[:post_id])
|
50
|
+
else
|
51
|
+
SpudPost.new
|
52
|
+
end
|
53
|
+
@post.assign_attributes(post_params)
|
54
|
+
@post.postprocess_content()
|
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
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def find_post
|
65
|
+
@post = SpudPost.find(params[:id])
|
66
|
+
if @post.blank?
|
67
|
+
flash[:error] = 'Post not found!'
|
68
|
+
redirect_to(admin_posts_path) && (return false)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def post_params
|
73
|
+
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
|
77
|
+
p = params.require(:spud_post).permit(permitted)
|
78
|
+
p[:updated_at] = DateTime.now
|
79
|
+
return p
|
80
|
+
end
|
81
|
+
|
82
|
+
def load_blog
|
83
|
+
@config = SpudBlogConfig.find(params[:blog_key])
|
84
|
+
if @config.blank?
|
85
|
+
redirect_to admin_root_path
|
86
|
+
return false
|
87
|
+
else
|
88
|
+
act_as_app "#{@config.name} Posts".parameterize.underscore.to_sym
|
89
|
+
add_breadcrumb "#{@config.name} Posts", admin_posts_path(blog_key: @config.key)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Create a redirect if the post URL has changed
|
94
|
+
#
|
95
|
+
# Normally this sort of thing might belong in a model after_update hook, but the model
|
96
|
+
# layer has no knowledge of URL helpers.
|
97
|
+
#
|
98
|
+
def create_redirect_if_necessary
|
99
|
+
@_redirect_source = post_path(@post.url_name, blog_key: @post.blog_key, only_path: true)
|
100
|
+
yield
|
101
|
+
ensure
|
102
|
+
if @post.errors.empty?
|
103
|
+
@_redirect_destination = post_path(@post.url_name, blog_key: @post.blog_key, only_path: true)
|
104
|
+
if @_redirect_source != @_redirect_destination
|
105
|
+
TbRedirect.create_smart(source: @_redirect_source,
|
106
|
+
destination: @_redirect_destination,
|
107
|
+
created_by: 'blog',
|
108
|
+
owner: @post)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
103
112
|
|
104
113
|
end
|
@@ -3,49 +3,53 @@ 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
|
+
:admin_post_preview_path
|
7
8
|
end
|
8
9
|
|
9
|
-
def posts_path(opts={})
|
10
|
-
url_for opts.merge(
|
10
|
+
def posts_path(opts = {})
|
11
|
+
url_for opts.merge(controller: '/posts', action: 'index', blog_key: params[:blog_key])
|
11
12
|
end
|
12
13
|
|
13
|
-
def post_path(url_name, opts={})
|
14
|
-
url_for opts.merge(
|
14
|
+
def post_path(url_name, opts = {})
|
15
|
+
url_for opts.merge(controller: '/posts', action: 'show', id: url_name, blog_key: params[:blog_key])
|
15
16
|
end
|
16
17
|
|
17
|
-
def post_category_path(category_url_name, opts={})
|
18
|
-
url_for opts.merge(
|
18
|
+
def post_category_path(category_url_name, opts = {})
|
19
|
+
url_for opts.merge(controller: '/posts', action: 'category', category_url_name: category_url_name, blog_key: params[:blog_key])
|
19
20
|
end
|
20
21
|
|
21
|
-
def post_archive_path(archive_date, opts={})
|
22
|
-
url_for opts.merge(
|
22
|
+
def post_archive_path(archive_date, opts = {})
|
23
|
+
url_for opts.merge(controller: '/posts', action: 'archive', archive_date: archive_date, blog_key: params[:blog_key])
|
23
24
|
end
|
24
25
|
|
25
|
-
def post_category_archive_path(category_url_name, archive_date, opts={})
|
26
|
-
url_for opts.merge(
|
26
|
+
def post_category_archive_path(category_url_name, archive_date, opts = {})
|
27
|
+
url_for opts.merge(controller: '/posts', action: 'category', category_url_name: category_url_name, archive_date: archive_date, blog_key: params[:blog_key])
|
27
28
|
end
|
28
29
|
|
29
|
-
#
|
30
|
-
# Admin
|
31
|
-
#
|
30
|
+
#
|
31
|
+
# Admin
|
32
|
+
#
|
32
33
|
|
33
34
|
def admin_posts_path(blog_key: nil)
|
34
35
|
blog_key ||= params[:blog_key]
|
35
|
-
url_for :
|
36
|
+
url_for controller: '/admin/posts', action: 'index', blog_key: blog_key
|
36
37
|
end
|
37
38
|
|
38
39
|
def new_admin_post_path(blog_key: nil)
|
39
40
|
blog_key ||= params[:blog_key]
|
40
|
-
url_for :
|
41
|
+
url_for controller: '/admin/posts', action: 'new', blog_key: blog_key
|
41
42
|
end
|
42
43
|
|
43
44
|
def admin_post_path(post)
|
44
|
-
url_for :
|
45
|
+
url_for controller: '/admin/posts', action: 'show', id: post.id, blog_key: post.blog_key
|
45
46
|
end
|
46
47
|
|
47
48
|
def edit_admin_post_path(post)
|
48
|
-
url_for :
|
49
|
+
url_for controller: '/admin/posts', action: 'edit', id: post.id, blog_key: post.blog_key
|
49
50
|
end
|
50
51
|
|
52
|
+
def admin_post_preview_path(post)
|
53
|
+
url_for controller: '/admin/posts', action: :preview, post_id: post.id, blog_key: (post.blog_key || params[:blog_key])
|
54
|
+
end
|
51
55
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module PostViewForAction
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
def post_view_for_action(action)
|
5
|
+
if File.exist?(Rails.root.join("app/views/#{@config.key}/#{action}.html.erb"))
|
6
|
+
return "/#{@config.key}/#{action}"
|
7
|
+
else
|
8
|
+
return "/posts/#{action}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,21 +1,20 @@
|
|
1
1
|
class PostsController < ApplicationController
|
2
2
|
include BlogUrlHelpers
|
3
|
+
include PostViewForAction
|
3
4
|
|
4
|
-
|
5
|
+
respond_to :html, :json, :rss
|
5
6
|
|
6
7
|
before_action :load_blog
|
7
|
-
before_action :load_page_number, :
|
8
|
-
before_action :find_post, :
|
8
|
+
before_action :load_page_number, only: [:index, :archive, :category]
|
9
|
+
before_action :find_post, only: [:show, :create_comment]
|
9
10
|
|
10
11
|
def index
|
11
|
-
@posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).ordered.paginate(:
|
12
|
-
if params[:search]
|
13
|
-
@posts = @posts.search(params[:search])
|
14
|
-
end
|
12
|
+
@posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).ordered.paginate(page: @page_number, per_page: Spud::Blog.config.posts_per_page)
|
13
|
+
@posts = @posts.search(params[:search]) if params[:search]
|
15
14
|
respond_with @posts do |format|
|
16
|
-
format.html
|
17
|
-
render
|
18
|
-
|
15
|
+
format.html do
|
16
|
+
render post_view_for_action(:index)
|
17
|
+
end
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
@@ -33,37 +32,35 @@ class PostsController < ApplicationController
|
|
33
32
|
end
|
34
33
|
|
35
34
|
def category
|
36
|
-
if @post_category = SpudPostCategory.
|
37
|
-
@posts = @post_category.posts.for_user(current_user).visible.for_blog(params[:blog_key]).from_archive(params[:archive_date]).paginate(:
|
35
|
+
if @post_category = SpudPostCategory.find_by(url_name: params[:category_url_name])
|
36
|
+
@posts = @post_category.posts.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)
|
38
37
|
else
|
39
38
|
redirect_to posts_path
|
40
39
|
return
|
41
40
|
end
|
42
41
|
respond_with @posts do |format|
|
43
|
-
format.html { render
|
42
|
+
format.html { render post_view_for_action :index }
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
46
|
def archive
|
48
|
-
@posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).from_archive(params[:archive_date]).paginate(:
|
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)
|
49
48
|
respond_with @posts do |format|
|
50
|
-
format.html { render
|
49
|
+
format.html { render post_view_for_action :index }
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
53
|
def show
|
55
|
-
|
56
|
-
format.html { render
|
54
|
+
respond_with @post do |format|
|
55
|
+
format.html { render post_view_for_action :show }
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
60
|
-
private
|
59
|
+
private
|
61
60
|
|
62
61
|
def find_post
|
63
|
-
@post = SpudPost.for_user(current_user).for_blog(params[:blog_key]).where(:
|
64
|
-
|
65
|
-
raise Spud::NotFoundError.new(:item => 'post')
|
66
|
-
end
|
62
|
+
@post = SpudPost.for_user(current_user).for_blog(params[:blog_key]).where(url_name: params[:id]).first
|
63
|
+
raise Spud::NotFoundError, item: 'post' if @post.blank? || @post.is_private?
|
67
64
|
end
|
68
65
|
|
69
66
|
def load_page_number
|
@@ -71,10 +68,10 @@ private
|
|
71
68
|
if params[:page].present?
|
72
69
|
page = params[:page].to_i
|
73
70
|
if page.to_s != params[:page].to_s
|
74
|
-
if
|
75
|
-
redirect_to
|
71
|
+
if page > 1
|
72
|
+
redirect_to(posts_path(page: page), status: :moved_permanently) && return
|
76
73
|
else
|
77
|
-
redirect_to
|
74
|
+
redirect_to(posts_path(page: nil), status: :moved_permanently) && return
|
78
75
|
end
|
79
76
|
end
|
80
77
|
end
|
@@ -84,19 +81,11 @@ private
|
|
84
81
|
def load_blog
|
85
82
|
@config = SpudBlogConfig.find(params[:blog_key])
|
86
83
|
if @config.blank?
|
87
|
-
raise Spud::NotFoundError(:
|
84
|
+
raise Spud::NotFoundError(item: 'blog')
|
88
85
|
return false
|
89
86
|
else
|
90
87
|
self.class.layout(@config.layout)
|
91
88
|
end
|
92
89
|
end
|
93
90
|
|
94
|
-
def view_for_action(action)
|
95
|
-
if File.exist?(Rails.root.join("app/views/#{@config.key}/#{action}.html.erb"))
|
96
|
-
return "#{@config.key}/#{action}"
|
97
|
-
else
|
98
|
-
return action
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
91
|
end
|