tb_blog 1.1.3 → 1.2.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.
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
@@ -1,69 +0,0 @@
1
- class Admin::NewsPostsController < Admin::ApplicationController
2
-
3
- respond_to :html, :xml, :json
4
- before_filter :find_post, :only => [:show, :edit, :update, :destroy]
5
- add_breadcrumb 'News Posts', :admin_news_posts_path
6
- belongs_to_spud_app :news_posts
7
-
8
- def index
9
- @posts = SpudPost.where(:is_news => true).order('published_at desc').includes(:author).paginate(:page => params[:page], :per_page => 15)
10
- respond_with @posts
11
- end
12
-
13
- def edit
14
- @categories = SpudPostCategory.ordered
15
- respond_with @post
16
- end
17
-
18
- def update
19
- @categories = SpudPostCategory.ordered
20
- params[:spud_post][:spud_site_ids] ||= []
21
- if @post.update_attributes(post_params)
22
- flash[:notice] = 'News Post was successfully updated.'
23
- end
24
- respond_with @post, :location => admin_news_posts_path
25
- end
26
-
27
- def new
28
- @categories = SpudPostCategory.ordered
29
- @post = SpudPost.new(:published_at => Time.zone.now, :spud_user_id => current_user.id, :is_news => true, :comments_enabled => false, :spud_site_ids => [current_site_id])
30
- respond_with @post
31
- end
32
-
33
- def create
34
- @categories = SpudPostCategory.ordered
35
- params[:spud_post][:spud_site_ids] ||= []
36
- @post = SpudPost.new(post_params)
37
- @post.is_news = true
38
- if @post.save
39
- flash[:notice] = 'News Post was successfully created.'
40
- end
41
- respond_with @post, :location => admin_news_posts_path
42
- end
43
-
44
- def destroy
45
- if @post.destroy
46
- flash[:notice] = 'News Post was successfully deleted.'
47
- end
48
- respond_with @post, :location => admin_news_posts_path
49
- end
50
-
51
- private
52
-
53
- def find_post
54
- @post = SpudPost.find(params[:id])
55
- if @post.blank?
56
- flash[:error] = 'News Post not found!'
57
- redirect_to admin_news_posts_path and return false
58
- end
59
- end
60
-
61
- 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 => []]
63
- if Spud::Blog.permitted_attributes.present?
64
- permitted = permitted + Spud::Blog.permitted_attributes
65
- end
66
- params.require(:spud_post).permit(permitted)
67
- end
68
-
69
- end
@@ -1,10 +0,0 @@
1
- class Blog::SitemapsController < Spud::ApplicationController
2
-
3
- respond_to :xml
4
-
5
- def show
6
- @posts = SpudPost.visible.ordered.all
7
- respond_with @pages
8
- end
9
-
10
- end
@@ -1,129 +0,0 @@
1
- class BlogController < ApplicationController
2
-
3
- respond_to :html, :xml, :json, :rss
4
- layout Spud::Blog.base_layout
5
-
6
- before_filter :find_post, :only => [:show, :create_comment]
7
-
8
- def index
9
- @posts = SpudPost.for_user(current_user).visible.blog_posts.ordered.paginate(:page => get_page_number, :per_page => Spud::Blog.config.posts_per_page)
10
- if Spud::Core.config.multisite_mode_enabled
11
- @posts = @posts.for_spud_site(current_site_id)
12
- end
13
- respond_with @posts
14
- end
15
-
16
- # The sole purpose of this action is to redirect from a POST to an seo-friendly url
17
- def filter
18
- if !params[:category_url_name].blank? && !params[:archive_date].blank?
19
- redirect_to blog_category_archive_path(params[:category_url_name], params[:archive_date])
20
- elsif !params[:category_url_name].blank?
21
- redirect_to blog_category_path(params[:category_url_name])
22
- elsif !params[:archive_date].blank?
23
- redirect_to blog_archive_path(params[:archive_date])
24
- else
25
- redirect_to blog_path
26
- end
27
- end
28
-
29
- def category
30
- page = 1
31
- if params[:page].blank? == false
32
- page = params[:page].to_i
33
- if page.to_s != params[:page].to_s
34
- if(page > 1)
35
- redirect_to blog_category_path(:page => page),:status => :moved_permanently and return
36
- else
37
- redirect_to blog_category_path(:page => nil),:status => :moved_permanently and return
38
- end
39
- end
40
- end
41
-
42
- if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name])
43
- if Spud::Core.config.multisite_mode_enabled
44
- @posts = @post_category.posts.for_user(current_user).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)
45
- else
46
- @posts = @post_category.posts.for_user(current_user).visible.blog_posts.from_archive(params[:archive_date]).paginate(:page => page, :per_page => Spud::Blog.config.posts_per_page)
47
- end
48
- else
49
- redirect_to blog_path
50
- return
51
- end
52
- respond_with @posts do |format|
53
- format.html { render 'index' }
54
- end
55
- end
56
-
57
- def archive
58
- if Spud::Core.config.multisite_mode_enabled
59
- @posts = SpudPost.for_user(current_user).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)
60
- else
61
- @posts = SpudPost.for_user(current_user).visible.blog_posts.from_archive(params[:archive_date]).paginate(:page => get_page_number, :per_page => Spud::Blog.config.posts_per_page)
62
- end
63
- respond_with @posts do |format|
64
- format.html { render 'index' }
65
- end
66
- end
67
-
68
- def show
69
- if @post.comments_enabled
70
- @comment = SpudPostComment.new()
71
- end
72
- respond_with @post
73
- end
74
-
75
- def create_comment
76
- unless params[:comment_validation].blank? # trap spam bots
77
- render :nothing => true
78
- return
79
- end
80
- @comment = @post.comments.new(comment_params)
81
- @comment.user_agent = request.env["HTTP_USER_AGENT"]
82
- @comment.user_ip = request.remote_ip
83
- @comment.referrer = request.referrer
84
- @comment.approved = Spud::Blog.default_comment_approval
85
- @comment.permalink = blog_post_url(@post.url_name)
86
- if @comment.save
87
- if @comment.approved?
88
- flash[:notice] = 'Your comment has been posted.'
89
- else
90
- flash[:notice] = 'Your comment has been saved and will appear after being reviewed by an administrator.'
91
- end
92
- @comment = SpudPostComment.new()
93
- end
94
- respond_with @comment do |format|
95
- format.html {
96
- render 'show'
97
- }
98
- end
99
- end
100
-
101
- private
102
-
103
- def find_post
104
- @post = SpudPost.for_user(current_user).where(:url_name => params[:id]).first
105
- if @post.blank? || @post.is_private? || (Spud::Core.config.multisite_mode_enabled && !@post.spud_site_ids.include?(current_site_id))
106
- raise Spud::NotFoundError.new(:item => 'post')
107
- end
108
- end
109
-
110
- def comment_params
111
- params.require(:spud_post_comment).permit(:author, :content)
112
- end
113
-
114
- def get_page_number
115
- page = 1
116
- if params[:page].blank? == false
117
- page = params[:page].to_i
118
- if page.to_s != params[:page].to_s
119
- if(page > 1)
120
- redirect_to blog_path(:page => page), :status => :moved_permanently and return
121
- else
122
- redirect_to blog_path(:page => nil), :status => :moved_permanently and return
123
- end
124
- end
125
- end
126
- return page
127
- end
128
-
129
- end
@@ -1,69 +0,0 @@
1
- class NewsController < ApplicationController
2
-
3
- respond_to :html, :xml, :json, :rss
4
- layout Spud::Blog.news_layout
5
-
6
- before_filter :find_post, :only => [:show]
7
-
8
- def index
9
- @posts = SpudPost.for_user(current_user).visible.news_posts.ordered.paginate(:page => params[:page], :per_page => Spud::Blog.config.posts_per_page)
10
- if Spud::Core.config.multisite_mode_enabled
11
- @posts = @posts.for_spud_site(current_site_id)
12
- end
13
- respond_with @posts
14
- end
15
-
16
- # The sole purpose of this action is to redirect from a POST to an seo-friendly url
17
- def filter
18
- if !params[:category_url_name].blank? && !params[:archive_date].blank?
19
- redirect_to news_category_archive_path(params[:category_url_name], params[:archive_date])
20
- elsif !params[:category_url_name].blank?
21
- redirect_to news_category_path(params[:category_url_name])
22
- elsif !params[:archive_date].blank?
23
- redirect_to news_archive_path(params[:archive_date])
24
- else
25
- redirect_to news_path
26
- end
27
- end
28
-
29
- def category
30
- if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name])
31
- if Spud::Core.config.multisite_mode_enabled
32
- @posts = @post_category.posts.for_user(current_user).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)
33
- else
34
- @posts = @post_category.posts.for_user(current_user).visible.news_posts.from_archive(params[:archive_date]).paginate(:page => params[:page], :per_page => Spud::Blog.config.posts_per_page)
35
- end
36
- else
37
- redirect_to news_path
38
- return
39
- end
40
- respond_with @posts do |format|
41
- format.html { render 'index' }
42
- end
43
- end
44
-
45
- def archive
46
- if Spud::Core.config.multisite_mode_enabled
47
- @posts = SpudPost.for_user(current_user).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)
48
- else
49
- @posts = SpudPost.for_user(current_user).visible.news_posts.from_archive(params[:archive_date]).paginate(:page => params[:page], :per_page => Spud::Blog.config.posts_per_page)
50
- end
51
- respond_with @posts do |format|
52
- format.html { render 'index' }
53
- end
54
- end
55
-
56
- def show
57
- respond_with @post
58
- end
59
-
60
- private
61
-
62
- def find_post
63
- @post = SpudPost.for_user(current_user).where(:url_name => params[:id]).first
64
- if @post.blank? || @post.is_private? || (Spud::Core.config.multisite_mode_enabled && !@post.spud_site_ids.include?(current_site_id))
65
- raise Spud::NotFoundError.new(:item => 'post')
66
- end
67
- end
68
-
69
- end
@@ -1,3 +0,0 @@
1
- <%= form_for @post, :url => admin_news_post_path(@post), :html => {:class => 'form-horizontal'} do |f| %>
2
- <%= render :partial => '/admin/posts/form', :locals => {:f => f} %>
3
- <% end %>
@@ -1,42 +0,0 @@
1
- <%= content_for :data_controls do %>
2
- <%= link_to "Manage Categories", admin_post_categories_path, :class => 'btn spud_blog_manage_categories', :title => 'Manage Categories' %>
3
- <%= link_to "New Post", new_admin_news_post_path, :class => "btn btn-primary", :title => "New Post" %>
4
- <% end %>
5
-
6
- <%=content_for :detail do %>
7
- <table class="table table-striped">
8
- <thead>
9
- <tr>
10
- <th>Title</th>
11
- <th>Author</th>
12
- <th>Published At</th>
13
- <th>&nbsp;</th>
14
- </tr>
15
- </thead>
16
- <tbody>
17
- <% @posts.each do |post| %>
18
- <tr>
19
- <td>
20
- <%= link_to post.title, news_post_path(post.url_name), :target => :blank %>
21
- <% if !post.visible? %>
22
- <span class="badge">Draft</span>
23
- <% end %>
24
- </td>
25
- <td><%= post.author.full_name %></td>
26
- <td><%= post.published_at.strftime('%m/%d/%Y') %></td>
27
- <td class="text-right">
28
- <%= link_to 'Edit', edit_admin_news_post_path(post), :class => 'btn btn-small' %>
29
- <%= link_to 'Delete', admin_news_post_path(post), :method => :delete, :data => {:confirm => 'Are you sure you want to delete this post?'}, :class => 'btn btn-small btn-danger' %>
30
- </td>
31
- </tr>
32
- <%end%>
33
- </tbody>
34
- </table>
35
- <div class="spud_admin_pagination">
36
- <%= will_paginate @posts %>
37
- </div>
38
-
39
- <script>
40
- $(document).ready(spud.admin.post_categories.index);
41
- </script>
42
- <%end%>
@@ -1,3 +0,0 @@
1
- <%= form_for @post, :url => admin_news_posts_path do |f| %>
2
- <%= render :partial => '/admin/posts/form', :locals => {:f => f} %>
3
- <% end %>
@@ -1,6 +0,0 @@
1
- <% cache(@comment) do %>
2
- <li>
3
- <h6>Posted by: <%= comment.author %></h6>
4
- <p><%= comment.content %></p>
5
- </li>
6
- <% end %>
@@ -1,16 +0,0 @@
1
-
2
- xml.instruct! :xml, :version => '1.0', :encoding => 'UTF-8'
3
-
4
- # create the urlset
5
- xml.urlset :xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9' do
6
- @posts.each do |post|
7
- xml.url do
8
- if post.is_news
9
- xml.loc news_post_url(post.url_name)
10
- else
11
- xml.loc blog_post_url(post.url_name)
12
- end
13
- xml.lastmod post.published_at.xmlschema
14
- end
15
- end
16
- end
@@ -1,37 +0,0 @@
1
- <% @page_title = 'News' %>
2
-
3
- <% content_for :head do %>
4
- <%= spud_news_rss_link %>
5
- <% end %>
6
-
7
- <% cache(cache_key_for_spud_collection(@posts, :cache_params => [:category_url_name, :archive_date, :page], :for_user => true)) do %>
8
- <div id="spud_news_filters">
9
- <%= form_tag news_path, :class => 'spud_blog_filter_form' do %>
10
- <label>Category:</label>
11
- <%= spud_post_category_select %>
12
- <label>Month:</label>
13
- <%= spud_post_archive_select %>
14
- <input type="submit" value="Submit" />
15
- <% end %>
16
- </div>
17
-
18
- <div id="spud_news_posts">
19
- <% if @posts.length > 0 %>
20
- <% @posts.includes(:categories, :author).each do |post| %>
21
- <% cache(post) do %>
22
- <div class="spud_news_post">
23
- <h3><%= link_to post.title, news_post_path(post.url_name) %></h3>
24
- <h4>Posted by <%= post.author.full_name %> on <%= post.display_date %></h4>
25
- <div class="spud_news_post_content">
26
- <%= truncate_html post.content_processed.html_safe, :length => 250 %>
27
- </div>
28
- </div>
29
- <% end %>
30
- <% end %>
31
- <% else %>
32
- <p>No posts were found in this category</p>
33
- <% end %>
34
- </div>
35
- <% end %>
36
-
37
- <%= will_paginate @posts %>
@@ -1,18 +0,0 @@
1
- xml.instruct! :xml, :version => "1.0"
2
- xml.rss :version => "2.0" do
3
- xml.channel do
4
- xml.title "#{Spud::Core.site_name} News"
5
- xml.description "News articles for #{Spud::Core.site_name}"
6
- xml.link news_url(:format => :rss)
7
-
8
- for article in @posts
9
- xml.item do
10
- xml.title article.title
11
- xml.description strip_tags(article.content_processed).truncate(250)
12
- xml.pubDate article.created_at.to_s(:rfc822)
13
- xml.link news_post_url(article.url_name)
14
- xml.guid news_post_url(article.url_name)
15
- end
16
- end
17
- end
18
- end
@@ -1,31 +0,0 @@
1
- <% content_for :title do %>
2
- <%= @post.title %> | <%=current_site_name%>
3
- <% end %>
4
-
5
- <% content_for :head do %>
6
- <% cache([@post, 'head']) do %>
7
- <%= spud_news_rss_link %>
8
- <meta name="description" content="<%= @post.meta_description %>" />
9
- <% if @post.meta_keywords.blank? %>
10
- <meta name="keywords" content="<%= @post.categories.collect{ |c| c.name }.join(',') %>" />
11
- <% else %>
12
- <meta name="keywords" content="<%= @post.meta_keywords %>" />
13
- <% end %>
14
- <% end %>
15
- <% end %>
16
-
17
- <% cache(@post) do %>
18
- <div class="spud_news_post">
19
- <h3><%= @post.title %></h3>
20
- <h4>Posted by <%= @post.author.full_name %> on <%= @post.display_date %></h4>
21
- <% if @post.categories.any? %>
22
- <p id="spud_news_post_categories">
23
- Filed under
24
- <%= raw(@post.categories.collect{ |c| link_to c.name, news_category_path(c.url_name) }.join(', ')) %>
25
- </p>
26
- <% end %>
27
- <div id="spud_news_post_content">
28
- <%= raw @post.content_processed %>
29
- </div>
30
- </div>
31
- <% end %>