tb_blog 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +29 -0
  4. data/Readme.markdown +130 -0
  5. data/app/assets/images/spud/admin/news_thumb.png +0 -0
  6. data/app/assets/images/spud/admin/news_thumb@2x.png +0 -0
  7. data/app/assets/images/spud/admin/posts_thumb.png +0 -0
  8. data/app/assets/javascripts/spud/admin/post_categories.js +116 -0
  9. data/app/assets/javascripts/spud/admin/posts.js +71 -0
  10. data/app/assets/javascripts/spud/blog/sitemaps.js +2 -0
  11. data/app/assets/javascripts/spud/blog.js +41 -0
  12. data/app/assets/stylesheets/news.css +4 -0
  13. data/app/assets/stylesheets/spud/admin/posts.css +113 -0
  14. data/app/assets/stylesheets/spud/blog/sitemaps.css +4 -0
  15. data/app/assets/stylesheets/spud/blog/validity.css +3 -0
  16. data/app/controllers/blog_controller.rb +135 -0
  17. data/app/controllers/news_controller.rb +80 -0
  18. data/app/controllers/spud/admin/news_posts_controller.rb +62 -0
  19. data/app/controllers/spud/admin/post_categories_controller.rb +59 -0
  20. data/app/controllers/spud/admin/post_comments_controller.rb +68 -0
  21. data/app/controllers/spud/admin/posts_controller.rb +62 -0
  22. data/app/controllers/spud/blog/sitemaps_controller.rb +9 -0
  23. data/app/helpers/blog_helper.rb +25 -0
  24. data/app/helpers/news_helper.rb +2 -0
  25. data/app/helpers/spud/admin/news_posts_helper.rb +2 -0
  26. data/app/helpers/spud/admin/post_categories_helper.rb +2 -0
  27. data/app/helpers/spud/admin/post_comments_helper.rb +2 -0
  28. data/app/helpers/spud/admin/posts_helper.rb +22 -0
  29. data/app/helpers/spud/blog/sitemaps_helper.rb +2 -0
  30. data/app/models/spud_post.rb +171 -0
  31. data/app/models/spud_post_categories_post.rb +5 -0
  32. data/app/models/spud_post_category.rb +70 -0
  33. data/app/models/spud_post_category_sweeper.rb +41 -0
  34. data/app/models/spud_post_comment.rb +19 -0
  35. data/app/models/spud_post_comment_sweeper.rb +33 -0
  36. data/app/models/spud_post_site.rb +9 -0
  37. data/app/models/spud_post_sweeper.rb +47 -0
  38. data/app/views/blog/_comment.html.erb +4 -0
  39. data/app/views/blog/_comment_form.html.erb +20 -0
  40. data/app/views/blog/index.html.erb +35 -0
  41. data/app/views/blog/index.rss.builder +18 -0
  42. data/app/views/blog/show.html.erb +37 -0
  43. data/app/views/news/index.html.erb +35 -0
  44. data/app/views/news/index.rss.builder +18 -0
  45. data/app/views/news/show.html.erb +27 -0
  46. data/app/views/spud/admin/news_posts/edit.html.erb +3 -0
  47. data/app/views/spud/admin/news_posts/index.html.erb +44 -0
  48. data/app/views/spud/admin/news_posts/new.html.erb +3 -0
  49. data/app/views/spud/admin/post_categories/_category.html.erb +14 -0
  50. data/app/views/spud/admin/post_categories/_form.html.erb +23 -0
  51. data/app/views/spud/admin/post_categories/edit.html.erb +1 -0
  52. data/app/views/spud/admin/post_categories/index.html.erb +9 -0
  53. data/app/views/spud/admin/post_categories/new.html.erb +1 -0
  54. data/app/views/spud/admin/post_comments/index.html.erb +47 -0
  55. data/app/views/spud/admin/posts/_category.html.erb +9 -0
  56. data/app/views/spud/admin/posts/_form.html.erb +117 -0
  57. data/app/views/spud/admin/posts/edit.html.erb +3 -0
  58. data/app/views/spud/admin/posts/index.html.erb +50 -0
  59. data/app/views/spud/admin/posts/new.html.erb +3 -0
  60. data/app/views/spud/blog/sitemaps/show.xml.builder +16 -0
  61. data/config/routes.rb +94 -0
  62. data/db/migrate/20120125180945_create_spud_posts.rb +15 -0
  63. data/db/migrate/20120125181022_create_spud_post_categories.rb +13 -0
  64. data/db/migrate/20120125181359_create_spud_post_comments.rb +13 -0
  65. data/db/migrate/20120127143054_add_url_to_spud_posts.rb +6 -0
  66. data/db/migrate/20120127144942_add_url_to_spud_post_categories.rb +8 -0
  67. data/db/migrate/20120210165540_add_is_news_to_spud_posts.rb +6 -0
  68. data/db/migrate/20120309181917_add_meta_to_posts.rb +6 -0
  69. data/db/migrate/20120413020437_add_comments_counter_to_spud_posts.rb +12 -0
  70. data/db/migrate/20120713150446_create_spud_post_sites.rb +11 -0
  71. data/db/migrate/20120825142547_add_spam_fields_to_spud_post_comments.rb +8 -0
  72. data/db/migrate/20120825144506_add_permalink_to_spud_post_comments.rb +5 -0
  73. data/db/migrate/20121113135812_add_nested_set_to_post_categories.rb +21 -0
  74. data/db/migrate/20130120151857_add_content_format_to_spud_posts.rb +5 -0
  75. data/db/migrate/20130121130612_add_content_processed_to_spud_post.rb +5 -0
  76. data/lib/generators/spud/blog/random_posts_generator.rb +60 -0
  77. data/lib/generators/spud/blog/views_generator.rb +19 -0
  78. data/lib/spud_blog/configuration.rb +25 -0
  79. data/lib/spud_blog/engine.rb +64 -0
  80. data/lib/spud_blog/version.rb +5 -0
  81. data/lib/tasks/spud_blog_tasks.rake +4 -0
  82. data/lib/tb_blog.rb +6 -0
  83. data/test/fixtures/spud_post_sites.yml +9 -0
  84. data/test/unit/spud_post_site_test.rb +7 -0
  85. metadata +338 -0
@@ -0,0 +1,23 @@
1
+ <%= form_for @post_category, :url => (@post_category.new_record? ? spud_admin_post_categories_path : spud_admin_post_category_path(@post_category)), :html => {:class => 'form-horizontal spud_post_category_form'} do |f| %>
2
+
3
+ <%= error_messages_for(f.object) %>
4
+
5
+ <fieldset>
6
+ <div class="control-group">
7
+ <%= f.label :name,"Name",:class => "control-label" %>
8
+ <div class="controls">
9
+ <%= f.text_field :name %>
10
+ </div>
11
+ </div>
12
+ <div class="control-group">
13
+ <%= label_tag :parent,'Parent',:class => "control-label" %>
14
+ <div class="controls">
15
+ <select name="spud_post_category[parent_id]">
16
+ <option value="">No Parent</option>
17
+ <%= options_for_select(SpudPostCategory.options_for_categories(:filter => @post_category.id), @post_category.parent_id) %>
18
+ </select>
19
+ </div>
20
+ </div>
21
+ </fieldset>
22
+
23
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= render :partial => 'form' %>
@@ -0,0 +1,9 @@
1
+ <div class="spud_blog_category_manager">
2
+ <%= link_to "New Post Category", new_spud_admin_post_category_path, :class => "btn btn-small btn-primary spud_blog_category_add_new", :title => "New Post Category" %>
3
+ <ul class="spud_blog_category_manager_list">
4
+ <% if @post_categories.length == 0 %>
5
+ <li class="spud_blog_category_manager_empty">You do not have any Post Categories at this time.</li>
6
+ <% end %>
7
+ <%= render :partial => 'category', :collection => @post_categories[nil] %>
8
+ </ul>
9
+ </div>
@@ -0,0 +1 @@
1
+ <%= render :partial => 'form', :locals => {:path => spud_admin_post_categories_path} %>
@@ -0,0 +1,47 @@
1
+ <%= content_for :data_controls do %>
2
+
3
+ <% end %>
4
+
5
+ <%=content_for :detail do %>
6
+ <table class="admin-table">
7
+ <thead>
8
+ <tr>
9
+
10
+ <th>Author</th>
11
+ <th>Comment</th>
12
+ <th>Attached To</th>
13
+ <th>Status</th>
14
+ <th>&nbsp;</th>
15
+ </tr>
16
+ </thead>
17
+ <tbody>
18
+ <% @post_comments.each do |comment| %>
19
+ <tr>
20
+ <td><%= comment.author %></td>
21
+ <td>
22
+ <span class='submitted-on'>Submitted: <%=timestamp(comment.created_at)%></span>
23
+ <%= comment.content %>
24
+ </td>
25
+ <td><%= link_to comment.post.title, blog_post_path(comment.post.url_name)%></td>
26
+ <td>
27
+ <% if comment.spam %>
28
+ Spam
29
+ <% else %>
30
+ Approved
31
+ <% end %>
32
+ </td>
33
+ <td align="right">
34
+ <%= link_to 'Approve', approve_spud_admin_post_comment_path(comment), :class => 'btn btn-success btn-small' %>
35
+ <%= link_to 'Spam', spam_spud_admin_post_comment_path(comment), :class => 'btn btn-warning btn-small' %>
36
+ <%= link_to 'Delete', spud_admin_post_comment_path(comment), :method => :delete, :confirm => 'Are you sure you want to delete this comment?', :class => 'btn btn-danger btn-small' %>
37
+ </td>
38
+ </tr>
39
+ <%end%>
40
+ </tbody>
41
+ </table>
42
+ <div class="spud_admin_pagination">
43
+ <%= will_paginate @post_comments%>
44
+ </div>
45
+
46
+
47
+ <%end%>
@@ -0,0 +1,9 @@
1
+ <%= content_tag :li, :class => 'spud_post_form_category', 'data-id' => category.id do %>
2
+ <%= check_box_tag 'spud_post[category_ids][]', category.id, @post.category_ids.include?(category.id), :id => "spud_post_category_#{category.id}" %>
3
+ <%= label_tag "spud_post_category_#{category.id}", category.name %>
4
+ <ul>
5
+ <% if @categories[category.id] %>
6
+ <%= render :partial => '/spud/admin/posts/category', :collection => @categories[category.id] %>
7
+ <% end %>
8
+ </ul>
9
+ <% end %>
@@ -0,0 +1,117 @@
1
+ <%=error_messages_for(f.object)%>
2
+
3
+ <fieldset>
4
+ <div class="control-group">
5
+ <%= f.label :title, :required=>true,:style =>"display:none;" %>
6
+ <%= f.text_field :title, :class => "full-width",:placeholder=>"Enter title here" %>
7
+ </div>
8
+ </fieldset>
9
+ <%if Spud::Blog.config.enable_markdown%>
10
+ <div class="control-group">
11
+ <div class="controls">
12
+ <%=f.select :content_format,[["HTML"],["Markdown"]], {:include_blank => false}, :class => "pull-right", "data-formatter" => "spud_post_content"%>
13
+ </div>
14
+ </div>
15
+ <%end%>
16
+ <div style="clear:both;">
17
+ <%= f.text_area :content,:style => "width:100%;", :class => 'tinymce full-width', "data-format" => f.object.content_format%>
18
+ </div>
19
+
20
+ <% if Spud::Blog.config.has_custom_fields %>
21
+ <fieldset>
22
+ <legend>Custom Fields</legend>
23
+ <%= render :partial => '/spud/admin/posts/custom_fields', :locals => {:f => f} %>
24
+ </fieldset>
25
+ <% end %>
26
+
27
+ <fieldset class="spud_post_form_fieldset">
28
+ <legend>Advanced</legend>
29
+
30
+ <div class="spud_post_form_col">
31
+ <h4>Meta Data</h4>
32
+
33
+ <div class="spud_post_form_row">
34
+ <%= f.label :published_at, 'Publish Date' %>
35
+ <%= f.text_field :published_at,:value => f.object.published_at.strftime("%Y-%m-%d %H:%M") , :class => 'spud_form_date_picker' %>
36
+ <span class="time_select">
37
+ <%= f.time_select :published_at, :ignore_date => true,:ampm => true%>
38
+ </span>
39
+ </div>
40
+
41
+ <% if @current_user.super_admin %>
42
+ <div class="spud_post_form_row">
43
+ <%= f.label :spud_user_id, 'Author' %>
44
+ <%= f.select :spud_user_id,options_for_select(SpudUser.order(:first_name,:last_name,:login).all.collect{|user| [user.full_name,user.id]},f.object.spud_user_id)%>
45
+ </div>
46
+ <% else %>
47
+ <%= f.hidden_field :spud_user_id %>
48
+ <% end %>
49
+
50
+ <% if Spud::Core.config.multisite_mode_enabled %>
51
+ <div class="spud_post_form_row">
52
+ <%= f.label :sites, 'Websites to Publish' %>
53
+ <div class="spud_post_form_input_group">
54
+ <%= spud_post_site_check_box_tag(Spud::Core.default_site_config, @post) %>
55
+ <%= spud_post_site_label_tag(Spud::Core.default_site_config) %>
56
+ <% Spud::Core.config.multisite_config.each do |site| %>
57
+ <%= spud_post_site_check_box_tag(site, @post) %>
58
+ <%= spud_post_site_label_tag(site) %>
59
+ <% end %>
60
+ </div>
61
+ </div>
62
+ <% end %>
63
+
64
+ <div class="spud_post_form_row">
65
+ <%= f.label :visible %>
66
+ <div class="spud_post_form_input_group">
67
+ <%= f.radio_button :visible, true %>
68
+ <label class="radio inline" for="spud_post_visible_true">Yes</label>
69
+ <%= f.radio_button :visible, false %>
70
+ <label class="radio inline" for="spud_post_visible_false">No</label>
71
+ </div>
72
+ </div>
73
+
74
+ <% unless @post.is_news %>
75
+ <div class="spud_post_form_row">
76
+ <%= f.label :comments_enabled,"Comments Enabled" %>
77
+ <div class="spud_post_form_input_group">
78
+ <%= f.radio_button :comments_enabled, true %>
79
+ <label class="radio inline" for="spud_post_comments_enabled_true">Yes</label>
80
+ <%= f.radio_button :comments_enabled, false %>
81
+ <label class="radio inline" for="spud_post_comments_enabled_false">No</label>
82
+ </div>
83
+ </div>
84
+ <% end %>
85
+
86
+ <div class="spud_post_form_row">
87
+ <%= f.label :meta_keywords, 'Keywords' %>
88
+ <%= f.text_field :meta_keywords %>
89
+ <span class="spud_post_form_help_block">A Comma seperated list of keywords for search engines. Keep it short (no more than 10 keywords)</span>
90
+ </div>
91
+
92
+ <div class="spud_post_form_row">
93
+ <%= f.label :meta_description, 'Description' %>
94
+ <%= f.text_area :meta_description %>
95
+ <span class="spud_post_form_help_block">A short description of the article. This is what appears on a search engines search result page.</span>
96
+ </div>
97
+ </div>
98
+
99
+ <div class="spud_post_form_col">
100
+ <h4>Categories</h4>
101
+ <%= link_to 'Add Category', new_spud_admin_post_category_path, :class => 'btn btn-mini spud_post_add_category' %>
102
+ <input type="hidden" name="spud_post[category_ids][]" value="" />
103
+ <ul class="spud_post_categories_form">
104
+ <%= render :partial => '/spud/admin/posts/category', :collection => @categories[nil] %>
105
+ </ul>
106
+ </div>
107
+
108
+ </fieldset>
109
+ <%= f.hidden_field :is_news %>
110
+
111
+ <div class="form-actions">
112
+ <%=f.submit "Save Post", :class=>"btn btn-primary form-btn","data-loading-text"=>"Saving..."%> or <%=link_to "cancel",request.referer, :class => "btn"%>
113
+ </div>
114
+
115
+ <script type="text/javascript">
116
+ $(document).ready(spud.admin.posts.edit);
117
+ </script>
@@ -0,0 +1,3 @@
1
+ <%= form_for @post, :url => spud_admin_post_path(@post), :html => {:class => 'form-horizontal'} do |f| %>
2
+ <%= render :partial => 'form', :locals => {:f => f} %>
3
+ <% end %>
@@ -0,0 +1,50 @@
1
+ <%= content_for :data_controls do %>
2
+ <%= link_to "Manage Categories", spud_admin_post_categories_path, :class => 'btn spud_blog_manage_categories', :title => 'Manage Categories' %>
3
+ <%= link_to "Manage Comments", spud_admin_post_comments_path, :class => 'btn', :title => 'Manage Comments' %>
4
+ <%= link_to "New Post", new_spud_admin_post_path, :class => "btn btn-primary", :title => "New Post" %>
5
+ <% end %>
6
+
7
+ <%=content_for :detail do %>
8
+ <table class="admin-table">
9
+ <thead>
10
+ <tr>
11
+ <th>Title</th>
12
+ <th>Author</th>
13
+ <th>Published At</th>
14
+ <th>Comments</th>
15
+ <th>&nbsp;</th>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ <% @posts.each do |post| %>
20
+ <tr>
21
+ <td>
22
+ <%= link_to edit_spud_admin_post_path(post) do %>
23
+ <%=post.title%>
24
+ <%if !post.visible%>
25
+ <span class="badge">Draft</span>
26
+ <%end%>
27
+ <%end%>
28
+ </td>
29
+ <td><%= post.author.full_name %></td>
30
+ <td><%= link_to(post.published_at.strftime('%m/%d/%Y'), blog_post_path(post.url_name)) %></td>
31
+ <td>
32
+ Approved: <%=link_to post.visible_comments.count, spud_admin_post_post_comments_path(:post_id => post.id) %>
33
+ <br/>
34
+ Spam: <%=link_to post.spam_comments.count, spud_admin_post_post_comments_path(:post_id => post.id) %>
35
+ </td>
36
+ <td align="right">
37
+ <%= link_to 'Delete', spud_admin_post_path(post), :method => :delete, :confirm => 'Are you sure you want to delete this post?', :class => 'btn btn-danger' %>
38
+ </td>
39
+ </tr>
40
+ <%end%>
41
+ </tbody>
42
+ </table>
43
+ <div class="spud_admin_pagination">
44
+ <%= will_paginate @posts %>
45
+ </div>
46
+
47
+ <script>
48
+ $(document).ready(spud.admin.post_categories.index);
49
+ </script>
50
+ <%end%>
@@ -0,0 +1,3 @@
1
+ <%= form_for @post, :url => spud_admin_posts_path do |f| %>
2
+ <%= render :partial => 'form', :locals => {:f => f} %>
3
+ <% end %>
@@ -0,0 +1,16 @@
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
data/config/routes.rb ADDED
@@ -0,0 +1,94 @@
1
+ Rails.application.routes.draw do
2
+
3
+ namespace :spud do
4
+ namespace :admin do
5
+ resources :posts do
6
+ resources :post_comments, :path => 'comments', :only => :index
7
+ end
8
+ resources :news_posts
9
+ resources :post_comments, :except => [:new, :create, :edit, :update] do
10
+ member do
11
+ get 'approve'
12
+ get 'spam'
13
+ end
14
+ end
15
+ resources :post_categories
16
+ end
17
+ namespace :blog do
18
+ resource :sitemap,:only => "show"
19
+ end
20
+ end
21
+
22
+ if Spud::Blog.config.blog_enabled
23
+ scope Spud::Blog.config.blog_path do
24
+
25
+ # Blog Post Categories
26
+ get 'category/:category_url_name(/page/:page)',
27
+ :controller => 'blog',
28
+ :action => 'category',
29
+ :as => 'blog_category',
30
+ :defaults => {:page => 1}
31
+ get 'category/:category_url_name/:archive_date(/page/:page)',
32
+ :controller => 'blog',
33
+ :action => 'category',
34
+ :as => 'blog_category_archive',
35
+ :defaults => {:page => 1}
36
+
37
+ # Blog Post Archives
38
+ get 'archive/:archive_date(/page/:page)',
39
+ :controller => 'blog',
40
+ :action => 'archive',
41
+ :as => 'blog_archive',
42
+ :defaults => {:page => 1}
43
+
44
+ # Category/Archive filtering
45
+ post '/', :controller => 'blog', :action => 'filter'
46
+
47
+ # Blog Posts
48
+ get '/(page/:page)',
49
+ :controller => 'blog',
50
+ :action => 'index',
51
+ :as => 'blog',
52
+ :defaults => {:page => 1}
53
+ resources :blog_posts, :path => '/', :controller => 'blog', :only => [:show] do
54
+ post '/', :on => :member, :controller => 'blog', :action => 'create_comment'
55
+ end
56
+ end
57
+ end
58
+
59
+ if Spud::Blog.config.news_enabled
60
+ scope Spud::Blog.config.news_path do
61
+
62
+ # News Post Categories
63
+ get 'category/:category_url_name(/page/:page)',
64
+ :controller => 'news',
65
+ :action => 'category',
66
+ :as => 'news_category',
67
+ :defaults => {:page => 1}
68
+ get 'category/:category_url_name/:archive_date(/page/:page)',
69
+ :controller => 'news',
70
+ :action => 'category',
71
+ :as => 'news_category_archive',
72
+ :defaults => {:page => 1}
73
+
74
+ # News Post Archives
75
+ get 'archive/:archive_date(/page/:page)',
76
+ :controller => 'news',
77
+ :action => 'archive',
78
+ :as => 'news_archive',
79
+ :defaults => {:page => 1}
80
+
81
+ # Category/Archive filtering
82
+ post '/', :controller => 'news', :action => 'filter'
83
+
84
+ # News Posts
85
+ get '/(page/:page)',
86
+ :controller => 'news',
87
+ :action => 'index',
88
+ :as => 'news',
89
+ :defaults => {:page => 1}
90
+ resources :news_posts, :path => '/', :controller => 'news', :only => [:show]
91
+ end
92
+ end
93
+
94
+ 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,6 @@
1
+ class AddUrlToSpudPosts < ActiveRecord::Migration
2
+ def change
3
+ add_column :spud_posts, :url_name, :string
4
+ add_index :spud_posts, :url_name
5
+ end
6
+ 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
@@ -0,0 +1,6 @@
1
+ class AddIsNewsToSpudPosts < ActiveRecord::Migration
2
+ def change
3
+ add_column :spud_posts, :is_news, :boolean, :default => false
4
+ add_index :spud_posts, :is_news
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ class AddMetaToPosts < ActiveRecord::Migration
2
+ def change
3
+ add_column :spud_posts, :meta_keywords, :string
4
+ add_column :spud_posts, :meta_description, :text
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ class AddCommentsCounterToSpudPosts < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :spud_posts, :comments_count, :integer, :default => 0
4
+ SpudPost.find_each do |post|
5
+ post.comments_count = post.comments.count
6
+ post.save
7
+ end
8
+ end
9
+ def self.down
10
+ remove_column :spud_posts, :comments_count
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ class CreateSpudPostSites < ActiveRecord::Migration
2
+ def change
3
+ create_table :spud_post_sites do |t|
4
+ t.integer :spud_post_id, :null => false
5
+ t.integer :spud_site_id, :null => false
6
+ t.timestamps
7
+ end
8
+ add_index :spud_post_sites, :spud_post_id
9
+ add_index :spud_post_sites, :spud_site_id
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ class AddSpamFieldsToSpudPostComments < ActiveRecord::Migration
2
+ def change
3
+ add_column :spud_post_comments, :spam, :boolean
4
+ add_column :spud_post_comments, :user_ip, :string
5
+ add_column :spud_post_comments, :user_agent, :string
6
+ add_column :spud_post_comments, :referrer, :string
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ class AddPermalinkToSpudPostComments < ActiveRecord::Migration
2
+ def change
3
+ add_column :spud_post_comments, :permalink, :string
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ class AddNestedSetToPostCategories < ActiveRecord::Migration
2
+ def up
3
+ change_table :spud_post_categories do |t|
4
+ t.integer :lft
5
+ t.integer :rgt
6
+ t.integer :depth
7
+ end
8
+
9
+ # Populates lft, rgt, and depth values for nested set
10
+ SpudPostCategory.where(:parent_id => 0).update_all({:parent_id => nil})
11
+ SpudPostCategory.rebuild!
12
+ end
13
+
14
+ def down
15
+ change_table :spud_post_categories do |t|
16
+ t.remove :ltf
17
+ t.remove :rgt
18
+ t.remove :depth
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ class AddContentFormatToSpudPosts < ActiveRecord::Migration
2
+ def change
3
+ add_column :spud_posts, :content_format, :string, :default => "HTML"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddContentProcessedToSpudPost < ActiveRecord::Migration
2
+ def change
3
+ add_column :spud_posts, :content_processed, :text
4
+ end
5
+ end
@@ -0,0 +1,60 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class Spud::Blog::RandomPostsGenerator < ::Rails::Generators::Base
4
+
5
+ def generate
6
+ if Spud::Blog.config.blog_enabled
7
+ puts 'Generating random blog posts...'
8
+ random_posts(false)
9
+ end
10
+ if Spud::Blog.config.news_enabled
11
+ puts 'Generating random news posts...'
12
+ random_posts(true)
13
+ end
14
+ puts 'Assigning categories...'
15
+ category_ids = SpudPostCategory.all.collect{ |c| c.id }
16
+ SpudPost.all.each do |p|
17
+ p.category_ids = [category_ids[rand(category_ids.length)]]
18
+ p.save
19
+ end
20
+ puts 'Done!'
21
+ end
22
+
23
+ private
24
+
25
+ def random_posts(is_news)
26
+ 100.times do
27
+ post = SpudPost.create({
28
+ :title => random_title,
29
+ :content => random_content,
30
+ :published_at => random_time,
31
+ :visible => 1,
32
+ :spud_user_id => 1,
33
+ :is_news => is_news
34
+ })
35
+ end
36
+ end
37
+
38
+ def random_word
39
+ chars = 'abcdefghjkmnpqrstuvwxyz'
40
+ length = rand(8) + 1
41
+ return (1..length).collect{ chars[rand(chars.length)] }.join('')
42
+ end
43
+
44
+ def random_title
45
+ return (1..4).collect{ random_word.capitalize }.join(' ')
46
+ end
47
+
48
+ def random_content
49
+ content = ''
50
+ 3.times do |i|
51
+ content += '<p>' + (1..30).collect{ random_word }.join(' ').capitalize + '.</p>'
52
+ end
53
+ return content
54
+ end
55
+
56
+ def random_time
57
+ return Time.at(1.year.ago + rand * (Time.now.to_f - 1.year.ago.to_f))
58
+ end
59
+
60
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class Spud::Blog::ViewsGenerator < ::Rails::Generators::Base
4
+
5
+ source_root File.expand_path('../../../../../app/views', __FILE__)
6
+
7
+ def install
8
+ if Spud::Blog.config.blog_enabled
9
+ copy_file 'blog/_comment.html.erb', 'app/views/blog/_comment.html.erb'
10
+ copy_file 'blog/_comment_form.html.erb', 'app/views/blog/_comment_form.html.erb'
11
+ copy_file 'blog/index.html.erb', 'app/views/blog/index.html.erb'
12
+ copy_file 'blog/show.html.erb', 'app/views/blog/show.html.erb'
13
+ end
14
+ if Spud::Blog.config.news_enabled
15
+ copy_file 'news/index.html.erb', 'app/views/news/index.html.erb'
16
+ copy_file 'news/show.html.erb', 'app/views/news/show.html.erb'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Spud
2
+ module Blog
3
+ include ActiveSupport::Configurable
4
+ config_accessor(
5
+ :base_layout, :news_layout, :blog_enabled,
6
+ :news_enabled, :posts_per_page, :blog_path,
7
+ :news_path, :enable_sitemap, :has_custom_fields,
8
+ :cache_mode, :action_caching_duration,
9
+ :enable_rakismet, :enable_markdown
10
+ )
11
+ self.base_layout = 'application'
12
+ self.news_layout = nil
13
+ self.news_enabled = false
14
+ self.blog_enabled = true
15
+ self.posts_per_page = 5
16
+ self.blog_path = 'blog'
17
+ self.news_path = 'news'
18
+ self.enable_sitemap = true
19
+ self.has_custom_fields = false
20
+ self.cache_mode = nil #options :full_page, :action
21
+ self.action_caching_duration = 3600
22
+ self.enable_rakismet = false
23
+ self.enable_markdown = false
24
+ end
25
+ end