tb_blog 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Readme.md +23 -6
  3. data/app/controllers/admin/post_comments_controller.rb +21 -8
  4. data/app/controllers/admin/posts_controller.rb +17 -10
  5. data/app/controllers/concerns/blog_url_helpers.rb +60 -0
  6. data/app/controllers/posts_controller.rb +140 -0
  7. data/app/helpers/blog_helper.rb +6 -11
  8. data/app/models/spud/spud_post_model.rb +12 -38
  9. data/app/models/spud_blog_config.rb +26 -0
  10. data/app/models/spud_post_category.rb +0 -4
  11. data/app/models/spud_post_comment.rb +15 -0
  12. data/app/views/admin/post_comments/index.html.erb +1 -1
  13. data/app/views/admin/posts/_form.html.erb +9 -11
  14. data/app/views/admin/posts/index.html.erb +2 -2
  15. data/app/views/{blog → posts}/_comment_form.html.erb +1 -1
  16. data/app/views/{blog → posts}/index.html.erb +5 -5
  17. data/app/views/{blog → posts}/index.rss.builder +4 -4
  18. data/app/views/{blog → posts}/show.html.erb +9 -2
  19. data/config/routes.rb +30 -64
  20. data/db/migrate/20140808132950_add_blog_key_to_spud_posts.rb +6 -0
  21. data/db/migrate/20140811152252_add_blog_key_to_spud_post_comments.rb +6 -0
  22. data/lib/generators/spud/blog/blog_generator.rb +33 -0
  23. data/lib/generators/spud/blog/views_generator.rb +2 -3
  24. data/lib/spud_blog/configuration.rb +12 -12
  25. data/lib/spud_blog/engine.rb +37 -26
  26. data/lib/spud_blog/version.rb +1 -1
  27. data/lib/tasks/spud_blog_tasks.rake +14 -0
  28. data/spec/controllers/{blog_controller_spec.rb → posts_controller_spec.rb} +6 -6
  29. data/spec/dummy/db/migrate/20140811161502_add_blog_key_to_spud_posts.tb_blog.rb +7 -0
  30. data/spec/dummy/db/migrate/20140811161503_add_blog_key_to_spud_post_comments.tb_blog.rb +7 -0
  31. data/spec/dummy/db/schema.rb +5 -1
  32. data/spec/factories/spud_post_factories.rb +1 -0
  33. metadata +18 -20
  34. data/app/controllers/admin/news_posts_controller.rb +0 -69
  35. data/app/controllers/blog/sitemaps_controller.rb +0 -10
  36. data/app/controllers/blog_controller.rb +0 -129
  37. data/app/controllers/news_controller.rb +0 -69
  38. data/app/views/admin/news_posts/edit.html.erb +0 -3
  39. data/app/views/admin/news_posts/index.html.erb +0 -42
  40. data/app/views/admin/news_posts/new.html.erb +0 -3
  41. data/app/views/blog/_comment.html.erb +0 -6
  42. data/app/views/blog/sitemaps/show.xml.builder +0 -16
  43. data/app/views/news/index.html.erb +0 -37
  44. data/app/views/news/index.rss.builder +0 -18
  45. data/app/views/news/show.html.erb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6985b911d99d89f62668336b020afd530179731b
4
- data.tar.gz: a6670c45aae3e10bc112844326cc78ef64310003
3
+ metadata.gz: 75d08014c6bfae23f36194966d8c44c90b2bf360
4
+ data.tar.gz: 9d671ef8e92119816d1e763c76c075f3f7e8355d
5
5
  SHA512:
6
- metadata.gz: 51fe31feee68e1f6191a5ac9eaa80a6d00454ada4b96089c3c8aee56d5a6550acf17405758ba8234de8c11f14af9735fd5aa4046c3ee6c60661029ee6bedce7e
7
- data.tar.gz: 96ae50f8a8e5393e3c03194e6e4b41302ee2bb3efc3c5509d6159fe447dce89c02646302cf3067658a9271d5bd89e937236e8a7b905a8bed38c8731f0d680e8b
6
+ metadata.gz: 034db71980235a49973be16e66a5041275accebe67aae1217251aca2904462670258902a5ae439ad81c53df5ccef212960ed1e12e980300cb582545bc1c0676f
7
+ data.tar.gz: 474aeaf3a4a457368cfb19092d9d2273df82da6b71d141f2f5dd540cfa22bbb7b74a63b9c91f942b37c47660f214ab81eca7ede8734723c58118d5f910a63530
data/Readme.md CHANGED
@@ -39,11 +39,30 @@ A number of built-in views have been provided to help you get started with the f
39
39
 
40
40
  __NOTE:__ The built-in views are likely to undergo changes as features are added to the blogging engine. If a new version of TB Blog does not play nicely with your customized views, try backing up your views to an alternate location and running the views generator again to see what has changed.
41
41
 
42
- ## Javascript Driver
42
+ ## Custom Blogs
43
43
 
44
- TB Blog includes a small, unobtrusive javascript driver that adds functionality to the built-in views. Including the driver is optional, as all client-side views and controllers are designed to work whether you include it or not.
44
+ TB Blog has the ability to define arbitrary blogs outside of the typical Blog and News feeds. To get a custom blog up and running quickly, simply run the provided generator.
45
45
 
46
- <%= javascript_include_tag 'spud/blog' %>
46
+ rails g spud:blog:blog "Press Releases"
47
+
48
+ The generator will have inserted the following snippet of code into your `application.rb` file:
49
+
50
+ Spud::Blog.config.blogs << {
51
+ :name => 'Press Releases', # Display name for the blog
52
+ :key => 'press-releases', # Used by the controller and database to key each post
53
+ :path => '/about/press-releases', # Front-end url for the blog
54
+ :layout => 'about' # Which erb layout should be used
55
+ }
56
+
57
+ By default, custom blogs will use the standard `index` and `show` views under `app/views/posts`. However, you may choose to customize those views by copying the same files over to `app/views/[BLOG KEY]`. Files in that directory will take precedence over those in the standard directory.
58
+
59
+ ### Upgrading from v1.1.2 or Lower
60
+
61
+ The new blog configuration system required a change to the way we determine blog vs news (vs other) posts. After upgrading your gems and running the migrations, you should run the following rake task to update your data model:
62
+
63
+ rake tb_blog:apply_blog_keys
64
+
65
+ The `is_news` column is being left on the `SpudPost` model for the time being to facilitate this transation. At some point in a future version will we remove that column entirely. Please make sure to transition your data before the column goes away for good.
47
66
 
48
67
  ## Access Control
49
68
 
@@ -52,9 +71,7 @@ TB Blog offers a mechanism for limitting who can see what posts. Supply a lambda
52
71
  The example below is from an application that allows subscribers to view subscriber-only content.
53
72
 
54
73
  Spud::Blog.query_for_user = ->(user){
55
- if user.present? && user.has_paid_subscription?
56
- {}
57
- else
74
+ if !user.try(:has_paid_subscription?)
58
75
  {:requires_subscription => false}
59
76
  end
60
77
  }
@@ -1,8 +1,9 @@
1
1
  class Admin::PostCommentsController < Admin::ApplicationController
2
+ include BlogUrlHelpers
2
3
 
3
4
  respond_to :html, :xml, :json
4
- belongs_to_spud_app :blog_posts
5
- before_filter :find_comment, :only => [:show, :edit, :update, :destroy, :approve, :spam]
5
+ before_action :load_blog, :only => :index
6
+ before_action :find_comment, :only => [:show, :edit, :update, :destroy, :approve, :spam]
6
7
  add_breadcrumb 'Blog Posts', :admin_posts_path
7
8
  add_breadcrumb 'Comments', :admin_post_comments_path
8
9
 
@@ -11,9 +12,9 @@ class Admin::PostCommentsController < Admin::ApplicationController
11
12
  if params[:post_id]
12
13
  @post_comments = SpudPostComment.where(:spud_post_id => params[:post_id])
13
14
  else
14
- @post_comments = SpudPostComment
15
+ @post_comments = SpudPostComment.for_blog(params[:blog_key])
15
16
  end
16
- @post_comments = @post_comments.order('created_at desc').includes(:post).paginate(:page => params[:page], :per_page => 15)
17
+ @post_comments = @post_comments.ordered.includes(:post).paginate(:page => params[:page], :per_page => 15)
17
18
  respond_with @post_comments
18
19
  end
19
20
 
@@ -40,7 +41,7 @@ class Admin::PostCommentsController < Admin::ApplicationController
40
41
  @post_comment.spam = false
41
42
  @post_comment.approved = true
42
43
  @post_comment.save()
43
- redirect_to request.referer || admin_post_comments_path
44
+ redirect_to request.referer || admin_post_post_comments_path(@post_comment.post)
44
45
  end
45
46
 
46
47
  def spam
@@ -50,20 +51,32 @@ class Admin::PostCommentsController < Admin::ApplicationController
50
51
  @post_comment.spam = true
51
52
  @post_comment.approved = false
52
53
  @post_comment.save()
53
- redirect_to request.referer || admin_post_comments_path
54
+ redirect_to request.referer || admin_post_post_comments_path(@post_comment.post)
54
55
  end
55
56
 
56
57
  def destroy
57
58
  if !@post_comment.destroy
58
59
  flash[:error] = "Whoops! Something odd happened while trying to delete that comment. Thats not fun. please try again."
59
60
  end
60
- respond_with @post_comment, :location => request.referer || admin_post_comments_path
61
+ respond_with @post_comment, :location => request.referer || admin_post_post_comments_path(@post_comment.post)
61
62
  end
62
63
 
63
- private
64
+ private
64
65
 
65
66
  def find_comment
66
67
  @post_comment = SpudPostComment.find(params[:id])
67
68
  end
68
69
 
70
+ def load_blog
71
+ logger.debug 'load_blog'
72
+ key = params[:blog_key]
73
+ config = Spud::Blog.config.blogs.find{ |it| it[:key] == key }
74
+ if key.blank? || config.blank?
75
+ redirect_to admin_root_path
76
+ return false
77
+ else
78
+ self.class.belongs_to_spud_app config[:name].parameterize.underscore.to_sym
79
+ end
80
+ end
81
+
69
82
  end
@@ -1,23 +1,20 @@
1
1
  class Admin::PostsController < Admin::ApplicationController
2
+ include BlogUrlHelpers
2
3
 
3
4
  respond_to :html, :xml, :json
4
- before_filter :find_post, :only => [:show, :edit, :update, :destroy]
5
- add_breadcrumb 'Blog Posts', :admin_posts_path
6
- belongs_to_spud_app :blog_posts
5
+ before_action :load_blog
6
+ before_action :find_post, :only => [:show, :edit, :update, :destroy]
7
7
 
8
8
  def index
9
- @posts = SpudPost.where(:is_news => false).order('published_at desc').includes(:pending_comments, :author).paginate(:page => params[:page], :per_page => 15)
9
+ @posts = SpudPost.for_blog(params[:blog_key]).ordered.includes(:pending_comments, :author).paginate(:page => params[:page], :per_page => 15)
10
10
  respond_with @posts
11
11
  end
12
12
 
13
13
  def edit
14
- @categories = SpudPostCategory.ordered
15
14
  respond_with @post
16
15
  end
17
16
 
18
17
  def update
19
- @categories = SpudPostCategory.ordered
20
- params[:spud_post][:spud_site_ids] ||= []
21
18
  params[:spud_post][:updated_at] = Time.now()
22
19
  if @post.update_attributes(post_params)
23
20
  flash[:notice] = 'Post was successfully updated.'
@@ -27,14 +24,14 @@ class Admin::PostsController < Admin::ApplicationController
27
24
 
28
25
  def new
29
26
  @categories = SpudPostCategory.ordered
30
- @post = SpudPost.new(:published_at => Time.zone.now, :spud_user_id => current_user.id, :spud_site_ids => [session[:admin_site] || 0])
27
+ @post = SpudPost.new(:published_at => Time.zone.now, :spud_user_id => current_user.id)
31
28
  respond_with @post
32
29
  end
33
30
 
34
31
  def create
35
32
  @categories = SpudPostCategory.ordered
36
- params[:spud_post][:spud_site_ids] ||= []
37
33
  @post = SpudPost.new(post_params)
34
+ @post.blog_key = params[:blog_key]
38
35
  if @post.save
39
36
  flash[:notice] = 'Post was successfully created.'
40
37
  end
@@ -59,11 +56,21 @@ private
59
56
  end
60
57
 
61
58
  def post_params
62
- permitted = [:published_at, :title, :content, :spud_user_id, :url_name, :visible, :comments_enabled, :meta_keywords, :meta_description, :content_format, :category_ids => [], :spud_site_ids => []]
59
+ permitted = [:published_at, :title, :content, :spud_user_id, :url_name, :visible, :comments_enabled, :meta_keywords, :meta_description, :content_format, :category_ids => []]
63
60
  if Spud::Blog.permitted_attributes.present?
64
61
  permitted = permitted + Spud::Blog.permitted_attributes
65
62
  end
66
63
  params.require(:spud_post).permit(permitted)
67
64
  end
68
65
 
66
+ def load_blog
67
+ @config = SpudBlogConfig.find(params[:blog_key])
68
+ if @config.blank?
69
+ redirect_to admin_root_path
70
+ return false
71
+ else
72
+ self.class.belongs_to_spud_app "#{@config.name} Posts".parameterize.underscore.to_sym
73
+ add_breadcrumb "#{@config.name} Posts", admin_posts_path(blog_key: @config.key)
74
+ end
75
+ end
69
76
  end
@@ -0,0 +1,60 @@
1
+ module BlogUrlHelpers
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
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, :admin_post_post_comments_path, :admin_post_comments_path
7
+ end
8
+
9
+ def posts_path(opts={})
10
+ url_for opts.merge({:controller => '/posts', :action => 'index', :blog_key => params[:blog_key]})
11
+ end
12
+
13
+ def post_path(url_name, opts={})
14
+ url_for opts.merge({:controller => '/posts', :action => 'show', :id => url_name, :blog_key => params[:blog_key]})
15
+ end
16
+
17
+ def post_category_path(category_url_name, opts={})
18
+ url_for opts.merge({:controller => '/posts', :action => 'category', :category_url_name => category_url_name, :blog_key => params[:blog_key]})
19
+ end
20
+
21
+ def post_archive_path(archive_date, opts={})
22
+ url_for opts.merge({:controller => '/posts', :action => 'archive', :archive_date => archive_date, :blog_key => params[:blog_key]})
23
+ end
24
+
25
+ def post_category_archive_path(category_url_name, archive_date, opts={})
26
+ url_for opts.merge({:controller => '/posts', :action => 'category', :category_url_name => category_url_name, :archive_date => archive_date, :blog_key => params[:blog_key]})
27
+ end
28
+
29
+ #
30
+ # Admin
31
+ #
32
+
33
+ def admin_posts_path(blog_key: nil)
34
+ blog_key ||= params[:blog_key]
35
+ url_for :controller => '/admin/posts', :action => 'index', :blog_key => blog_key
36
+ end
37
+
38
+ def new_admin_post_path(blog_key: nil)
39
+ blog_key ||= params[:blog_key]
40
+ url_for :controller => '/admin/posts', :action => 'new', :blog_key => blog_key
41
+ end
42
+
43
+ def admin_post_path(post)
44
+ url_for :controller => '/admin/posts', :action => 'show', :id => post.id, :blog_key => post.blog_key
45
+ end
46
+
47
+ def edit_admin_post_path(post)
48
+ url_for :controller => '/admin/posts', :action => 'edit', :id => post.id, :blog_key => post.blog_key
49
+ end
50
+
51
+ def admin_post_comments_path(blog_key: nil)
52
+ blog_key ||= params[:blog_key]
53
+ url_for :controller => '/admin/post_comments', :action => 'index', :blog_key => blog_key
54
+ end
55
+
56
+ def admin_post_post_comments_path(post)
57
+ url_for :controller => '/admin/post_comments', :action => 'index', :post_id => post.id, :blog_key => post.blog_key
58
+ end
59
+
60
+ end
@@ -0,0 +1,140 @@
1
+ class PostsController < ApplicationController
2
+ include BlogUrlHelpers
3
+
4
+ respond_to :html, :json, :rss
5
+
6
+ before_action :load_blog
7
+ before_action :find_post, :only => [:show, :create_comment]
8
+
9
+ def index
10
+ @posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).ordered.paginate(:page => get_page_number, :per_page => Spud::Blog.config.posts_per_page)
11
+ respond_with @posts do |format|
12
+ format.html{
13
+ render view_for_action('index')
14
+ }
15
+ end
16
+ end
17
+
18
+ # The sole purpose of this action is to redirect from a POST to an seo-friendly url
19
+ def filter
20
+ if !params[:category_url_name].blank? && !params[:archive_date].blank?
21
+ redirect_to post_category_archive_path(params[:category_url_name], params[:archive_date])
22
+ elsif !params[:category_url_name].blank?
23
+ redirect_to post_category_path(params[:category_url_name])
24
+ elsif !params[:archive_date].blank?
25
+ redirect_to post_archive_path(params[:archive_date])
26
+ else
27
+ redirect_to posts_path
28
+ end
29
+ end
30
+
31
+ def category
32
+ page = 1
33
+ if params[:page].blank? == false
34
+ page = params[:page].to_i
35
+ if page.to_s != params[:page].to_s
36
+ if(page > 1)
37
+ redirect_to post_category_path(:page => page),:status => :moved_permanently and return
38
+ else
39
+ redirect_to post_category_path(:page => nil),:status => :moved_permanently and return
40
+ end
41
+ end
42
+ end
43
+ if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name])
44
+ @posts = @post_category.posts.for_user(current_user).visible.for_blog(params[:blog_key]).from_archive(params[:archive_date]).paginate(:page => page, :per_page => Spud::Blog.config.posts_per_page)
45
+ else
46
+ redirect_to posts_path
47
+ return
48
+ end
49
+ respond_with @posts do |format|
50
+ format.html { render view_for_action 'index' }
51
+ end
52
+ end
53
+
54
+ def archive
55
+ @posts = SpudPost.for_user(current_user).visible.for_blog(params[:blog_key]).from_archive(params[:archive_date]).paginate(:page => get_page_number, :per_page => Spud::Blog.config.posts_per_page)
56
+ respond_with @posts do |format|
57
+ format.html { render view_for_action 'index' }
58
+ end
59
+ end
60
+
61
+ def show
62
+ if @post.comments_enabled
63
+ @comment = SpudPostComment.new()
64
+ end
65
+ respond_with @post do |format|
66
+ format.html { render view_for_action 'show' }
67
+ end
68
+ end
69
+
70
+ def create_comment
71
+ unless params[:comment_validation].blank? # trap spam bots
72
+ render :nothing => true
73
+ return
74
+ end
75
+ @comment = @post.comments.new(comment_params)
76
+ @comment.user_agent = request.env["HTTP_USER_AGENT"]
77
+ @comment.user_ip = request.remote_ip
78
+ @comment.referrer = request.referrer
79
+ @comment.approved = Spud::Blog.default_comment_approval
80
+ @comment.permalink = post_path(@post.url_name)
81
+ if @comment.save
82
+ if @comment.approved?
83
+ flash[:notice] = 'Your comment has been posted.'
84
+ else
85
+ flash[:notice] = 'Your comment has been saved and will appear after being reviewed by an administrator.'
86
+ end
87
+ @comment = SpudPostComment.new()
88
+ end
89
+ respond_with @comment do |format|
90
+ format.html { render view_for_action 'show' }
91
+ end
92
+ end
93
+
94
+ private
95
+
96
+ def find_post
97
+ @post = SpudPost.for_user(current_user).for_blog(params[:blog_key]).where(:url_name => params[:id]).first
98
+ if @post.blank? || @post.is_private?
99
+ raise Spud::NotFoundError.new(:item => 'post')
100
+ end
101
+ end
102
+
103
+ def comment_params
104
+ params.require(:spud_post_comment).permit(:author, :content)
105
+ end
106
+
107
+ def get_page_number
108
+ page = 1
109
+ if params[:page].present?
110
+ page = params[:page].to_i
111
+ if page.to_s != params[:page].to_s
112
+ if(page > 1)
113
+ redirect_to posts_path(:page => page), :status => :moved_permanently and return
114
+ else
115
+ redirect_to posts_path(:page => nil), :status => :moved_permanently and return
116
+ end
117
+ end
118
+ end
119
+ return page
120
+ end
121
+
122
+ def load_blog
123
+ @config = SpudBlogConfig.find(params[:blog_key])
124
+ if @config.blank?
125
+ raise Spud::NotFoundError(:item => 'blog')
126
+ return false
127
+ else
128
+ self.class.layout(@config.layout)
129
+ end
130
+ end
131
+
132
+ def view_for_action(action)
133
+ if File.exist?(Rails.root.join("app/views/#{@config.key}/#{action}.html.erb"))
134
+ return "#{@config.key}/#{action}"
135
+ else
136
+ return action
137
+ end
138
+ end
139
+
140
+ end
@@ -1,24 +1,19 @@
1
1
  module BlogHelper
2
2
 
3
3
  def spud_post_category_select
4
- return select_tag 'category_url_name',
5
- options_for_select(SpudPostCategory.options_for_categories(), params[:category_url_name]),
6
- :include_blank => true,
7
- :rel => 'category'
4
+ return select_tag('category_url_name',
5
+ options_from_collection_for_select(SpudPostCategory.ordered, :url_name, :name, params[:category_url_name]),
6
+ {:prompt => 'All Categories'})
8
7
  end
9
8
 
10
9
  def spud_post_archive_select
11
10
  return select_tag 'archive_date', options_for_select(SpudPost.months_with_public_posts.collect{ |d|
12
11
  [d.strftime('%B %Y'), d.strftime('%Y-%b').downcase]
13
- }, params[:archive_date]), :include_blank => true, :rel => 'archive'
12
+ }, params[:archive_date]), :prompt => 'All Dates', :rel => 'archive'
14
13
  end
15
14
 
16
15
  def spud_blog_rss_link
17
- return tag :link, :rel => 'alternate', :type => 'application/rss+xml', :title => "#{Spud::Core.site_name} Blog RSS", :href => blog_url(:format => :rss)
16
+ return tag :link, :rel => 'alternate', :type => 'application/rss+xml', :title => "#{Spud::Core.site_name} Blog RSS", :href => posts_path(:format => :rss)
18
17
  end
19
18
 
20
- def spud_news_rss_link
21
- return tag(:link, :rel => 'alternate', :type => 'application/rss+xml', :title => "#{Spud::Core.site_name} News RSS", :href => news_url(:format => :rss))
22
- end
23
-
24
- end
19
+ end
@@ -14,11 +14,12 @@ class Spud::SpudPostModel < ActiveRecord::Base
14
14
  has_many :pending_comments, ->{ where(:spam => [nil, false], :approved => false) }, :class_name => "SpudPostComment", :foreign_key => 'spud_post_id'
15
15
  has_many :visible_comments, ->{ where(:spam => [nil,false], :approved => true) }, :class_name => 'SpudPostComment', :foreign_key => 'spud_post_id'
16
16
  has_many :spam_comments, ->{ where(:spam => true) }, :class_name => "SpudPostComment", :foreign_key => 'spud_post_id'
17
- has_many :spud_permalinks,:as => :attachment
18
- has_many :spud_post_sites, :dependent => :destroy
17
+ has_many :spud_permalinks, :as => :attachment
18
+ has_many :spud_post_sites, :dependent => :destroy, :foreign_key => 'spud_post_id'
19
19
 
20
- scope :blog_posts, ->{ where(:is_news => false) }
21
- scope :news_posts, ->{ where(:is_news => true) }
20
+ scope :blog_posts, ->{ for_blog('blog') }
21
+ scope :news_posts, ->{ for_blog('news') }
22
+ scope :for_blog, ->(key){ where(:blog_key => key) }
22
23
  scope :visible, ->{ where('visible = true AND published_at <= ?', Time.now.utc) }
23
24
  scope :ordered, ->{ order('published_at desc') }
24
25
 
@@ -43,21 +44,6 @@ class Spud::SpudPostModel < ActiveRecord::Base
43
44
  return joins(:spud_post_sites).where(:spud_post_sites => {:spud_site_id => spud_site_id})
44
45
  end
45
46
 
46
- def self.public_posts(page, per_page)
47
- ActiveSupport::Deprecation.warn "SpudPost.public_posts is deprecated. Please the :visible, and :ordered scopes instead.", caller
48
- return where('visible = ? AND published_at <= ?', true,Time.now.utc).order('published_at desc').paginate(:page => page, :per_page => per_page)
49
- end
50
-
51
- def self.public_blog_posts(page, per_page)
52
- ActiveSupport::Deprecation.warn "SpudPost.public_blog_posts is deprecated. Please the :blog_posts, :visible, and :ordered scopes instead.", caller
53
- return self.public_posts(page, per_page).where(:is_news => false)
54
- end
55
-
56
- def self.public_news_posts(page, per_page)
57
- ActiveSupport::Deprecation.warn "SpudPost.public_news_posts is deprecated. Please the :news_posts, :visible, and :ordered scopes instead.", caller
58
- return self.public_posts(page, per_page).where(:is_news => true)
59
- end
60
-
61
47
  def self.recent_posts(limit=5)
62
48
  return where('visible = ? AND published_at <= ?', true, Time.now.utc).order('published_at desc').limit(limit)
63
49
  end
@@ -75,10 +61,16 @@ class Spud::SpudPostModel < ActiveRecord::Base
75
61
  date = Date.strptime(date_string, "%Y-%b")
76
62
  return where(:published_at => date..date.end_of_month)
77
63
  rescue
78
- return all
64
+ logger.debug 'fallback'
65
+ return where('')
79
66
  end
80
67
  end
81
68
 
69
+ def is_news
70
+ ActiveSupport::Deprecation.warn ":is_news is deprecated. Please rely on the :blog_key column stead.", caller
71
+ return self.read_attribute(:is_news)
72
+ end
73
+
82
74
  #def self.posts_for_category_archive(category, )
83
75
 
84
76
  # Returns an array of Date objects for months with public posts
@@ -100,24 +92,6 @@ class Spud::SpudPostModel < ActiveRecord::Base
100
92
  end
101
93
  end
102
94
 
103
- def self.months_with_public_news_posts
104
- records = SpudPost.select('Extract(Month from published_at) as published_month, Extract(Year from published_at) as published_year').where('visible = ? AND published_at < ? AND is_news = ?', true, DateTime.now, true).group('published_month, published_year').order('published_year desc, published_month desc')
105
- begin
106
- return records.collect{ |r| Date.new(r[:published_year].to_i, r[:published_month].to_i) }
107
- rescue Exception => e
108
- logger.fatal "Exception occurred while fetching post archive dates:\n #{e.to_s}"
109
- end
110
- end
111
-
112
- def self.months_with_public_blog_posts
113
- records = SpudPost.select('Extract(Month from published_at) as published_month, Extract(Year from published_at) as published_year').where('visible = ? AND published_at < ? AND is_news = ?', true, DateTime.now, false).group('published_month, published_year').order('published_year desc, published_month desc')
114
- begin
115
- return records.collect{ |r| Date.new(r[:published_year].to_i, r[:published_month].to_i) }
116
- rescue Exception => e
117
- logger.fatal "Exception occurred while fetching post archive dates:\n #{e.to_s}"
118
- end
119
- end
120
-
121
95
  def postprocess_content
122
96
  # if self.content_format == 'Markdown'
123
97
  # require 'redcarpet'
@@ -0,0 +1,26 @@
1
+ class SpudBlogConfig
2
+
3
+ def self.push(config)
4
+ Spud::Blog.config.blogs.push(new(config))
5
+ end
6
+
7
+ def self.find(key)
8
+ return Spud::Blog.config.blogs.find{ |it| it.key == key }
9
+ end
10
+
11
+ def self.each
12
+ Spud::Blog.config.blogs.each do |config|
13
+ yield(config)
14
+ end
15
+ end
16
+
17
+ attr_accessor :name, :key, :path, :layout
18
+
19
+ def initialize(name:, key:, path:, layout:nil)
20
+ @name = name
21
+ @key = key
22
+ @path = path
23
+ @layout = layout || Spud::Blog.config.base_layout
24
+ end
25
+
26
+ end
@@ -15,10 +15,6 @@ class SpudPostCategory < ActiveRecord::Base
15
15
 
16
16
  scope :ordered, ->{ order('name asc') }
17
17
 
18
- def self.options_for_categories()
19
- return ordered.select(:name, :url_name).collect{ |c| [c.name, c.url_name] }
20
- end
21
-
22
18
  private
23
19
 
24
20
  def set_url_name
@@ -8,6 +8,12 @@ class SpudPostComment < ActiveRecord::Base
8
8
  validates_presence_of :author, :content
9
9
  belongs_to :post, :class_name => 'SpudPost', :foreign_key => 'spud_post_id', :counter_cache => :comments_count, :inverse_of => :comments, :touch => true
10
10
 
11
+ scope :for_blog, ->(key){ where(:blog_key => key) }
12
+ scope :pending_approval, ->{ where(:approved => nil) }
13
+ scope :ordered, ->{ order('created_at desc') }
14
+
15
+ before_save :set_blog_key
16
+
11
17
  def visible?
12
18
  return approved && !spam
13
19
  end
@@ -24,4 +30,13 @@ private
24
30
  return true
25
31
  end
26
32
 
33
+ def set_blog_key
34
+ self.blog_key = self.post.blog_key
35
+ end
36
+
27
37
  end
38
+
39
+ # To update current comments
40
+ # SpudPostComment.all.each do |comment|
41
+ # comment.update_column(:blog_key, comment.post.blog_key)
42
+ # end
@@ -21,7 +21,7 @@
21
21
  <span class="spud-post-comment-details-timestamp"><%= timestamp(comment.created_at) %></span>
22
22
  </p>
23
23
  <p class="spud-post-comment-details-title">
24
- <%= link_to truncate(comment.post.title, {:length => 100}), blog_post_path(comment.post.url_name), :target => :blank %>
24
+ <%= link_to truncate(comment.post.title, {:length => 100}), post_path(comment.post.url_name), :target => :blank %>
25
25
  </p>
26
26
  <p>
27
27
  <span class="spud-post-comment-details-content"><%= comment.content %></span>
@@ -66,17 +66,15 @@
66
66
  </div>
67
67
  </div>
68
68
 
69
- <% unless @post.is_news %>
70
- <div class="spud_post_form_row">
71
- <%= f.label :comments_enabled,"Comments Enabled" %>
72
- <div class="spud_post_form_input_group">
73
- <%= f.radio_button :comments_enabled, true %>
74
- <label class="radio inline" for="spud_post_comments_enabled_true">Yes</label>
75
- <%= f.radio_button :comments_enabled, false %>
76
- <label class="radio inline" for="spud_post_comments_enabled_false">No</label>
77
- </div>
69
+ <div class="spud_post_form_row">
70
+ <%= f.label :comments_enabled,"Comments Enabled" %>
71
+ <div class="spud_post_form_input_group">
72
+ <%= f.radio_button :comments_enabled, true %>
73
+ <label class="radio inline" for="spud_post_comments_enabled_true">Yes</label>
74
+ <%= f.radio_button :comments_enabled, false %>
75
+ <label class="radio inline" for="spud_post_comments_enabled_false">No</label>
78
76
  </div>
79
- <% end %>
77
+ </div>
80
78
 
81
79
  <div class="spud_post_form_row">
82
80
  <%= f.label :meta_keywords, 'Keywords' %>
@@ -96,7 +94,7 @@
96
94
  <%= link_to 'Add Category', new_admin_post_category_path, :class => 'btn btn-mini spud_post_add_category' %>
97
95
  <input type="hidden" name="spud_post[category_ids][]" value="" />
98
96
  <ul class="spud_post_categories_form">
99
- <%= render :partial => '/admin/posts/category', :collection => @categories %>
97
+ <%= render :partial => '/admin/posts/category', :collection => SpudPostCategory.ordered %>
100
98
  </ul>
101
99
  </div>
102
100
 
@@ -19,7 +19,7 @@
19
19
  <% @posts.each do |post| %>
20
20
  <tr>
21
21
  <td>
22
- <%= link_to post.title, blog_post_path(post.url_name), :target => :blank %>
22
+ <%= link_to post.title, post_path(post.url_name), :target => :blank %>
23
23
  <% if !post.visible? %>
24
24
  <span class="badge">Draft</span>
25
25
  <% end %>
@@ -28,7 +28,7 @@
28
28
  <td><%= post.published_at.strftime('%m/%d/%Y') %></td>
29
29
  <td>
30
30
  <%= post.pending_comments.length %>
31
- <%= link_to "Manage", admin_post_post_comments_path(:post_id => post.id), :class => 'spud-post-comments-manage' %>
31
+ <%= link_to "Manage", admin_post_post_comments_path(post), :class => 'spud-post-comments-manage' %>
32
32
  </td>
33
33
  <td class="text-right">
34
34
  <%= link_to 'Edit', edit_admin_post_path(post), :class => 'btn btn-small' %>
@@ -1,4 +1,4 @@
1
- <%= form_for @comment, :url => blog_post_path(@post.url_name, :anchor => 'comment_form') do |f| %>
1
+ <%= form_for @comment, :url => post_path(@post.url_name, :anchor => 'comment_form') do |f| %>
2
2
 
3
3
  <% if @comment.errors.any? %>
4
4
  <div class="comment_error_list">