spud_blog 0.6.3 → 0.7.0
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +40 -0
- data/app/controllers/blog_controller.rb +12 -9
- data/app/controllers/news_controller.rb +11 -3
- data/app/controllers/spud/admin/news_posts_controller.rb +1 -9
- data/app/controllers/spud/admin/post_categories_controller.rb +1 -1
- data/app/controllers/spud/admin/posts_controller.rb +1 -9
- data/app/controllers/spud/blog/sitemaps_controller.rb +2 -1
- data/app/models/spud_post_category_sweeper.rb +41 -0
- data/app/models/spud_post_comment.rb +1 -0
- data/app/models/spud_post_comment_sweeper.rb +33 -0
- data/app/models/spud_post_sweeper.rb +44 -0
- data/db/migrate/20120125180945_create_spud_posts.rb +15 -0
- data/db/migrate/20120125181022_create_spud_post_categories.rb +13 -0
- data/db/migrate/20120125181359_create_spud_post_comments.rb +13 -0
- data/db/migrate/20120127143054_add_url_to_spud_posts.rb +6 -0
- data/db/migrate/20120127144942_add_url_to_spud_post_categories.rb +8 -0
- data/db/migrate/20120210165540_add_is_news_to_spud_posts.rb +6 -0
- data/lib/spud_blog/configuration.rb +10 -3
- data/lib/spud_blog/version.rb +5 -0
- data/lib/tasks/spud_blog_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +56 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +15 -0
- data/test/dummy/config/environment.rb +10 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/db/schema.rb +64 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- metadata +170 -14
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'SpudBlog'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
|
32
|
+
Rake::TestTask.new(:test) do |t|
|
33
|
+
t.libs << 'lib'
|
34
|
+
t.libs << 'test'
|
35
|
+
t.pattern = 'test/**/*_test.rb'
|
36
|
+
t.verbose = false
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
task :default => :spec
|
@@ -1,16 +1,22 @@
|
|
1
1
|
class BlogController < ApplicationController
|
2
2
|
|
3
|
-
|
4
|
-
respond_to :html, :xml, :json,:rss
|
5
|
-
|
3
|
+
respond_to :html, :xml, :json, :rss
|
6
4
|
layout Spud::Blog.base_layout
|
7
5
|
|
8
6
|
caches_action :show, :index,
|
9
|
-
:expires => Spud::Blog.config.
|
7
|
+
:expires => Spud::Blog.config.action_caching_duration,
|
10
8
|
:if => Proc.new{ |c|
|
11
|
-
Spud::Blog.config.
|
9
|
+
Spud::Blog.config.enable_action_caching && !(c.params[:page] && c.params[:page].to_i > 1)
|
12
10
|
}
|
13
11
|
|
12
|
+
after_filter :only => [:show, :index] do |c|
|
13
|
+
if Spud::Blog.enable_full_page_caching && !(c.params[:page] && c.params[:page].to_i > 1)
|
14
|
+
c.cache_page(nil, nil, false)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
cache_sweeper :spud_post_comment_sweeper, :only => [:create_comment]
|
19
|
+
|
14
20
|
def index
|
15
21
|
@posts = SpudPost.public_blog_posts(params[:page], Spud::Blog.config.posts_per_page)
|
16
22
|
respond_with @posts
|
@@ -65,10 +71,7 @@ class BlogController < ApplicationController
|
|
65
71
|
end
|
66
72
|
@comment = @post.comments.new(params[:spud_post_comment])
|
67
73
|
@comment.approved = true
|
68
|
-
if @comment.save
|
69
|
-
flash[:notice] = 'Your comment has been posted, however it will not appear until it is approved.'
|
70
|
-
expire_action blog_post_url(@post.url_name)
|
71
|
-
end
|
74
|
+
flash[:notice] = 'Your comment has been posted, however it will not appear until it is approved.' if @comment.save
|
72
75
|
respond_with @comment do |format|
|
73
76
|
format.html { redirect_to blog_post_path(@post.url_name, :anchor => 'spud_post_comment_form') }
|
74
77
|
end
|
@@ -1,14 +1,22 @@
|
|
1
1
|
class NewsController < ApplicationController
|
2
2
|
|
3
|
-
respond_to :html, :xml, :json
|
3
|
+
respond_to :html, :xml, :json, :rss
|
4
4
|
layout Spud::Blog.news_layout
|
5
5
|
|
6
6
|
caches_action :show, :index,
|
7
|
-
:expires => Spud::Blog.config.
|
7
|
+
:expires => Spud::Blog.config.action_caching_duration,
|
8
8
|
:if => Proc.new{ |c|
|
9
|
-
Spud::Blog.config.
|
9
|
+
Spud::Blog.config.enable_action_caching && !(c.params[:page] && c.params[:page].to_i > 1)
|
10
10
|
}
|
11
11
|
|
12
|
+
after_filter :only => [:show, :index] do |c|
|
13
|
+
if Spud::Blog.enable_full_page_caching && !(c.params[:page] && c.params[:page].to_i > 1)
|
14
|
+
c.cache_page(nil, nil, false)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
cache_sweeper :spud_post_comment_sweeper, :only => [:create_comment]
|
19
|
+
|
12
20
|
def index
|
13
21
|
@posts = SpudPost.public_news_posts(params[:page], Spud::Blog.config.posts_per_page)
|
14
22
|
respond_with @posts
|
@@ -4,8 +4,8 @@ class Spud::Admin::NewsPostsController < Spud::Admin::ApplicationController
|
|
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
|
7
|
-
|
8
7
|
belongs_to_spud_app :news_posts
|
8
|
+
cache_sweeper :spud_post_sweeper, :only => [:create, :update, :destroy]
|
9
9
|
|
10
10
|
def index
|
11
11
|
@posts = SpudPost.where(:is_news => true).order('published_at desc').includes(:comments).paginate(:page => params[:page], :per_page => 15)
|
@@ -21,7 +21,6 @@ class Spud::Admin::NewsPostsController < Spud::Admin::ApplicationController
|
|
21
21
|
@categories = SpudPostCategory.grouped
|
22
22
|
if @post.update_attributes(params[:spud_post])
|
23
23
|
flash[:notice] = 'News Post was successfully updated.'
|
24
|
-
expire_news_actions(@post)
|
25
24
|
end
|
26
25
|
respond_with @post, :location => spud_admin_news_posts_path
|
27
26
|
end
|
@@ -37,7 +36,6 @@ class Spud::Admin::NewsPostsController < Spud::Admin::ApplicationController
|
|
37
36
|
@post = SpudPost.new(params[:spud_post])
|
38
37
|
if @post.save
|
39
38
|
flash[:notice] = 'News Post was successfully created.'
|
40
|
-
expire_news_actions
|
41
39
|
end
|
42
40
|
respond_with @post, :location => spud_admin_news_posts_path
|
43
41
|
end
|
@@ -45,7 +43,6 @@ class Spud::Admin::NewsPostsController < Spud::Admin::ApplicationController
|
|
45
43
|
def destroy
|
46
44
|
if @post.destroy
|
47
45
|
flash[:notice] = 'News Post was successfully deleted.'
|
48
|
-
expire_news_actions
|
49
46
|
end
|
50
47
|
respond_with @post, :location => spud_admin_news_posts_path
|
51
48
|
end
|
@@ -60,9 +57,4 @@ class Spud::Admin::NewsPostsController < Spud::Admin::ApplicationController
|
|
60
57
|
end
|
61
58
|
end
|
62
59
|
|
63
|
-
def expire_news_actions
|
64
|
-
expire_action news_url
|
65
|
-
expire_action news_post_url(@post.url_name) unless @post.nil?
|
66
|
-
end
|
67
|
-
|
68
60
|
end
|
@@ -4,8 +4,8 @@ class Spud::Admin::PostCategoriesController < Spud::Admin::ApplicationController
|
|
4
4
|
respond_to :html, :xml, :json
|
5
5
|
before_filter :find_category, :only => [:show, :edit, :update, :destroy]
|
6
6
|
add_breadcrumb 'Post Categories', :spud_admin_post_categories_path
|
7
|
-
|
8
7
|
belongs_to_spud_app :post_categories
|
8
|
+
cache_sweeper :spud_post_category_sweeper, :only => [:create, :update, :destroy]
|
9
9
|
|
10
10
|
def index
|
11
11
|
@post_categories = SpudPostCategory.order('name asc').includes(:posts).paginate(:page => params[:page], :per_page => 15)
|
@@ -4,8 +4,8 @@ class Spud::Admin::PostsController < Spud::Admin::ApplicationController
|
|
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
|
7
|
-
|
8
7
|
belongs_to_spud_app :blog_posts
|
8
|
+
cache_sweeper :spud_post_sweeper, :only => [:create, :update, :destroy]
|
9
9
|
|
10
10
|
def index
|
11
11
|
@posts = SpudPost.where(:is_news => false).order('published_at desc').includes(:comments, :author).paginate(:page => params[:page], :per_page => 15)
|
@@ -21,7 +21,6 @@ class Spud::Admin::PostsController < Spud::Admin::ApplicationController
|
|
21
21
|
@categories = SpudPostCategory.grouped
|
22
22
|
if @post.update_attributes(params[:spud_post])
|
23
23
|
flash[:notice] = 'Post was successfully updated.'
|
24
|
-
expire_blog_actions
|
25
24
|
end
|
26
25
|
respond_with @post, :location => spud_admin_posts_path
|
27
26
|
end
|
@@ -37,7 +36,6 @@ class Spud::Admin::PostsController < Spud::Admin::ApplicationController
|
|
37
36
|
@post = SpudPost.new(params[:spud_post])
|
38
37
|
if @post.save
|
39
38
|
flash[:notice] = 'Post was successfully created.'
|
40
|
-
expire_blog_actions
|
41
39
|
end
|
42
40
|
respond_with @post, :location => spud_admin_posts_path
|
43
41
|
end
|
@@ -45,7 +43,6 @@ class Spud::Admin::PostsController < Spud::Admin::ApplicationController
|
|
45
43
|
def destroy
|
46
44
|
if @post.destroy
|
47
45
|
flash[:notice] = 'Post was successfully deleted.'
|
48
|
-
expire_blog_actions
|
49
46
|
end
|
50
47
|
respond_with @post, :location => spud_admin_posts_path
|
51
48
|
end
|
@@ -60,9 +57,4 @@ class Spud::Admin::PostsController < Spud::Admin::ApplicationController
|
|
60
57
|
end
|
61
58
|
end
|
62
59
|
|
63
|
-
def expire_blog_actions
|
64
|
-
expire_action blog_url
|
65
|
-
expire_action blog_post_url(@post.url_name) unless @post.nil?
|
66
|
-
end
|
67
|
-
|
68
60
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
class Spud::Blog::SitemapsController < Spud::ApplicationController
|
2
2
|
respond_to :xml
|
3
|
-
caches_action :show, :expires_in => 1.day
|
3
|
+
caches_action :show, :expires_in => 1.day, :if => Proc.new{ |c| Spud::Blog.config.enable_action_caching }
|
4
|
+
caches_page :show, :if => Proc.new{ |c| Spud::Blog.config.enable_full_page_caching }
|
4
5
|
def show
|
5
6
|
@posts = SpudPost.publicly.all
|
6
7
|
respond_with @pages
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class SpudPostCategorySweeper < ActionController::Caching::Sweeper
|
2
|
+
|
3
|
+
observe SpudPostCategory
|
4
|
+
|
5
|
+
def after_save(record)
|
6
|
+
expire_cache_for(record)
|
7
|
+
end
|
8
|
+
|
9
|
+
def after_destroy(record)
|
10
|
+
expire_cache_for(record)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def expire_cache_for(record)
|
16
|
+
if Spud::Blog.config.enable_action_caching
|
17
|
+
SpudPost.find_each do |p|
|
18
|
+
if p.is_news
|
19
|
+
expire_action news_post_url(p.url_name)
|
20
|
+
else
|
21
|
+
expire_action blog_post_url(p.url_name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
expire_action news_url
|
25
|
+
expire_action blog_url
|
26
|
+
expire_action spud_blog_sitemap_url
|
27
|
+
end
|
28
|
+
if Spud::Blog.config.enable_full_page_caching
|
29
|
+
SpudPost.find_each do |p|
|
30
|
+
if p.is_news
|
31
|
+
expire_page news_post_path(p.url_name)
|
32
|
+
else
|
33
|
+
expire_page blog_post_path(p.url_name)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
expire_page news_path
|
37
|
+
expire_page blog_path
|
38
|
+
expire_page spud_blog_sitemap_path(:format => :xml)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class SpudPostCommentSweeper < ActionController::Caching::Sweeper
|
2
|
+
|
3
|
+
observe SpudPostComment
|
4
|
+
|
5
|
+
def after_save(record)
|
6
|
+
expire_cache_for(record)
|
7
|
+
end
|
8
|
+
|
9
|
+
def after_destroy(record)
|
10
|
+
expire_cache_for(record)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def expire_cache_for(record)
|
16
|
+
unless record.post.nil?
|
17
|
+
if Spud::Blog.config.enable_action_caching
|
18
|
+
if record.post.is_news
|
19
|
+
expire_action news_post_url(record.post.url_name)
|
20
|
+
else
|
21
|
+
expire_action blog_post_url(record.post.url_name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
if Spud::Blog.config.enable_full_page_caching
|
25
|
+
if record.post.is_news
|
26
|
+
expire_page news_post_path(record.post.url_name)
|
27
|
+
else
|
28
|
+
expire_page blog_post_path(record.post.url_name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class SpudPostSweeper < ActionController::Caching::Sweeper
|
2
|
+
|
3
|
+
observe SpudPost
|
4
|
+
|
5
|
+
def after_save(record)
|
6
|
+
expire_cache_for(record)
|
7
|
+
end
|
8
|
+
|
9
|
+
def after_destroy(record)
|
10
|
+
expire_cache_for(record)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def expire_cache_for(record)
|
16
|
+
if Spud::Blog.config.enable_action_caching
|
17
|
+
expire_action spud_blog_sitemap_url
|
18
|
+
if record.is_news
|
19
|
+
expire_action blog_url
|
20
|
+
expire_action blog_url(:format => :rss)
|
21
|
+
expire_action blog_post_url(record.url_name)
|
22
|
+
else
|
23
|
+
expire_action news_url
|
24
|
+
expire_action news_url(:format => :rss)
|
25
|
+
expire_action news_post_url(record.url_name)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
if Spud::Blog.config.enable_full_page_caching
|
29
|
+
expire_page spud_blog_sitemap_path(:format => :xml)
|
30
|
+
if record.is_news
|
31
|
+
expire_page news_path
|
32
|
+
expire_page news_path(:format => :rss)
|
33
|
+
expire_page news_post_path(record.url_name)
|
34
|
+
else
|
35
|
+
expire_page blog_path
|
36
|
+
expire_page blog_path(:format => :rss)
|
37
|
+
expire_page blog_post_path(record.url_name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
expire_page spud_sitemap_path(:format => :xml)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateSpudPosts < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :spud_posts do |t|
|
4
|
+
t.integer :spud_user_id
|
5
|
+
t.string :title
|
6
|
+
t.text :content
|
7
|
+
t.boolean :comments_enabled, :default => false
|
8
|
+
t.boolean :visible, :default => true
|
9
|
+
t.datetime :published_at
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
add_index :spud_posts, :spud_user_id
|
13
|
+
add_index :spud_posts, :visible
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateSpudPostCategories < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :spud_post_categories do |t|
|
4
|
+
t.string :name
|
5
|
+
t.timestamps
|
6
|
+
end
|
7
|
+
create_table :spud_post_categories_posts, :id => false do |t|
|
8
|
+
t.integer :spud_post_id
|
9
|
+
t.integer :spud_post_category_id
|
10
|
+
end
|
11
|
+
add_index :spud_post_categories_posts, :spud_post_category_id
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateSpudPostComments < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :spud_post_comments do |t|
|
4
|
+
t.integer :spud_post_id
|
5
|
+
t.string :author
|
6
|
+
t.text :content
|
7
|
+
t.boolean :approved, :default => false
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
add_index :spud_post_comments, :spud_post_id
|
11
|
+
add_index :spud_post_comments, :approved
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class AddUrlToSpudPostCategories < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :spud_post_categories, :parent_id, :integer, :default => 0
|
4
|
+
add_column :spud_post_categories, :url_name, :string
|
5
|
+
add_index :spud_post_categories, :parent_id
|
6
|
+
add_index :spud_post_categories, :url_name
|
7
|
+
end
|
8
|
+
end
|