tb_blog 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/Readme.markdown +3 -2
- data/app/assets/javascripts/admin/blog/application.js +1 -0
- data/app/assets/javascripts/{spud/admin → admin/blog}/post_categories.js +0 -3
- data/app/assets/javascripts/{spud/admin → admin/blog}/posts.js +0 -6
- data/app/controllers/{spud/admin → admin}/news_posts_controller.rb +13 -11
- data/app/controllers/{spud/admin → admin}/post_categories_controller.rb +9 -7
- data/app/controllers/{spud/admin → admin}/post_comments_controller.rb +6 -7
- data/app/controllers/{spud/admin → admin}/posts_controller.rb +14 -11
- data/app/controllers/blog/sitemaps_controller.rb +10 -0
- data/app/controllers/blog_controller.rb +25 -34
- data/app/controllers/news_controller.rb +5 -21
- data/app/helpers/admin/news_posts_helper.rb +2 -0
- data/app/helpers/admin/post_categories_helper.rb +2 -0
- data/app/helpers/admin/post_comments_helper.rb +3 -0
- data/app/helpers/{spud/admin → admin}/posts_helper.rb +1 -1
- data/app/helpers/blog/sitemaps_helper.rb +2 -0
- data/app/helpers/blog_helper.rb +0 -1
- data/app/models/spud_post.rb +30 -21
- data/app/models/spud_post_categories_post.rb +2 -3
- data/app/models/spud_post_category.rb +9 -2
- data/app/models/spud_post_comment.rb +1 -3
- data/app/models/spud_post_site.rb +0 -1
- data/app/views/admin/news_posts/edit.html.erb +3 -0
- data/app/views/admin/news_posts/index.html.erb +42 -0
- data/app/views/admin/news_posts/new.html.erb +3 -0
- data/app/views/{spud/admin → admin}/post_categories/_category.html.erb +2 -2
- data/app/views/{spud/admin → admin}/post_categories/_form.html.erb +1 -1
- data/app/views/{spud/admin → admin}/post_categories/index.html.erb +1 -1
- data/app/views/admin/post_categories/new.html.erb +1 -0
- data/app/views/{spud/admin → admin}/post_comments/index.html.erb +3 -3
- data/app/views/{spud/admin → admin}/posts/_category.html.erb +1 -1
- data/app/views/{spud/admin → admin}/posts/_form.html.erb +3 -3
- data/app/views/admin/posts/edit.html.erb +3 -0
- data/app/views/admin/posts/index.html.erb +48 -0
- data/app/views/admin/posts/new.html.erb +3 -0
- data/app/views/blog/_comment.html.erb +6 -4
- data/app/views/blog/_comment_form.html.erb +0 -2
- data/app/views/blog/index.html.erb +30 -28
- data/app/views/blog/show.html.erb +35 -31
- data/app/views/news/index.html.erb +26 -24
- data/app/views/news/show.html.erb +25 -21
- data/config/routes.rb +14 -15
- data/lib/spud_blog/configuration.rb +1 -2
- data/lib/spud_blog/engine.rb +13 -10
- data/lib/spud_blog/version.rb +1 -1
- data/lib/tb_blog.rb +1 -1
- data/spec/controllers/admin/posts_controller_spec.rb +5 -0
- data/spec/dummy/config/application.rb +5 -2
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/environments/test.rb +5 -6
- data/spec/dummy/config/initializers/secret_token.rb +1 -0
- data/spec/dummy/db/migrate/20140110180411_create_spud_roles.tb_core.rb +11 -0
- data/spec/dummy/db/migrate/20140110180412_create_spud_permissions.tb_core.rb +11 -0
- data/spec/dummy/db/migrate/20140110180413_create_spud_role_permissions.tb_core.rb +12 -0
- data/spec/dummy/db/migrate/20140110180414_drop_spud_admin_permissions.tb_core.rb +16 -0
- data/spec/dummy/db/migrate/20140110180415_create_spud_permalinks.tb_permalinks.rb +12 -0
- data/spec/dummy/db/migrate/20140110180416_add_site_id_to_spud_permalinks.tb_permalinks.rb +7 -0
- data/spec/dummy/db/migrate/20140110180417_modify_site_id_for_spud_permalinks.tb_permalinks.rb +12 -0
- data/spec/dummy/db/migrate/20140110180418_create_spud_posts.tb_blog.rb +16 -0
- data/spec/dummy/db/migrate/20140110180419_create_spud_post_categories.tb_blog.rb +14 -0
- data/spec/dummy/db/migrate/20140110180420_create_spud_post_comments.tb_blog.rb +14 -0
- data/spec/dummy/db/migrate/20140110180421_add_url_to_spud_posts.tb_blog.rb +7 -0
- data/spec/dummy/db/migrate/20140110180422_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 +7 -0
- data/spec/dummy/db/migrate/20140110180424_add_meta_to_posts.tb_blog.rb +7 -0
- data/spec/dummy/db/migrate/20140110180425_add_comments_counter_to_spud_posts.tb_blog.rb +13 -0
- data/spec/dummy/db/migrate/20140110180426_create_spud_post_sites.tb_blog.rb +12 -0
- data/spec/dummy/db/migrate/20140110180427_add_spam_fields_to_spud_post_comments.tb_blog.rb +9 -0
- data/spec/dummy/db/migrate/20140110180428_add_permalink_to_spud_post_comments.tb_blog.rb +6 -0
- data/spec/dummy/db/migrate/20140110180429_add_nested_set_to_post_categories.tb_blog.rb +22 -0
- data/spec/dummy/db/migrate/20140110180430_add_content_format_to_spud_posts.tb_blog.rb +6 -0
- data/spec/dummy/db/migrate/20140110180431_add_content_processed_to_spud_post.tb_blog.rb +6 -0
- data/spec/dummy/db/migrate/20140113162805_create_tb_liquid_spud_liquid_tags.tb_liquid.rb +13 -0
- data/spec/dummy/db/schema.rb +100 -59
- metadata +123 -104
- data/app/assets/javascripts/spud/blog/sitemaps.js +0 -2
- data/app/assets/javascripts/spud/blog.js +0 -41
- data/app/assets/stylesheets/news.css +0 -4
- data/app/assets/stylesheets/spud/blog/sitemaps.css +0 -4
- data/app/assets/stylesheets/spud/blog/validity.css +0 -3
- data/app/controllers/spud/blog/sitemaps_controller.rb +0 -9
- data/app/helpers/spud/admin/news_posts_helper.rb +0 -2
- data/app/helpers/spud/admin/post_categories_helper.rb +0 -2
- data/app/helpers/spud/admin/post_comments_helper.rb +0 -3
- data/app/helpers/spud/blog/sitemaps_helper.rb +0 -2
- data/app/models/spud_post_category_sweeper.rb +0 -41
- data/app/models/spud_post_comment_sweeper.rb +0 -33
- data/app/models/spud_post_sweeper.rb +0 -47
- data/app/views/spud/admin/news_posts/edit.html.erb +0 -3
- data/app/views/spud/admin/news_posts/index.html.erb +0 -44
- data/app/views/spud/admin/news_posts/new.html.erb +0 -3
- data/app/views/spud/admin/post_categories/new.html.erb +0 -1
- data/app/views/spud/admin/posts/edit.html.erb +0 -3
- data/app/views/spud/admin/posts/index.html.erb +0 -49
- data/app/views/spud/admin/posts/new.html.erb +0 -3
- data/spec/controllers/spud/admin/posts_controller_spec.rb +0 -5
- data/spec/dummy/log/development.log +0 -263
- data/spec/dummy/log/test.log +0 -3339
- /data/app/assets/javascripts/{spud/admin → admin/blog}/post_comments.js +0 -0
- /data/app/assets/stylesheets/{spud/admin/posts.css.scss → admin/blog/application.css.scss} +0 -0
- /data/app/views/{spud/admin → admin}/post_categories/edit.html.erb +0 -0
- /data/app/views/{spud/blog → blog}/sitemaps/show.xml.builder +0 -0
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MGU5ZjJhZWU3NWJkNjNlMzU0YmJiYzQ0MDEyNDkyODc5NjdkMzQ2ODg3MzI1
|
10
|
-
YTI0YzU3ZDk2OTJmMjMxMjdiNTA4ZGZlYzVkOTBiOWQyYWI0OGFlNGZmYjAz
|
11
|
-
MTBmOWI3NGZhOTE3ODRkMzIzZmVhZDAwOTdiZDIyZGEzNmQ4YjA=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YWQzYmI5MmI2MzJiNzEwYmM4NTM4YzNmZjA0NDQ2OTAwM2Y2MDFmNTVmYTcz
|
14
|
-
YzhhM2EzNDZkZTU3NTllNmUwZGY1ZTMzYWEzOTcyYzllYmNlMGE4Nzg2NTc3
|
15
|
-
ODJhMzgxYmUzOWUzNDczOTgzOWIwMzYyY2JlMDhlMjJlYTMxMGE=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0abb0b9fcb8a6000c80e57993fc82eec445d1621
|
4
|
+
data.tar.gz: adf69ebae439dcdac7a9b487c857814465dd9fa5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5ce39a72962d7796bfb9e0c880abfe6bc6ca318f6e7edeed3f1da5740212d0a6693bc011a3b3e02e9b5f5f60fb356ba243db4f0b6c95ada6121ae3f10af7762b
|
7
|
+
data.tar.gz: 698bc9ebf8b2c7e878e7213f0814df54e8bda5f6f785793039314ccacfd11ac62301d4b70043fe41e3ca12e5a8335b2489a820fe5e26163592112a07b7e153d2
|
data/Readme.markdown
CHANGED
@@ -13,8 +13,8 @@ __NOTE:__ This project is still in its early infancy.
|
|
13
13
|
|
14
14
|
1. In your Gemfile add the following
|
15
15
|
|
16
|
-
gem '
|
17
|
-
gem '
|
16
|
+
gem 'tb_core'
|
17
|
+
gem 'tb_blog'
|
18
18
|
|
19
19
|
2. Run bundle install
|
20
20
|
3. Copy in database migrations to your new rails project
|
@@ -38,6 +38,7 @@ Spud Blog current accepts the following configuration options.
|
|
38
38
|
config.has_custom_fields = true
|
39
39
|
config.caching_enabled = true
|
40
40
|
config.caching_expires_in = 1.hour
|
41
|
+
config.default_comment_approval = true
|
41
42
|
end
|
42
43
|
|
43
44
|
## Customizing Views
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require_directory
|
@@ -1,11 +1,9 @@
|
|
1
|
-
class
|
1
|
+
class Admin::NewsPostsController < Admin::ApplicationController
|
2
2
|
|
3
|
-
layout 'spud/admin/detail'
|
4
3
|
respond_to :html, :xml, :json
|
5
4
|
before_filter :find_post, :only => [:show, :edit, :update, :destroy]
|
6
|
-
add_breadcrumb 'News Posts', :
|
5
|
+
add_breadcrumb 'News Posts', :admin_news_posts_path
|
7
6
|
belongs_to_spud_app :news_posts
|
8
|
-
cache_sweeper :spud_post_sweeper, :only => [:create, :update, :destroy]
|
9
7
|
|
10
8
|
def index
|
11
9
|
@posts = SpudPost.where(:is_news => true).order('published_at desc').includes(:comments).paginate(:page => params[:page], :per_page => 15)
|
@@ -20,10 +18,10 @@ class Spud::Admin::NewsPostsController < Spud::Admin::ApplicationController
|
|
20
18
|
def update
|
21
19
|
@categories = SpudPostCategory.grouped
|
22
20
|
params[:spud_post][:spud_site_ids] ||= []
|
23
|
-
if @post.update_attributes(
|
21
|
+
if @post.update_attributes(post_params)
|
24
22
|
flash[:notice] = 'News Post was successfully updated.'
|
25
23
|
end
|
26
|
-
respond_with @post, :location =>
|
24
|
+
respond_with @post, :location => admin_news_posts_path
|
27
25
|
end
|
28
26
|
|
29
27
|
def new
|
@@ -35,28 +33,32 @@ class Spud::Admin::NewsPostsController < Spud::Admin::ApplicationController
|
|
35
33
|
def create
|
36
34
|
@categories = SpudPostCategory.grouped
|
37
35
|
params[:spud_post][:spud_site_ids] ||= []
|
38
|
-
@post = SpudPost.new(
|
36
|
+
@post = SpudPost.new(post_params)
|
39
37
|
if @post.save
|
40
38
|
flash[:notice] = 'News Post was successfully created.'
|
41
39
|
end
|
42
|
-
respond_with @post, :location =>
|
40
|
+
respond_with @post, :location => admin_news_posts_path
|
43
41
|
end
|
44
42
|
|
45
43
|
def destroy
|
46
44
|
if @post.destroy
|
47
45
|
flash[:notice] = 'News Post was successfully deleted.'
|
48
46
|
end
|
49
|
-
respond_with @post, :location =>
|
47
|
+
respond_with @post, :location => admin_news_posts_path
|
50
48
|
end
|
51
49
|
|
52
|
-
|
50
|
+
private
|
53
51
|
|
54
52
|
def find_post
|
55
53
|
@post = SpudPost.find(params[:id])
|
56
54
|
if @post.blank?
|
57
55
|
flash[:error] = 'News Post not found!'
|
58
|
-
redirect_to
|
56
|
+
redirect_to admin_news_posts_path and return false
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
60
|
+
def post_params
|
61
|
+
params.require(:spud_post).permit(:published_at, :title, :content, :spud_user_id, :url_name, :visible, :comments_enabled, :meta_keywords, :meta_description, :content_format, :category_ids => [], :spud_site_ids => [])
|
62
|
+
end
|
63
|
+
|
62
64
|
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
class
|
1
|
+
class Admin::PostCategoriesController < Admin::ApplicationController
|
2
2
|
|
3
3
|
layout false
|
4
4
|
respond_to :html, :json
|
5
5
|
|
6
6
|
before_filter :find_category, :only => [:show, :edit, :update, :destroy]
|
7
|
-
cache_sweeper :spud_post_category_sweeper, :only => [:create, :update, :destroy]
|
8
7
|
|
9
8
|
def index
|
10
9
|
@post_categories = SpudPostCategory.grouped
|
@@ -16,9 +15,9 @@ class Spud::Admin::PostCategoriesController < Spud::Admin::ApplicationController
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def update
|
19
|
-
if @post_category.update_attributes(
|
18
|
+
if @post_category.update_attributes(category_params)
|
20
19
|
flash[:notice] = 'Post Category was successfully updated'
|
21
|
-
respond_with @post_category, :location =>
|
20
|
+
respond_with @post_category, :location => admin_post_categories_path
|
22
21
|
else
|
23
22
|
render 'new', :status => 422
|
24
23
|
end
|
@@ -30,10 +29,10 @@ class Spud::Admin::PostCategoriesController < Spud::Admin::ApplicationController
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def create
|
33
|
-
@post_category = SpudPostCategory.new(
|
32
|
+
@post_category = SpudPostCategory.new(category_params)
|
34
33
|
if @post_category.save
|
35
34
|
flash[:notice] = 'Post Category was successfully created'
|
36
|
-
respond_with @post_category, :location =>
|
35
|
+
respond_with @post_category, :location => admin_post_categories_path
|
37
36
|
else
|
38
37
|
render 'new', :status => 422
|
39
38
|
end
|
@@ -45,7 +44,7 @@ class Spud::Admin::PostCategoriesController < Spud::Admin::ApplicationController
|
|
45
44
|
@post_categories = SpudPostCategory.grouped
|
46
45
|
render 'index'
|
47
46
|
else
|
48
|
-
respond_with @post_category, :location =>
|
47
|
+
respond_with @post_category, :location => admin_post_categories_path
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
@@ -55,5 +54,8 @@ class Spud::Admin::PostCategoriesController < Spud::Admin::ApplicationController
|
|
55
54
|
@post_category = SpudPostCategory.find(params[:id])
|
56
55
|
end
|
57
56
|
|
57
|
+
def category_params
|
58
|
+
params.require(:spud_post_category).permit(:name, :parent_id)
|
59
|
+
end
|
58
60
|
|
59
61
|
end
|
@@ -1,11 +1,10 @@
|
|
1
|
-
class
|
1
|
+
class Admin::PostCommentsController < Admin::ApplicationController
|
2
2
|
|
3
3
|
respond_to :html, :xml, :json
|
4
|
-
layout 'spud/admin/detail'
|
5
4
|
belongs_to_spud_app :blog_posts
|
6
5
|
before_filter :find_comment, :only => [:show, :edit, :update, :destroy, :approve, :spam]
|
7
|
-
add_breadcrumb 'Blog Posts', :
|
8
|
-
add_breadcrumb 'Comments', :
|
6
|
+
add_breadcrumb 'Blog Posts', :admin_posts_path
|
7
|
+
add_breadcrumb 'Comments', :admin_post_comments_path
|
9
8
|
|
10
9
|
def index
|
11
10
|
@page_name = "Comments"
|
@@ -41,7 +40,7 @@ class Spud::Admin::PostCommentsController < Spud::Admin::ApplicationController
|
|
41
40
|
@post_comment.spam = false
|
42
41
|
@post_comment.approved = true
|
43
42
|
@post_comment.save()
|
44
|
-
redirect_to request.referer ||
|
43
|
+
redirect_to request.referer || admin_post_comments_path
|
45
44
|
end
|
46
45
|
|
47
46
|
def spam
|
@@ -51,14 +50,14 @@ class Spud::Admin::PostCommentsController < Spud::Admin::ApplicationController
|
|
51
50
|
@post_comment.spam = true
|
52
51
|
@post_comment.approved = false
|
53
52
|
@post_comment.save()
|
54
|
-
redirect_to request.referer ||
|
53
|
+
redirect_to request.referer || admin_post_comments_path
|
55
54
|
end
|
56
55
|
|
57
56
|
def destroy
|
58
57
|
if !@post_comment.destroy
|
59
58
|
flash[:error] = "Whoops! Something odd happened while trying to delete that comment. Thats not fun. please try again."
|
60
59
|
end
|
61
|
-
respond_with @post_comment, :location => request.referer ||
|
60
|
+
respond_with @post_comment, :location => request.referer || admin_post_comments_path
|
62
61
|
end
|
63
62
|
|
64
63
|
private
|
@@ -1,11 +1,9 @@
|
|
1
|
-
class
|
1
|
+
class Admin::PostsController < Admin::ApplicationController
|
2
2
|
|
3
|
-
layout 'spud/admin/detail'
|
4
3
|
respond_to :html, :xml, :json
|
5
4
|
before_filter :find_post, :only => [:show, :edit, :update, :destroy]
|
6
|
-
add_breadcrumb 'Blog Posts', :
|
5
|
+
add_breadcrumb 'Blog Posts', :admin_posts_path
|
7
6
|
belongs_to_spud_app :blog_posts
|
8
|
-
cache_sweeper :spud_post_sweeper, :only => [:create, :update, :destroy]
|
9
7
|
|
10
8
|
def index
|
11
9
|
@posts = SpudPost.where(:is_news => false).order('published_at desc').includes(:pending_comments, :author).paginate(:page => params[:page], :per_page => 15)
|
@@ -20,10 +18,11 @@ class Spud::Admin::PostsController < Spud::Admin::ApplicationController
|
|
20
18
|
def update
|
21
19
|
@categories = SpudPostCategory.grouped
|
22
20
|
params[:spud_post][:spud_site_ids] ||= []
|
23
|
-
|
21
|
+
params[:spud_post][:updated_at] = Time.now()
|
22
|
+
if @post.update_attributes(post_params)
|
24
23
|
flash[:notice] = 'Post was successfully updated.'
|
25
24
|
end
|
26
|
-
respond_with @post, :location =>
|
25
|
+
respond_with @post, :location => admin_posts_path
|
27
26
|
end
|
28
27
|
|
29
28
|
def new
|
@@ -35,28 +34,32 @@ class Spud::Admin::PostsController < Spud::Admin::ApplicationController
|
|
35
34
|
def create
|
36
35
|
@categories = SpudPostCategory.grouped
|
37
36
|
params[:spud_post][:spud_site_ids] ||= []
|
38
|
-
@post = SpudPost.new(
|
37
|
+
@post = SpudPost.new(post_params)
|
39
38
|
if @post.save
|
40
39
|
flash[:notice] = 'Post was successfully created.'
|
41
40
|
end
|
42
|
-
respond_with @post, :location =>
|
41
|
+
respond_with @post, :location => admin_posts_path
|
43
42
|
end
|
44
43
|
|
45
44
|
def destroy
|
46
45
|
if @post.destroy
|
47
46
|
flash[:notice] = 'Post was successfully deleted.'
|
48
47
|
end
|
49
|
-
respond_with @post, :location =>
|
48
|
+
respond_with @post, :location => admin_posts_path
|
50
49
|
end
|
51
50
|
|
52
|
-
|
51
|
+
private
|
53
52
|
|
54
53
|
def find_post
|
55
54
|
@post = SpudPost.find(params[:id])
|
56
55
|
if @post.blank?
|
57
56
|
flash[:error] = "Post not found!"
|
58
|
-
redirect_to
|
57
|
+
redirect_to admin_posts_path and return false
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
61
|
+
def post_params
|
62
|
+
params.require(:spud_post).permit(:published_at, :title, :content, :spud_user_id, :url_name, :visible, :comments_enabled, :meta_keywords, :meta_description, :content_format, :category_ids => [], :spud_site_ids => [])
|
63
|
+
end
|
64
|
+
|
62
65
|
end
|
@@ -5,36 +5,8 @@ class BlogController < ApplicationController
|
|
5
5
|
|
6
6
|
before_filter :find_post, :only => [:show, :create_comment]
|
7
7
|
|
8
|
-
caches_action :show, :index,
|
9
|
-
:expires => Spud::Blog.config.action_caching_duration,
|
10
|
-
:if => Proc.new{ |c|
|
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
|
-
}
|
13
|
-
|
14
|
-
after_filter :only => [:show, :index] do |c|
|
15
|
-
if Spud::Blog.cache_mode == :full_page && !(c.params[:page] && c.params[:page].to_i > 1)
|
16
|
-
if (SpudPost.where(:is_news => false).future_posts.count == 0)
|
17
|
-
c.cache_page(nil, nil, false)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
cache_sweeper :spud_post_comment_sweeper, :only => [:create_comment]
|
23
|
-
|
24
8
|
def index
|
25
|
-
|
26
|
-
if params[:page].blank? == false
|
27
|
-
page = params[:page].to_i
|
28
|
-
if page.to_s != params[:page].to_s
|
29
|
-
if(page > 1)
|
30
|
-
redirect_to blog_path(:page => page), :status => :moved_permanently and return
|
31
|
-
else
|
32
|
-
redirect_to blog_path(:page => nil), :status => :moved_permanently and return
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
@posts = SpudPost.public_blog_posts(page, Spud::Blog.config.posts_per_page).includes(:categories, :author)
|
9
|
+
@posts = SpudPost.visible.blog_posts.ordered.paginate(:page => get_page_number, :per_page => Spud::Blog.config.posts_per_page)
|
38
10
|
if Spud::Core.config.multisite_mode_enabled
|
39
11
|
@posts = @posts.for_spud_site(current_site_id)
|
40
12
|
end
|
@@ -69,9 +41,9 @@ class BlogController < ApplicationController
|
|
69
41
|
|
70
42
|
if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name])
|
71
43
|
if Spud::Core.config.multisite_mode_enabled
|
72
|
-
@posts = @post_category.posts_with_children.
|
44
|
+
@posts = @post_category.posts_with_children.visible.blog_posts.for_spud_site(current_site_id).from_archive(params[:archive_date]).paginate(:page => page, :per_page => Spud::Blog.config.posts_per_page)
|
73
45
|
else
|
74
|
-
@posts = @post_category.posts_with_children.
|
46
|
+
@posts = @post_category.posts_with_children.visible.blog_posts.from_archive(params[:archive_date]).paginate(:page => page, :per_page => Spud::Blog.config.posts_per_page)
|
75
47
|
end
|
76
48
|
else
|
77
49
|
redirect_to blog_path
|
@@ -84,9 +56,9 @@ class BlogController < ApplicationController
|
|
84
56
|
|
85
57
|
def archive
|
86
58
|
if Spud::Core.config.multisite_mode_enabled
|
87
|
-
@posts = SpudPost.
|
59
|
+
@posts = SpudPost.visible.blog_posts.from_archive(params[:archive_date]).for_spud_site(current_site_id).paginate(:page => get_page_number, :per_page => Spud::Blog.config.posts_per_page)
|
88
60
|
else
|
89
|
-
@posts = SpudPost.
|
61
|
+
@posts = SpudPost.visible.blog_posts.from_archive(params[:archive_date]).paginate(:page => get_page_number, :per_page => Spud::Blog.config.posts_per_page)
|
90
62
|
end
|
91
63
|
respond_with @posts do |format|
|
92
64
|
format.html { render 'index' }
|
@@ -105,7 +77,7 @@ class BlogController < ApplicationController
|
|
105
77
|
render :nothing => true
|
106
78
|
return
|
107
79
|
end
|
108
|
-
@comment = @post.comments.new(
|
80
|
+
@comment = @post.comments.new(comment_params)
|
109
81
|
@comment.user_agent = request.env["HTTP_USER_AGENT"]
|
110
82
|
@comment.user_ip = request.remote_ip
|
111
83
|
@comment.referrer = request.referrer
|
@@ -136,4 +108,23 @@ class BlogController < ApplicationController
|
|
136
108
|
end
|
137
109
|
end
|
138
110
|
|
111
|
+
def comment_params
|
112
|
+
params.require(:spud_post_comment).permit(:author, :content)
|
113
|
+
end
|
114
|
+
|
115
|
+
def get_page_number
|
116
|
+
page = 1
|
117
|
+
if params[:page].blank? == false
|
118
|
+
page = params[:page].to_i
|
119
|
+
if page.to_s != params[:page].to_s
|
120
|
+
if(page > 1)
|
121
|
+
redirect_to blog_path(:page => page), :status => :moved_permanently and return
|
122
|
+
else
|
123
|
+
redirect_to blog_path(:page => nil), :status => :moved_permanently and return
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
return page
|
128
|
+
end
|
129
|
+
|
139
130
|
end
|
@@ -3,24 +3,8 @@ class NewsController < ApplicationController
|
|
3
3
|
respond_to :html, :xml, :json, :rss
|
4
4
|
layout Spud::Blog.news_layout
|
5
5
|
|
6
|
-
caches_action :show, :index,
|
7
|
-
:expires => Spud::Blog.config.action_caching_duration,
|
8
|
-
:if => Proc.new{ |c|
|
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
|
-
}
|
11
|
-
|
12
|
-
after_filter :only => [:show, :index] do |c|
|
13
|
-
if Spud::Blog.cache_mode == :full_page && !(c.params[:page] && c.params[:page].to_i > 1)
|
14
|
-
if (SpudPost.where(:is_news => true).future_posts.count == 0)
|
15
|
-
c.cache_page(nil, nil, false)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
cache_sweeper :spud_post_comment_sweeper, :only => [:create_comment]
|
21
|
-
|
22
6
|
def index
|
23
|
-
@posts = SpudPost.
|
7
|
+
@posts = SpudPost.visible.news_posts.ordered.paginate(:page => params[:page], :per_page => Spud::Blog.config.posts_per_page)
|
24
8
|
if Spud::Core.config.multisite_mode_enabled
|
25
9
|
@posts = @posts.for_spud_site(current_site_id)
|
26
10
|
end
|
@@ -43,9 +27,9 @@ class NewsController < ApplicationController
|
|
43
27
|
def category
|
44
28
|
if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name])
|
45
29
|
if Spud::Core.config.multisite_mode_enabled
|
46
|
-
@posts = @post_category.posts_with_children.
|
30
|
+
@posts = @post_category.posts_with_children.visible.news_posts.for_spud_site(current_site_id).from_archive(params[:archive_date]).paginate(:page => params[:page], :per_page => Spud::Blog.config.posts_per_page)
|
47
31
|
else
|
48
|
-
@posts = @post_category.posts_with_children.
|
32
|
+
@posts = @post_category.posts_with_children.visible.news_posts.from_archive(params[:archive_date]).paginate(:page => params[:page], :per_page => Spud::Blog.config.posts_per_page)
|
49
33
|
end
|
50
34
|
else
|
51
35
|
redirect_to news_path
|
@@ -58,9 +42,9 @@ class NewsController < ApplicationController
|
|
58
42
|
|
59
43
|
def archive
|
60
44
|
if Spud::Core.config.multisite_mode_enabled
|
61
|
-
@posts = SpudPost.
|
45
|
+
@posts = SpudPost.visible.news_posts.for_spud_site(current_site_id).from_archive(params[:archive_date]).paginate(:page => params[:page], :per_page => Spud::Blog.config.posts_per_page)
|
62
46
|
else
|
63
|
-
@posts = SpudPost.
|
47
|
+
@posts = SpudPost.visible.news_posts.from_archive(params[:archive_date]).paginate(:page => params[:page], :per_page => Spud::Blog.config.posts_per_page)
|
64
48
|
end
|
65
49
|
respond_with @posts do |format|
|
66
50
|
format.html { render 'index' }
|
data/app/helpers/blog_helper.rb
CHANGED
@@ -8,7 +8,6 @@ module BlogHelper
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def spud_post_archive_select
|
11
|
-
dates = SpudPost.months_with_public_posts
|
12
11
|
return select_tag 'archive_date', options_for_select(SpudPost.months_with_public_posts.collect{ |d|
|
13
12
|
[d.strftime('%B %Y'), d.strftime('%Y-%b').downcase]
|
14
13
|
}, params[:archive_date]), :include_blank => true, :rel => 'archive'
|
data/app/models/spud_post.rb
CHANGED
@@ -1,28 +1,34 @@
|
|
1
1
|
class SpudPost < ActiveRecord::Base
|
2
2
|
spud_searchable
|
3
3
|
|
4
|
-
|
4
|
+
has_many :spud_post_categories_posts
|
5
|
+
has_many :categories,
|
5
6
|
:class_name => 'SpudPostCategory',
|
6
|
-
:
|
7
|
-
:
|
7
|
+
:through => :spud_post_categories_posts,
|
8
|
+
:source => :spud_post_category
|
9
|
+
|
8
10
|
belongs_to :author, :class_name => 'SpudUser', :foreign_key => 'spud_user_id'
|
9
11
|
has_many :comments, :class_name => 'SpudPostComment', :inverse_of => :post
|
10
|
-
has_many :pending_comments,
|
11
|
-
has_many :visible_comments,
|
12
|
-
has_many :spam_comments, :
|
12
|
+
has_many :pending_comments, ->{ where(:spam => [nil, false], :approved => false) }, :class_name => "SpudPostComment"
|
13
|
+
has_many :visible_comments, ->{ where(:spam => [nil,false], :approved => true) }, :class_name => 'SpudPostComment'
|
14
|
+
has_many :spam_comments, ->{ where(:spam => true) }, :class_name => "SpudPostComment"
|
13
15
|
has_many :spud_permalinks,:as => :attachment
|
14
16
|
has_many :spud_post_sites, :dependent => :destroy
|
15
17
|
|
16
|
-
scope :publicly, where('visible = true AND published_at <= ?', Time.now.utc).order('published_at desc')
|
17
|
-
scope :future_posts, where('visible = true AND published_at > ?', Time.now.utc)
|
18
|
+
scope :publicly, ->{ where('visible = true AND published_at <= ?', Time.now.utc).order('published_at desc') }
|
19
|
+
scope :future_posts, ->{ where('visible = true AND published_at > ?', Time.now.utc) }
|
20
|
+
|
21
|
+
scope :blog_posts, ->{ where(:is_news => false) }
|
22
|
+
scope :news_posts, ->{ where(:is_news => true) }
|
23
|
+
scope :visible, ->{ where('visible = true AND published_at <= ?', Time.now.utc) }
|
24
|
+
scope :ordered, ->{ order('published_at desc') }
|
25
|
+
|
18
26
|
validates_presence_of :title, :content, :published_at, :spud_user_id, :url_name
|
19
27
|
validates_uniqueness_of :url_name
|
20
28
|
before_validation :set_url_name
|
21
|
-
before_save :postprocess_content
|
22
|
-
|
23
29
|
after_save :set_spud_site_ids
|
30
|
+
acts_as_spud_liquid_content
|
24
31
|
|
25
|
-
attr_accessible :is_news,:published_at,:title,:content,:spud_user_id,:url_name,:visible,:comments_enabled,:meta_keywords,:meta_description,:category_ids, :spud_site_ids, :content_format
|
26
32
|
attr_accessor :spud_site_ids
|
27
33
|
|
28
34
|
def self.for_spud_site(spud_site_id)
|
@@ -30,14 +36,17 @@ class SpudPost < ActiveRecord::Base
|
|
30
36
|
end
|
31
37
|
|
32
38
|
def self.public_posts(page, per_page)
|
39
|
+
ActiveSupport::Deprecation.warn "SpudPost.public_posts is deprecated. Please the :visible, and :ordered scopes instead.", caller
|
33
40
|
return where('visible = ? AND published_at <= ?', true,Time.now.utc).order('published_at desc').paginate(:page => page, :per_page => per_page)
|
34
41
|
end
|
35
42
|
|
36
43
|
def self.public_blog_posts(page, per_page)
|
44
|
+
ActiveSupport::Deprecation.warn "SpudPost.public_blog_posts is deprecated. Please the :blog_posts, :visible, and :ordered scopes instead.", caller
|
37
45
|
return self.public_posts(page, per_page).where(:is_news => false)
|
38
46
|
end
|
39
47
|
|
40
48
|
def self.public_news_posts(page, per_page)
|
49
|
+
ActiveSupport::Deprecation.warn "SpudPost.public_news_posts is deprecated. Please the :news_posts, :visible, and :ordered scopes instead.", caller
|
41
50
|
return self.public_posts(page, per_page).where(:is_news => true)
|
42
51
|
end
|
43
52
|
|
@@ -46,11 +55,11 @@ class SpudPost < ActiveRecord::Base
|
|
46
55
|
end
|
47
56
|
|
48
57
|
def self.recent_blog_posts(limit=5)
|
49
|
-
return self.recent_posts(limit)
|
58
|
+
return self.blog_posts.recent_posts(limit)
|
50
59
|
end
|
51
60
|
|
52
61
|
def self.recent_news_posts(limit=5)
|
53
|
-
return self.recent_posts(limit)
|
62
|
+
return self.news_posts.recent_posts(limit)
|
54
63
|
end
|
55
64
|
|
56
65
|
def self.from_archive(date_string)
|
@@ -102,16 +111,16 @@ class SpudPost < ActiveRecord::Base
|
|
102
111
|
end
|
103
112
|
|
104
113
|
def postprocess_content
|
105
|
-
if self.content_format == 'Markdown'
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
else
|
114
|
+
# if self.content_format == 'Markdown'
|
115
|
+
# require 'redcarpet'
|
116
|
+
# renderer = Redcarpet::Render::HTML.new
|
117
|
+
# extensions = {fenced_code_blocks: true}
|
118
|
+
# redcarpet = Redcarpet::Markdown.new(renderer, extensions)
|
119
|
+
# self.content_processed = redcarpet.render self.content
|
120
|
+
# else
|
112
121
|
template = Liquid::Template.parse(self.content)
|
113
122
|
self.content_processed = template.render()
|
114
|
-
end
|
123
|
+
# end
|
115
124
|
end
|
116
125
|
|
117
126
|
def content_processed
|
@@ -12,8 +12,8 @@ class SpudPostCategory < ActiveRecord::Base
|
|
12
12
|
before_validation :set_url_name
|
13
13
|
|
14
14
|
before_destroy :update_child_categories
|
15
|
-
|
16
|
-
|
15
|
+
after_update :touch_posts
|
16
|
+
after_destroy :touch_posts
|
17
17
|
|
18
18
|
# tell awesome_nested_set not to destroy descendants
|
19
19
|
def skip_before_destroy
|
@@ -67,4 +67,11 @@ class SpudPostCategory < ActiveRecord::Base
|
|
67
67
|
self.children.update_all(:parent_id => self.parent_id)
|
68
68
|
self.class.rebuild!
|
69
69
|
end
|
70
|
+
|
71
|
+
def touch_posts
|
72
|
+
if self.name_changed?
|
73
|
+
self.posts.update_all(:updated_at => Time.now)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
70
77
|
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
class SpudPostComment < ActiveRecord::Base
|
2
2
|
|
3
|
-
attr_accessible :author, :content, :spud_post_id, :referrer, :spam, :user_agent, :user_ip, :permalink
|
4
|
-
|
5
3
|
if Spud::Blog.enable_rakismet
|
6
4
|
include Rakismet::Model
|
7
5
|
before_save :rakismet_check_for_spam
|
8
6
|
end
|
9
7
|
|
10
8
|
validates_presence_of :author, :content
|
11
|
-
belongs_to :post, :class_name => 'SpudPost', :foreign_key => 'spud_post_id', :counter_cache => :comments_count, :inverse_of => :comments
|
9
|
+
belongs_to :post, :class_name => 'SpudPost', :foreign_key => 'spud_post_id', :counter_cache => :comments_count, :inverse_of => :comments, :touch => true
|
12
10
|
|
13
11
|
def visible?
|
14
12
|
return approved && !spam
|