spud_blog 0.8.18 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/images/spud/admin/news_thumb@2x.png +0 -0
- data/app/assets/javascripts/spud/admin/post_categories.js +116 -2
- data/app/assets/javascripts/spud/admin/posts.js +52 -10
- data/app/assets/stylesheets/spud/admin/posts.css +93 -38
- data/app/controllers/blog_controller.rb +2 -4
- data/app/controllers/news_controller.rb +4 -4
- data/app/controllers/spud/admin/news_posts_controller.rb +2 -2
- data/app/controllers/spud/admin/post_categories_controller.rb +14 -8
- data/app/controllers/spud/admin/posts_controller.rb +1 -1
- data/app/controllers/spud/blog/sitemaps_controller.rb +2 -2
- data/app/models/spud_post_categories_post.rb +5 -0
- data/app/models/spud_post_category.rb +12 -7
- data/app/models/spud_post_category_sweeper.rb +3 -3
- data/app/models/spud_post_comment_sweeper.rb +4 -4
- data/app/models/spud_post_sweeper.rb +5 -5
- data/app/views/blog/index.html.erb +6 -2
- data/app/views/blog/show.html.erb +1 -1
- data/app/views/news/index.html.erb +6 -2
- data/app/views/news/show.html.erb +2 -2
- data/app/views/spud/admin/news_posts/index.html.erb +6 -1
- data/app/views/spud/admin/news_posts/new.html.erb +1 -1
- data/app/views/spud/admin/post_categories/_category.html.erb +14 -0
- data/app/views/spud/admin/post_categories/_form.html.erb +17 -27
- data/app/views/spud/admin/post_categories/edit.html.erb +1 -1
- data/app/views/spud/admin/post_categories/index.html.erb +6 -29
- data/app/views/spud/admin/posts/_category.html.erb +7 -7
- data/app/views/spud/admin/posts/_form.html.erb +70 -67
- data/app/views/spud/admin/posts/index.html.erb +5 -0
- data/app/views/spud/admin/posts/new.html.erb +1 -1
- data/db/migrate/20121113135812_add_nested_set_to_post_categories.rb +21 -0
- data/lib/spud_blog/configuration.rb +3 -4
- data/lib/spud_blog/engine.rb +6 -6
- data/lib/spud_blog/version.rb +1 -1
- data/test/dummy/log/development.log +36 -0
- metadata +44 -19
- data/app/assets/javascripts/spud/admin/news_posts.js +0 -2
- data/app/assets/javascripts/spud/admin/post_comments.js +0 -2
- data/app/assets/stylesheets/spud/admin/news_posts.css +0 -4
- data/app/assets/stylesheets/spud/admin/post_categories.css +0 -4
- data/app/assets/stylesheets/spud/admin/post_comments.css +0 -4
- data/app/views/layouts/spud/admin/post.html.erb +0 -5
- data/app/views/spud/admin/post_categories/show.html.erb +0 -0
Binary file
|
@@ -1,2 +1,116 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Spud = (typeof(Spud) == 'undefined') ? {} : Spud;
|
2
|
+
Spud.Admin = (typeof(Spud.Admin) == 'undefined') ? {} : Spud.Admin;
|
3
|
+
|
4
|
+
Spud.Admin.PostCategories = new function(){
|
5
|
+
|
6
|
+
var self = this;
|
7
|
+
var _cachedCategoryIndex;
|
8
|
+
|
9
|
+
this.index = function(){
|
10
|
+
$('.spud_blog_manage_categories').live('click', self.clickedManageCategories);
|
11
|
+
$('.spud_blog_category_add_new').live('click', self.clickedAddNewCategory);
|
12
|
+
$('.spud_blog_category_edit').live('click', self.clickedEditCategory);
|
13
|
+
$('.spud_blog_manage_categories_back').live('click', self.clickedBackButton);
|
14
|
+
$('.spud_blog_manage_categories_save').live('click', self.submittedPostCategoryForm);
|
15
|
+
$('.spud_post_category_form').live('submit', self.submittedPostCategoryForm);
|
16
|
+
$('.spud_blog_category_delete').live('click', self.clickedDeleteCategory);
|
17
|
+
};
|
18
|
+
|
19
|
+
this.clickedManageCategories = function(e){
|
20
|
+
e.preventDefault();
|
21
|
+
$.ajax({
|
22
|
+
url: $(this).attr('href'),
|
23
|
+
success: function(html, textStatus, jqXHR){
|
24
|
+
_cachedCategoryIndex = html;
|
25
|
+
displayModalDialogWithOptions({
|
26
|
+
title: 'Manage Categories',
|
27
|
+
html: html,
|
28
|
+
buttons: {
|
29
|
+
'spud_blog_manage_categories_back': 'Back',
|
30
|
+
'spud_blog_manage_categories_save btn-primary': 'Save'
|
31
|
+
}
|
32
|
+
});
|
33
|
+
}
|
34
|
+
});
|
35
|
+
};
|
36
|
+
|
37
|
+
this.clickedAddNewCategory = function(e){
|
38
|
+
e.preventDefault();
|
39
|
+
$.ajax({
|
40
|
+
url: $(this).attr('href'),
|
41
|
+
dataType: 'html',
|
42
|
+
success: function(html, textStatus, jqXHR){
|
43
|
+
$('.modal-footer button[data-dismiss="modal"]').hide();
|
44
|
+
$('.spud_blog_manage_categories_save, .spud_blog_manage_categories_back').show();
|
45
|
+
$('.spud_blog_category_manager').replaceWith(html);
|
46
|
+
}
|
47
|
+
});
|
48
|
+
};
|
49
|
+
|
50
|
+
this.clickedEditCategory = function(e){
|
51
|
+
e.preventDefault();
|
52
|
+
$.ajax({
|
53
|
+
url: $(this).attr('href'),
|
54
|
+
dataType: 'html',
|
55
|
+
success: function(html, textStatus, jqXHR){
|
56
|
+
$('.modal-footer button[data-dismiss="modal"]').hide();
|
57
|
+
$('.spud_blog_manage_categories_save, .spud_blog_manage_categories_back').show();
|
58
|
+
$('.spud_blog_category_manager').replaceWith(html);
|
59
|
+
}
|
60
|
+
});
|
61
|
+
};
|
62
|
+
|
63
|
+
this.clickedBackButton = function(e){
|
64
|
+
e.preventDefault();
|
65
|
+
$('.spud_post_category_form').replaceWith(_cachedCategoryIndex);
|
66
|
+
$('.modal-footer button[data-dismiss="modal"]').show();
|
67
|
+
$('.spud_blog_manage_categories_save, .spud_blog_manage_categories_back').hide();
|
68
|
+
};
|
69
|
+
|
70
|
+
this.clickedDeleteCategory = function(e){
|
71
|
+
e.preventDefault();
|
72
|
+
if(window.confirm('Are you sure you want to delete this category?')){
|
73
|
+
$.ajax({
|
74
|
+
url: $(this).attr('href'),
|
75
|
+
data: {_method: 'delete'},
|
76
|
+
type: 'delete',
|
77
|
+
dataType: 'html',
|
78
|
+
success: function(html, textStatus, jqXHR){
|
79
|
+
_cachedCategoryIndex = html;
|
80
|
+
$('.spud_blog_category_manager').replaceWith(html);
|
81
|
+
}
|
82
|
+
});
|
83
|
+
}
|
84
|
+
};
|
85
|
+
|
86
|
+
this.submittedPostCategoryForm = function(e){
|
87
|
+
e.preventDefault();
|
88
|
+
var form = $('.spud_post_category_form');
|
89
|
+
$.ajax({
|
90
|
+
url: form.attr('action'),
|
91
|
+
data: form.serialize(),
|
92
|
+
type: 'post',
|
93
|
+
dataType: 'html',
|
94
|
+
success: self.savedPostCategorySuccess,
|
95
|
+
error: self.savePostCategoryError
|
96
|
+
});
|
97
|
+
};
|
98
|
+
|
99
|
+
this.savedPostCategorySuccess = function(html, textStatus, jqXHR){
|
100
|
+
_cachedCategoryIndex = html;
|
101
|
+
$('.spud_blog_manage_categories_save, .spud_blog_manage_categories_back').hide();
|
102
|
+
$('.spud_post_category_form').replaceWith(html);
|
103
|
+
};
|
104
|
+
|
105
|
+
this.savePostCategoryError = function(jqXHR, textStatus, errorThrown){
|
106
|
+
if(jqXHR.status == 422){
|
107
|
+
var html = jqXHR.responseText;
|
108
|
+
$('.spud_post_category_form').replaceWith(html);
|
109
|
+
}
|
110
|
+
else{
|
111
|
+
if(window.console){
|
112
|
+
console.error('Oh Snap:', arguments);
|
113
|
+
}
|
114
|
+
}
|
115
|
+
};
|
116
|
+
};
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
// All this logic will automatically be available in application.js.
|
1
|
+
//= require spud/admin/post_categories
|
3
2
|
|
4
3
|
Spud = (typeof(Spud) == 'undefined') ? {} : Spud;
|
5
4
|
Spud.Admin = (typeof(Spud.Admin) == 'undefined') ? {} : Spud.Admin;
|
@@ -9,21 +8,64 @@ Spud.Admin.Posts = new function(){
|
|
9
8
|
var self = this;
|
10
9
|
|
11
10
|
this.edit = function(){
|
12
|
-
$('input[type=submit],.close_dialog').button();
|
13
11
|
initDatePicker();
|
14
12
|
initTinyMCE();
|
15
|
-
$('
|
13
|
+
$('.spud_post_add_category').live('click', self.clickedPostAddCategory);
|
14
|
+
$('.save_post_category_button').live('click', self.submittedPostCategoryForm);
|
15
|
+
$('.spud_post_category_form').live('submit', self.submittedPostCategoryForm);
|
16
16
|
};
|
17
17
|
|
18
|
-
this.
|
18
|
+
this.clickedPostAddCategory = function(e){
|
19
|
+
e.preventDefault();
|
19
20
|
$.ajax({
|
20
|
-
url: $(
|
21
|
+
url: $(this).attr('href'),
|
22
|
+
dataType: 'html',
|
23
|
+
success: function(html, textStatus, jqXHR){
|
24
|
+
displayModalDialogWithOptions({
|
25
|
+
title: 'Add Category',
|
26
|
+
html: html
|
27
|
+
});
|
28
|
+
}
|
29
|
+
});
|
30
|
+
};
|
31
|
+
|
32
|
+
this.submittedPostCategoryForm = function(e){
|
33
|
+
e.preventDefault();
|
34
|
+
var form = $('.spud_post_category_form');
|
35
|
+
$.ajax({
|
36
|
+
url: form.attr('action'),
|
37
|
+
data: form.serialize(),
|
21
38
|
type: 'post',
|
22
39
|
dataType: 'json',
|
23
|
-
|
24
|
-
|
25
|
-
'spud_post_category[parent_id]': $('#spud_post_new_category_parent_id').val()
|
26
|
-
}
|
40
|
+
success: self.savedPostCategorySuccess,
|
41
|
+
error: self.savePostCategoryError
|
27
42
|
});
|
28
43
|
};
|
44
|
+
|
45
|
+
this.savedPostCategorySuccess = function(data, textStatus, jqXHR){
|
46
|
+
var checkbox = '';
|
47
|
+
checkbox += '<li class="spud_post_form_category" data-id="'+data.id+'">';
|
48
|
+
checkbox += '<input id="spud_post_category_'+data.id+'" name="spud_post[category_ids][]" type="checkbox" value="'+data.id+'" checked>' + "\n";
|
49
|
+
checkbox += '<label for="spud_post_category_'+data.id+'">'+data.name+'</label>';
|
50
|
+
checkbox += '<ul></ul></li>';
|
51
|
+
if(data.parent_id > 0){
|
52
|
+
$('.spud_post_form_category[data-id="'+data.parent_id+'"]>ul').append(checkbox);
|
53
|
+
}
|
54
|
+
else{
|
55
|
+
$('.spud_post_categories_form').append(checkbox);
|
56
|
+
}
|
57
|
+
hideModalDialog();
|
58
|
+
};
|
59
|
+
|
60
|
+
this.savePostCategoryError = function(jqXHR, textStatus, errorThrown){
|
61
|
+
if(jqXHR.status == 422){
|
62
|
+
var html = jqXHR.responseText;
|
63
|
+
$('.spud_post_category_form').replaceWith(html);
|
64
|
+
}
|
65
|
+
else{
|
66
|
+
if(window.console){
|
67
|
+
console.error('Oh Snap:', arguments);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
};
|
29
71
|
};
|
@@ -1,52 +1,107 @@
|
|
1
|
-
/*
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
/* Form Layout
|
2
|
+
---------------- */
|
3
|
+
.spud_post_form_fieldset{
|
4
|
+
margin: 30px 0;
|
5
|
+
}
|
6
|
+
.spud_post_form_col{
|
7
|
+
width: 400px;
|
8
|
+
float: left;
|
9
|
+
margin: 0 20px;
|
10
|
+
}
|
11
|
+
.spud_post_form_input_group{
|
12
|
+
border: 1px dashed #E5E5E5;
|
13
|
+
padding: 4px;
|
14
|
+
margin: 0 0 10px;
|
15
|
+
}
|
16
|
+
.spud_post_form_input_group input{
|
17
|
+
display: inline-block;
|
18
|
+
}
|
19
|
+
.spud_post_form_input_group select{
|
20
|
+
margin-bottom: 20px;
|
21
|
+
}
|
22
|
+
.spud_post_form_input_group label{
|
23
|
+
margin: 0 10px 0 0;
|
24
|
+
padding: 0;
|
25
|
+
}
|
26
|
+
.spud_post_form_row{
|
27
|
+
margin: 5px 0;
|
28
|
+
}
|
29
|
+
.spud_post_form_help_block{
|
30
|
+
font-size: 12px;
|
31
|
+
font-style: italic;
|
32
|
+
margin: 0 0 20px;
|
33
|
+
display: block;
|
34
|
+
}
|
35
|
+
#spud_post_meta_keywords, #spud_post_meta_description{
|
36
|
+
width: 380px;
|
37
|
+
}
|
38
|
+
#spud_post_meta_description{
|
39
|
+
height: 100px;
|
40
|
+
}
|
5
41
|
|
6
|
-
|
42
|
+
/* Categories
|
43
|
+
-------------- */
|
44
|
+
.spud_post_categories_form{
|
45
|
+
white-space: nowrap;
|
7
46
|
list-style-type: none;
|
8
|
-
margin: 15px 0
|
9
|
-
height:
|
10
|
-
|
47
|
+
margin: 15px 0;
|
48
|
+
max-height: 400px;
|
49
|
+
min-height: 200px;
|
11
50
|
background: white;
|
12
|
-
border: 1px solid #
|
13
|
-
padding: 10px;
|
14
|
-
overflow:
|
51
|
+
border: 1px solid #E5E5E5;
|
52
|
+
padding: 10px 0 10px 15px;
|
53
|
+
overflow: auto;
|
54
|
+
border-radius: 5px;
|
15
55
|
}
|
16
|
-
|
56
|
+
.spud_post_categories_form ul{
|
17
57
|
list-style-type: none;
|
18
|
-
margin:
|
19
|
-
padding: 0 0 0
|
58
|
+
margin: 0;
|
59
|
+
padding: 0 0 0 15px;
|
60
|
+
}
|
61
|
+
.spud_post_categories_form input{
|
62
|
+
display: inline-block;
|
63
|
+
margin: 0;
|
20
64
|
}
|
21
|
-
|
22
|
-
float: none;
|
23
|
-
text-align: left;
|
65
|
+
.spud_post_categories_form label{
|
24
66
|
display: inline;
|
25
67
|
}
|
26
|
-
|
27
|
-
|
28
|
-
border: 1px solid #ccc;
|
29
|
-
margin: 15px 0 15px 20px;
|
30
|
-
padding: 10px 20px;
|
31
|
-
overflow: hidden;
|
32
|
-
width: 380px;
|
68
|
+
.spud_post_form_category{
|
69
|
+
margin: 4px 0;
|
33
70
|
}
|
34
|
-
|
35
|
-
|
71
|
+
|
72
|
+
/* Category Manager
|
73
|
+
------------------- */
|
74
|
+
.spud_blog_category_add_new{
|
75
|
+
float: right;
|
36
76
|
}
|
37
|
-
|
38
|
-
|
77
|
+
.spud_blog_category_manager{
|
78
|
+
padding-right: 10px;
|
39
79
|
}
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
80
|
+
.spud_blog_category_manager ul{
|
81
|
+
|
82
|
+
}
|
83
|
+
.spud_blog_category_manager_list{
|
84
|
+
clear: right;
|
85
|
+
padding: 0 0 0 20px;
|
86
|
+
margin: 10px 0;
|
87
|
+
min-height: 100px;
|
88
|
+
max-height: 350px;
|
89
|
+
overflow: auto;
|
90
|
+
}
|
91
|
+
.spud_blog_category_manager_item{
|
92
|
+
position: relative;
|
93
|
+
margin: 10px 0;
|
94
|
+
/*border: 1px solid #E5E5E5;*/
|
95
|
+
}
|
96
|
+
.spud_blog_category_manager_item_children{
|
97
|
+
margin: 0;
|
98
|
+
padding: 0 0 0 15px;
|
46
99
|
}
|
47
|
-
|
48
|
-
|
100
|
+
.spud_blog_category_manager_item_actions{
|
101
|
+
position: absolute;
|
102
|
+
right: 0;
|
103
|
+
margin: 0 0 0 10px;
|
49
104
|
}
|
50
|
-
|
51
|
-
|
105
|
+
.spud_blog_manage_categories_save, .spud_blog_manage_categories_back{
|
106
|
+
display: none;
|
52
107
|
}
|
@@ -8,11 +8,11 @@ class BlogController < ApplicationController
|
|
8
8
|
caches_action :show, :index,
|
9
9
|
:expires => Spud::Blog.config.action_caching_duration,
|
10
10
|
:if => Proc.new{ |c|
|
11
|
-
Spud::Blog.
|
11
|
+
Spud::Blog.cache_mode == :action && !(c.params[:page] && c.params[:page].to_i > 1) && (SpudPost.where(:is_news => false).future_posts.count == 0)
|
12
12
|
}
|
13
13
|
|
14
14
|
after_filter :only => [:show, :index] do |c|
|
15
|
-
if Spud::Blog.
|
15
|
+
if Spud::Blog.cache_mode == :full_page && !(c.params[:page] && c.params[:page].to_i > 1)
|
16
16
|
if (SpudPost.where(:is_news => false).future_posts.count == 0)
|
17
17
|
c.cache_page(nil, nil, false)
|
18
18
|
end
|
@@ -30,8 +30,6 @@ class BlogController < ApplicationController
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
logger.debug("Page = #{page}")
|
35
33
|
@posts = SpudPost.public_blog_posts(page, Spud::Blog.config.posts_per_page)
|
36
34
|
if Spud::Core.config.multisite_mode_enabled
|
37
35
|
@posts = @posts.for_spud_site(current_site_id)
|
@@ -6,11 +6,11 @@ class NewsController < ApplicationController
|
|
6
6
|
caches_action :show, :index,
|
7
7
|
:expires => Spud::Blog.config.action_caching_duration,
|
8
8
|
:if => Proc.new{ |c|
|
9
|
-
Spud::Blog.
|
9
|
+
Spud::Blog.cache_mode == :action && !(c.params[:page] && c.params[:page].to_i > 1) && (SpudPost.where(:is_news => true).future_posts.count == 0)
|
10
10
|
}
|
11
11
|
|
12
12
|
after_filter :only => [:show, :index] do |c|
|
13
|
-
if Spud::Blog.
|
13
|
+
if Spud::Blog.cache_mode == :full_page && !(c.params[:page] && c.params[:page].to_i > 1)
|
14
14
|
if (SpudPost.where(:is_news => true).future_posts.count == 0)
|
15
15
|
c.cache_page(nil, nil, false)
|
16
16
|
end
|
@@ -23,7 +23,7 @@ class NewsController < ApplicationController
|
|
23
23
|
@posts = SpudPost.public_news_posts(params[:page], Spud::Blog.config.posts_per_page)
|
24
24
|
if Spud::Core.config.multisite_mode_enabled
|
25
25
|
@posts = @posts.for_spud_site(current_site_id)
|
26
|
-
end
|
26
|
+
end
|
27
27
|
respond_with @posts
|
28
28
|
end
|
29
29
|
|
@@ -77,4 +77,4 @@ class NewsController < ApplicationController
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
end
|
80
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Spud::Admin::NewsPostsController < Spud::Admin::ApplicationController
|
2
2
|
|
3
|
-
layout 'spud/admin/
|
3
|
+
layout 'spud/admin/detail'
|
4
4
|
respond_to :html, :xml, :json
|
5
5
|
before_filter :find_post, :only => [:show, :edit, :update, :destroy]
|
6
6
|
add_breadcrumb 'News Posts', :spud_admin_news_posts_path
|
@@ -59,4 +59,4 @@ class Spud::Admin::NewsPostsController < Spud::Admin::ApplicationController
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
end
|
62
|
+
end
|
@@ -1,14 +1,13 @@
|
|
1
1
|
class Spud::Admin::PostCategoriesController < Spud::Admin::ApplicationController
|
2
2
|
|
3
|
-
layout
|
4
|
-
respond_to :html, :
|
3
|
+
layout false
|
4
|
+
respond_to :html, :json
|
5
|
+
|
5
6
|
before_filter :find_category, :only => [:show, :edit, :update, :destroy]
|
6
|
-
add_breadcrumb 'Post Categories', :spud_admin_post_categories_path
|
7
|
-
belongs_to_spud_app :post_categories
|
8
7
|
cache_sweeper :spud_post_category_sweeper, :only => [:create, :update, :destroy]
|
9
8
|
|
10
9
|
def index
|
11
|
-
@post_categories = SpudPostCategory.
|
10
|
+
@post_categories = SpudPostCategory.grouped
|
12
11
|
respond_with @post_categories
|
13
12
|
end
|
14
13
|
|
@@ -20,8 +19,10 @@ class Spud::Admin::PostCategoriesController < Spud::Admin::ApplicationController
|
|
20
19
|
if @post_category.update_attributes(params[:spud_post_category])
|
21
20
|
flash[:notice] = 'Post Category was successfully updated'
|
22
21
|
expire_post_actions
|
22
|
+
respond_with @post_category, :location => spud_admin_post_categories_path
|
23
|
+
else
|
24
|
+
render 'new', :status => 422
|
23
25
|
end
|
24
|
-
respond_with @post_category, :location => spud_admin_post_categories_path
|
25
26
|
end
|
26
27
|
|
27
28
|
def new
|
@@ -34,16 +35,21 @@ class Spud::Admin::PostCategoriesController < Spud::Admin::ApplicationController
|
|
34
35
|
if @post_category.save
|
35
36
|
flash[:notice] = 'Post Category was successfully created'
|
36
37
|
expire_post_actions
|
38
|
+
respond_with @post_category, :location => spud_admin_post_categories_path
|
39
|
+
else
|
40
|
+
render 'new', :status => 422
|
37
41
|
end
|
38
|
-
respond_with @post_category, :location => spud_admin_post_categories_path
|
39
42
|
end
|
40
43
|
|
41
44
|
def destroy
|
42
45
|
if @post_category.destroy
|
43
46
|
flash[:notice] = 'Post Category was successfully deleted'
|
44
47
|
expire_post_actions
|
48
|
+
@post_categories = SpudPostCategory.grouped
|
49
|
+
render 'index'
|
50
|
+
else
|
51
|
+
respond_with @post_category, :location => spud_admin_post_categories_path
|
45
52
|
end
|
46
|
-
respond_with @post_category, :location => spud_admin_post_categories_path
|
47
53
|
end
|
48
54
|
|
49
55
|
private
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Spud::Admin::PostsController < Spud::Admin::ApplicationController
|
2
2
|
|
3
|
-
layout 'spud/admin/
|
3
|
+
layout 'spud/admin/detail'
|
4
4
|
respond_to :html, :xml, :json
|
5
5
|
before_filter :find_post, :only => [:show, :edit, :update, :destroy]
|
6
6
|
add_breadcrumb 'Blog Posts', :spud_admin_posts_path
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Spud::Blog::SitemapsController < Spud::ApplicationController
|
2
2
|
respond_to :xml
|
3
|
-
caches_action :show, :expires_in => 1.day, :if => Proc.new{ |c| Spud::Blog.
|
4
|
-
caches_page :show, :if => Proc.new{ |c| Spud::Blog.
|
3
|
+
caches_action :show, :expires_in => 1.day, :if => Proc.new{ |c| Spud::Blog.cache_mode == :action }
|
4
|
+
caches_page :show, :if => Proc.new{ |c| Spud::Blog.cache_mode == :full_page }
|
5
5
|
def show
|
6
6
|
@posts = SpudPost.publicly.all
|
7
7
|
respond_with @pages
|
@@ -1,22 +1,25 @@
|
|
1
1
|
class SpudPostCategory < ActiveRecord::Base
|
2
2
|
searchable
|
3
|
+
acts_as_nested_set
|
4
|
+
|
3
5
|
has_and_belongs_to_many :posts,
|
4
6
|
:class_name => 'SpudPost',
|
5
7
|
:join_table => 'spud_post_categories_posts',
|
6
8
|
:foreign_key => 'spud_post_category_id'
|
7
|
-
has_many :children, :class_name => 'SpudPostCategory', :foreign_key => 'parent_id'
|
8
9
|
|
9
10
|
validates_presence_of :name, :url_name
|
10
11
|
validates_uniqueness_of :name, :url_name
|
11
|
-
validate :parent_is_valid
|
12
12
|
before_validation :set_url_name
|
13
13
|
|
14
14
|
before_destroy :update_child_categories
|
15
15
|
|
16
|
-
scope :top_level, where(:parent_id => 0).order('name asc')
|
17
|
-
|
18
16
|
attr_accessible :name, :url_name, :parent_id
|
19
17
|
|
18
|
+
# tell awesome_nested_set not to destroy descendants
|
19
|
+
def skip_before_destroy
|
20
|
+
return true
|
21
|
+
end
|
22
|
+
|
20
23
|
def self.grouped
|
21
24
|
return all.group_by(&:parent_id)
|
22
25
|
end
|
@@ -27,7 +30,7 @@ class SpudPostCategory < ActiveRecord::Base
|
|
27
30
|
def self.options_for_categories(config={})
|
28
31
|
collection = config[:collection] || self.grouped
|
29
32
|
level = config[:level] || 0
|
30
|
-
parent_id = config[:parent_id] ||
|
33
|
+
parent_id = config[:parent_id] || nil
|
31
34
|
filter = config[:filter] || nil
|
32
35
|
value = config[:value] || :id
|
33
36
|
list = []
|
@@ -43,8 +46,9 @@ class SpudPostCategory < ActiveRecord::Base
|
|
43
46
|
end
|
44
47
|
|
45
48
|
def posts_with_children
|
46
|
-
|
47
|
-
|
49
|
+
category_ids = self.self_and_ancestors.collect{ |category| category.id }
|
50
|
+
post_ids = SpudPostCategoriesPost.where(:spud_post_category_id => category_ids).collect{ |it| it.spud_post_id }
|
51
|
+
return SpudPost.where(:id => post_ids)
|
48
52
|
end
|
49
53
|
|
50
54
|
private
|
@@ -61,5 +65,6 @@ class SpudPostCategory < ActiveRecord::Base
|
|
61
65
|
|
62
66
|
def update_child_categories
|
63
67
|
self.children.update_all(:parent_id => self.parent_id)
|
68
|
+
self.class.rebuild!
|
64
69
|
end
|
65
70
|
end
|
@@ -13,7 +13,7 @@ class SpudPostCategorySweeper < ActionController::Caching::Sweeper
|
|
13
13
|
private
|
14
14
|
|
15
15
|
def expire_cache_for(record)
|
16
|
-
if Spud::Blog.config.
|
16
|
+
if Spud::Blog.config.cache_mode = :action
|
17
17
|
SpudPost.find_each do |p|
|
18
18
|
if p.is_news && Spud::Blog.config.news_enabled
|
19
19
|
expire_action news_post_url(p.url_name)
|
@@ -25,7 +25,7 @@ class SpudPostCategorySweeper < ActionController::Caching::Sweeper
|
|
25
25
|
expire_action blog_url if Spud::Blog.config.blog_enabled
|
26
26
|
expire_action spud_blog_sitemap_url
|
27
27
|
end
|
28
|
-
if Spud::Blog.config.
|
28
|
+
if Spud::Blog.config.cache_mode = :full_page
|
29
29
|
SpudPost.find_each do |p|
|
30
30
|
if p.is_news && Spud::Blog.config.news_enabled
|
31
31
|
expire_page news_post_path(p.url_name)
|
@@ -38,4 +38,4 @@ class SpudPostCategorySweeper < ActionController::Caching::Sweeper
|
|
38
38
|
expire_page spud_blog_sitemap_path(:format => :xml)
|
39
39
|
end
|
40
40
|
end
|
41
|
-
end
|
41
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class SpudPostCommentSweeper < ActionController::Caching::Sweeper
|
2
|
-
|
2
|
+
|
3
3
|
observe SpudPostComment
|
4
4
|
|
5
5
|
def after_save(record)
|
@@ -14,14 +14,14 @@ class SpudPostCommentSweeper < ActionController::Caching::Sweeper
|
|
14
14
|
|
15
15
|
def expire_cache_for(record)
|
16
16
|
unless record.post.nil?
|
17
|
-
if Spud::Blog.config.
|
17
|
+
if Spud::Blog.config.cache_mode == :action
|
18
18
|
if record.post.is_news
|
19
19
|
expire_action news_post_url(record.post.url_name)
|
20
20
|
else
|
21
21
|
expire_action blog_post_url(record.post.url_name)
|
22
22
|
end
|
23
23
|
end
|
24
|
-
if Spud::Blog.config.
|
24
|
+
if Spud::Blog.config.cache_mode == :full_page
|
25
25
|
if record.post.is_news
|
26
26
|
expire_page news_post_path(record.post.url_name)
|
27
27
|
else
|
@@ -30,4 +30,4 @@ class SpudPostCommentSweeper < ActionController::Caching::Sweeper
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class SpudPostSweeper < ActionController::Caching::Sweeper
|
2
|
-
|
2
|
+
|
3
3
|
observe SpudPost
|
4
4
|
|
5
5
|
def after_create(record)
|
@@ -17,10 +17,10 @@ class SpudPostSweeper < ActionController::Caching::Sweeper
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def expire_cache_for(record)
|
20
|
-
if Spud::Blog.config.
|
20
|
+
if Spud::Blog.config.cache_mode == :action
|
21
21
|
expire_action spud_blog_sitemap_url
|
22
22
|
if !record.is_news && Spud::Blog.config.blog_enabled
|
23
|
-
expire_action blog_url
|
23
|
+
expire_action blog_url
|
24
24
|
expire_action blog_url(:format => :rss)
|
25
25
|
expire_action blog_post_url(record.url_name)
|
26
26
|
elsif Spud::Blog.config.news_enabled
|
@@ -29,7 +29,7 @@ class SpudPostSweeper < ActionController::Caching::Sweeper
|
|
29
29
|
expire_action news_post_url(record.url_name)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
if Spud::Blog.config.
|
32
|
+
if Spud::Blog.config.cache_mode == :full_page
|
33
33
|
expire_page spud_blog_sitemap_path(:format => :xml)
|
34
34
|
if record.is_news && Spud::Blog.config.news_enabled
|
35
35
|
expire_page news_path
|
@@ -44,4 +44,4 @@ class SpudPostSweeper < ActionController::Caching::Sweeper
|
|
44
44
|
expire_page spud_sitemap_path(:format => :xml)
|
45
45
|
end
|
46
46
|
|
47
|
-
end
|
47
|
+
end
|
@@ -1,3 +1,7 @@
|
|
1
|
+
<% content_for :title do %>
|
2
|
+
Blog | <%=current_site_name%>
|
3
|
+
<% end %>
|
4
|
+
|
1
5
|
<% content_for :head do %>
|
2
6
|
<%= spud_blog_rss_link %>
|
3
7
|
<% end %>
|
@@ -19,7 +23,7 @@
|
|
19
23
|
<h3><%= link_to post.title, blog_post_path(post.url_name) %></h3>
|
20
24
|
<h4>Posted by <%= post.author.full_name %> on <%= post.display_date %></h4>
|
21
25
|
<div class="spud_blog_post_content">
|
22
|
-
<%=
|
26
|
+
<%= truncate_html post.content.html_safe, :length => 250 %>
|
23
27
|
</div>
|
24
28
|
</div>
|
25
29
|
<% end %>
|
@@ -28,4 +32,4 @@
|
|
28
32
|
<% end %>
|
29
33
|
</div>
|
30
34
|
|
31
|
-
<%= will_paginate @posts %>
|
35
|
+
<%= will_paginate @posts %>
|