tkh_content 0.9.15 → 0.9.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddaafe17fdfb0f5223668dce65eff0e7f95548d4
4
- data.tar.gz: 0dfab79e9ed637e6981f8f5af5da7307436bde5a
3
+ metadata.gz: cc7e2632e838c737c884c85407b4ecb138a45bb8
4
+ data.tar.gz: 6e6fde83fa313aa364ece8625235ed2662cb0741
5
5
  SHA512:
6
- metadata.gz: f45d405a4c45ef21a1d302f3cac1c4850c40dea1b601b31f122cd4c06cf9cb3442fc2f28e09b83ce7fd82a3b9c0e661a2552c08c6f9fb6df81afb9374fad3767
7
- data.tar.gz: 8b9ca69acd5ff94f6abb7bec97e6fd6706da9146428910d5a77d57cdf6935765eecb55a7c94ee89002ab593f7da2fec471a10158f320863bbbcea11ad395de69
6
+ metadata.gz: 8ea78f5026638811c223906318f257b27728768c0afea888cacfda3bcfead1fadf4c71c065fd61c723608686ba194d60046a728197c730aa57d37a11d5cc942c
7
+ data.tar.gz: 5c4782a9dc46a68ee159ac6283622bb03036c6cc8b23f2d4a39032b9a21034c5f2a9a72349ef6b654c0e771f809940a67c6c2fbd467c0662c4c0d059bfad0132
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # TKH Content
2
2
 
3
3
 
4
+
5
+ ## 0.9.16
6
+
7
+ * Comments are now polymorphic. rake 'tkh_content:update' and 'rake db:migrate' commands needed.
8
+
9
+
4
10
  ## 0.9.14-15
5
11
 
6
12
  * Upgraded Rails and simple_form dependencies.
@@ -22,10 +22,10 @@ class CommentsController < ApplicationController
22
22
  @comment.locale = I18n.locale.to_s
23
23
  @comment.status = 'pending' # translation not done with globalize3 but with locale files upon showing status to user
24
24
  if @comment.save
25
- redirect_to @comment.page, notice: t('comments.create.notice')
25
+ redirect_to @comment.commentable, notice: t('comments.create.notice')
26
26
  else
27
27
  flash[:warning] = t('comments.create.warning')
28
- redirect_to @comment.page
28
+ redirect_to @comment.commentable
29
29
  end
30
30
  end
31
31
 
@@ -94,7 +94,7 @@ class CommentsController < ApplicationController
94
94
 
95
95
  # Never trust parameters from the scary internet, only allow the white list through.
96
96
  def comment_params
97
- params.require(:comment).permit(:body, :page_id)
97
+ params.require(:comment).permit(:body, :commentable_type, :commentable_id)
98
98
  # non-accessible attributes: author_id, :status, :locale
99
99
  end
100
100
 
@@ -6,9 +6,9 @@
6
6
  class Comment < ActiveRecord::Base
7
7
 
8
8
  belongs_to :author, class_name: 'User', foreign_key: 'author_id'
9
- belongs_to :page
9
+ belongs_to :commentable, polymorphic: true
10
10
 
11
- validates_presence_of :page_id, :body
11
+ validates_presence_of :commentable_type, :commentable_id, :author_id, :body
12
12
 
13
13
  scope :showable, -> { where('status = ? OR status = ?', 'pending', 'accepted') }
14
14
  scope :pending, -> { where('status = ?', 'pending') }
data/app/models/page.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  class Page < ActiveRecord::Base
7
7
 
8
8
  belongs_to :author, class_name: 'User'
9
- has_many :comments, :dependent => :destroy
9
+ has_many :comments, as: :commentable, :dependent => :destroy
10
10
 
11
11
  has_many :taggings, :dependent => :destroy
12
12
  has_many :tags, through: :taggings
@@ -0,0 +1,13 @@
1
+ <tr>
2
+ <td class='text-center'>
3
+ <% model_name = comment.commentable.class.name.underscore %>
4
+ <% p = model_name.to_s + '_path' %>
5
+ <%= comment.author.name %> - <%= link_to (comment.commentable.try(:title) || comment.commentable.try(:name)), comment.commentable %> (<%= comment.locale %>). <%= link_to l(comment.created_at, format: :tkh_default), p(comment.commentable, anchor: "comment-#{comment.id}") %>
6
+ <br /><br />
7
+ <p class="admin-comment-body"><%= sanitize comment.body.gsub(/\r\n?/, "<br>"), :tags => %w(br), :attributes => %w() %></p>
8
+ <strong><%= t("comments.status.#{comment.status}") %></strong><br />
9
+ <%= render 'comments/status_buttons', comment: comment %>
10
+ <br /><br />
11
+ <%= link_to t('edit'), edit_comment_path(comment), class: 'btn btn-xs btn-default' %><%= link_to t('delete'), comment, method: :delete, data: { confirm: t('are_you_sure') }, class: 'btn btn-xs btn-danger' %>
12
+ </td>
13
+ </tr>
@@ -0,0 +1,6 @@
1
+ <div id="comment-section">
2
+ <% # host variable correspond to commentable polymorphic host %>
3
+ <h2><%= pluralize host.comments.showable.for_locale(I18n.locale.to_s).count, t('activerecord.models.comment') %></h2>
4
+ <%= render 'comments/list_of_comments', host: host %>
5
+ <%= render 'comments/new_comment_section' %>
6
+ </div>
@@ -1,14 +1,14 @@
1
1
  <%= simple_form_for @comment, :html => { class: 'form-horizontal' } do |f| %>
2
2
  <%= f.error_notification %>
3
-
3
+
4
4
  <div class="form-inputs">
5
5
  <%= @comment.author.name %><br />
6
- <%= link_to @comment.page.title, @comment.page %><br />
7
- <%= f.input :short_title, hint: 'ideally one word only, used for the menu' %><br />
8
- <%= render 'comments/status_buttons' %><br />
6
+ <%= link_to (@comment.commentable.title || @comment.commentable.name), @comment.commentable %><br />
7
+ <%#= f.input :short_title, hint: 'ideally one word only, used for the menu' %><br />
8
+ <%= render 'comments/status_buttons', comment: @comment %><br />
9
9
  <%= f.input :body, :input_html => { :rows => 3 } %>
10
10
  </div>
11
-
11
+
12
12
  <div class="form-actions">
13
13
  <%= f.button :submit, :class => 'btn btn-primary' %>
14
14
  </div>
@@ -3,8 +3,9 @@
3
3
 
4
4
  <div class="form-inputs">
5
5
  <%= f.input :body, label: false, :input_html => { :rows => 8 } %>
6
- <%= f.hidden_field :page_id, value: @page.id %>
6
+ <%= f.hidden_field :commentable_type, value: controller_name.classify %>
7
+ <%= f.hidden_field :commentable_id, value: params[:id] %>
7
8
  <%= f.button :submit, :class => 'btn btn-primary' %>
8
9
  </div>
9
10
 
10
- <% end %>
11
+ <% end %>
@@ -1,5 +1,5 @@
1
- <% @page.comments.showable.for_locale(I18n.locale.to_s).by_created.each_with_index do |comment, index| %>
2
- <div id="comment-<%= comment.id %>" class="individual-comment<%= " by-page-author" if comment.author_id == comment.page.author_id %>">
1
+ <% host.comments.showable.for_locale(I18n.locale.to_s).by_created.each_with_index do |comment, index| %>
2
+ <div id="comment-<%= comment.id %>" class="individual-comment<%= " by-page-author" if comment.author_id == comment.commentable.try(:author_id) %>">
3
3
  <p>
4
4
  <span class="comment-index"><%= index + 1 %></span>
5
5
  <span class="comment-author-name"><%= comment.author.name %></span>
@@ -1,7 +1,7 @@
1
1
  <div id="new-comment-section">
2
2
  <h3><%= t('comments.what_do_you_think') %></h3>
3
3
  <% if current_user %>
4
- <%= render 'comments/form_in_page' %>
4
+ <%= render 'comments/form_in_commentable' %>
5
5
  <% else %>
6
6
  <p><label class="label label-info"><%= t('comments.login_needed') %></label></p>
7
7
  <%= render 'shared/embedded_access_control' %>
@@ -1,7 +1,7 @@
1
1
  <% if comment.status == 'pending' %>
2
- <%= link_to t('comments.moderation.actions.accept'), accept_comment_path(comment), method: :post, class: 'btn btn-xs btn-default' %><%= link_to t('comments.moderation.actions.block'), block_comment_path(comment), method: :post, class: 'btn btn-xs btn-default' %>
2
+ <%= link_to t('comments.moderation.actions.accept'), accept_comment_path(comment), method: :post, class: 'btn btn-xs btn-success' %><%= link_to t('comments.moderation.actions.block'), block_comment_path(comment), method: :post, class: 'btn btn-xs btn-default' %>
3
3
  <% elsif comment.status == 'accepted' %>
4
4
  <%= link_to t('comments.moderation.actions.block'), block_comment_path(comment), method: :post, class: 'btn btn-xs btn-default' %>
5
5
  <% elsif comment.status == 'blocked' %>
6
- <%= link_to t('comments.moderation.actions.accept'), accept_comment_path(comment), method: :post, class: 'btn btn-xs btn-default' %>
6
+ <%= link_to t('comments.moderation.actions.accept'), accept_comment_path(comment), method: :post, class: 'btn btn-xs btn-success' %>
7
7
  <% end -%>
@@ -3,23 +3,9 @@
3
3
  <%= render 'tab_admin_menu' %>
4
4
 
5
5
  <table class='table table-striped'>
6
- <thead>
7
- <tr>
8
- <th><%= t('activerecord.attributes.comments.author') %>, <%= t('activerecord.models.page') %>, <%= t('activerecord.attributes.comments.locale') %><br />
9
- <%= t('activerecord.attributes.comments.body') %></th>
10
- <th><%= t('activerecord.attributes.comments.status') %></th>
11
- <th><%= t('actions') %></th>
12
- </tr>
13
- </thead>
14
-
15
6
  <tbody>
16
7
  <% @comments.each do |comment| %>
17
- <tr>
18
- <td><%= comment.author.name %> - <%= link_to comment.page.title, comment.page %> | <%= comment.locale %><br /><br />
19
- <%= sanitize comment.body.gsub(/\r\n?/, "<br>"), :tags => %w(br), :attributes => %w() %></td>
20
- <td><%= t("comments.status.#{comment.status}") %><%= t 'colon' %><%= render 'comments/status_buttons', comment: comment %></td>
21
- <td><%= link_to t('edit'), edit_comment_path(comment), class: 'btn btn-mini' %><%= link_to t('delete'), comment, method: :delete, data: { confirm: t('are_you_sure') }, class: 'btn btn-mini btn-danger' %></td>
22
- </tr>
8
+ <%= render 'comments/admin_individual_comment', comment: comment %>
23
9
  <% end %>
24
10
  </tbody>
25
11
  </table>
@@ -3,23 +3,9 @@
3
3
  <%= render 'tab_admin_menu' %>
4
4
 
5
5
  <table class='table table-striped'>
6
- <thead>
7
- <tr>
8
- <th><%= t('activerecord.attributes.comments.author') %>, <%= t('activerecord.models.page') %>, <%= t('activerecord.attributes.comments.locale') %><br />
9
- <%= t('activerecord.attributes.comments.body') %></th>
10
- <th><%= t('activerecord.attributes.comments.status') %></th>
11
- <th><%= t('actions') %></th>
12
- </tr>
13
- </thead>
14
-
15
6
  <tbody>
16
7
  <% @comments.each do |comment| %>
17
- <tr>
18
- <td><%= comment.author.name %> - <%= link_to comment.page.title, comment.page %> | <%= comment.locale %><br /><br />
19
- <%= sanitize comment.body.gsub(/\r\n?/, "<br>"), :tags => %w(br), :attributes => %w() %></td>
20
- <td><%= t("comments.status.#{comment.status}") %><%= t 'colon' %><%= render 'comments/status_buttons', comment: comment %></td>
21
- <td><%= link_to t('edit'), edit_comment_path(comment), class: 'btn btn-mini' %><%= link_to t('delete'), comment, method: :delete, data: { confirm: t('are_you_sure') }, class: 'btn btn-mini btn-danger' %></td>
22
- </tr>
8
+ <%= render 'comments/admin_individual_comment', comment: comment %>
23
9
  <% end %>
24
10
  </tbody>
25
11
  </table>
@@ -1,6 +1,5 @@
1
1
  <h1><%= t('activerecord.models.comments') %></h1>
2
-
3
-
2
+ <%= render 'tab_admin_menu' %>
4
3
 
5
4
  <%= render 'form' %>
6
5
  <%= render 'shared/admin_sidebar' %>
@@ -5,24 +5,9 @@
5
5
  <%= will_paginate @comments, inner_window: 2 %>
6
6
 
7
7
  <table class='table table-striped'>
8
- <thead>
9
- <tr>
10
- <th><%= t('activerecord.attributes.comments.author') %>, <%= t('activerecord.models.page') %>, <%= t('activerecord.attributes.comments.locale') %><br />
11
- <%= t('activerecord.attributes.comments.body') %></th>
12
- <th><%= t('activerecord.attributes.comments.status') %></th>
13
- <th><%= t('actions') %></th>
14
- </tr>
15
- </thead>
16
-
17
8
  <tbody>
18
9
  <% @comments.each do |comment| %>
19
- <tr>
20
- <td><%= comment.author.name %> - <%= link_to comment.page.title, comment.page %> | <%= comment.locale %><br /><br />
21
- <%= sanitize comment.body.gsub(/\r\n?/, "<br>"), :tags => %w(br), :attributes => %w() %></td>
22
-
23
- <td><%= t("comments.status.#{comment.status}") %><%= t 'colon' %><%= render 'comments/status_buttons', comment: comment %></td>
24
- <td><%= link_to t('edit'), edit_comment_path(comment), class: 'btn btn-xs btn-default' %><%= link_to t('delete'), comment, method: :delete, data: { confirm: t('are_you_sure') }, class: 'btn btn-xs btn-danger' %></td>
25
- </tr>
10
+ <%= render 'comments/admin_individual_comment', comment: comment %>
26
11
  <% end %>
27
12
  </tbody>
28
13
  </table>
@@ -5,23 +5,9 @@
5
5
  <p><%= t('comments.sorted_by_oldest') %></p>
6
6
 
7
7
  <table class='table table-striped'>
8
- <thead>
9
- <tr>
10
- <th><%= t('activerecord.attributes.comments.author') %>, <%= t('activerecord.models.page') %>, <%= t('activerecord.attributes.comments.locale') %><br />
11
- <%= t('activerecord.attributes.comments.body') %></th>
12
- <th><%= t('activerecord.attributes.comments.status') %></th>
13
- <th><%= t('actions') %></th>
14
- </tr>
15
- </thead>
16
-
17
8
  <tbody>
18
9
  <% @comments.each do |comment| %>
19
- <tr>
20
- <td><%= comment.author.name %> - <%= link_to comment.page.title, comment.page %> | <%= comment.locale %><br /><br />
21
- <%= sanitize comment.body.gsub(/\r\n?/, "<br>"), :tags => %w(br), :attributes => %w() %></td>
22
- <td><%= t("comments.status.#{comment.status}") %><%= t 'colon' %><%= render 'comments/status_buttons', comment: comment %></td>
23
- <td><%= link_to t('edit'), edit_comment_path(comment), class: 'btn btn-mini' %><%= link_to t('delete'), comment, method: :delete, data: { confirm: t('are_you_sure') }, class: 'btn btn-mini btn-danger' %></td>
24
- </tr>
10
+ <%= render 'comments/admin_individual_comment', comment: comment %>
25
11
  <% end %>
26
12
  </tbody>
27
13
  </table>
@@ -5,14 +5,14 @@
5
5
  <% unless @page.for_blog? %>
6
6
 
7
7
  <%= raw tkhed(@page.body) %>
8
- <%= render 'comment_section' if Setting.first.enable_comments_in_pages? %>
8
+ <%= render 'comments/comment_section', host: @page if Setting.first.enable_comments_in_pages? %>
9
9
 
10
10
  <% else %>
11
11
 
12
12
  <%= content_tag(:h1, @page.title) %>
13
13
  <%= render '/pages/blog_post_meta', post: @page %>
14
14
  <%= raw tkhed(@page.body) %>
15
- <%= render 'comment_section' if Setting.first.enable_comments_in_blog? %>
15
+ <%= render 'comments/comment_section', host: @page if Setting.first.enable_comments_in_blog? %>
16
16
  <%= render 'blog/all_tags_list' %>
17
17
 
18
18
  <% end -%>
@@ -1,5 +1,5 @@
1
1
  require 'rails/generators/migration'
2
-
2
+
3
3
  module TkhContent
4
4
  module Generators
5
5
  class CreateOrUpdateMigrationsGenerator < ::Rails::Generators::Base
@@ -14,7 +14,7 @@ module TkhContent
14
14
  end
15
15
  @prev_migration_nr.to_s
16
16
  end
17
-
17
+
18
18
  def copy_migrations
19
19
  puts 'creating or updating page migrations'
20
20
  migration_template "create_pages.rb", "db/migrate/create_pages.rb"
@@ -26,8 +26,9 @@ module TkhContent
26
26
  migration_template "create_contacts.rb", "db/migrate/create_contacts.rb"
27
27
  migration_template "add_various_indices_to_pages.rb", "db/migrate/add_various_indices_to_pages.rb"
28
28
  migration_template "create_comments.rb", "db/migrate/create_comments.rb"
29
+ migration_template "make_comments_polymorphic.rb", "db/migrate/make_comments_polymorphic.rb"
29
30
  end
30
-
31
+
31
32
  end
32
33
  end
33
- end
34
+ end
@@ -0,0 +1,36 @@
1
+ class MakeCommentsPolymorphic < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ add_column :comments, :commentable_type, :string
5
+ add_column :comments, :commentable_id, :integer
6
+ add_index :comments, :commentable_id
7
+
8
+ Comment.all.each do |comment|
9
+ unless comment.page_id.blank?
10
+ comment.commentable_type = 'Page'
11
+ comment.commentable_id = comment.page_id
12
+ comment.save
13
+ end
14
+ end
15
+
16
+ # Clean up comment table. The index is removed automatically
17
+ remove_column :comments, :page_id
18
+
19
+ end
20
+
21
+ def self.down
22
+ add_column :comments, :page_id
23
+ add_index :comments, :page_id
24
+
25
+ Comment.all.each do |comment|
26
+ if comment.commentable_type == 'Page'
27
+ comment.page_id = comment.commentable_id
28
+ comment.save
29
+ end
30
+ end
31
+
32
+ remove_column :comments, :commentable_type, :string
33
+ remove_column :comments, :commentable_id, :integer
34
+
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module TkhContent
2
- VERSION = "0.9.15"
2
+ VERSION = "0.9.16"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tkh_content
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.15
4
+ version: 0.9.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Swami Atma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-21 00:00:00.000000000 Z
11
+ date: 2014-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -153,9 +153,12 @@ files:
153
153
  - app/views/blog/by_tag.html.erb
154
154
  - app/views/blog/index.atom.builder
155
155
  - app/views/blog/index.html.erb
156
+ - app/views/comments/_admin_individual_comment.html.erb
157
+ - app/views/comments/_comment_section.html.erb
156
158
  - app/views/comments/_form.html.erb
157
- - app/views/comments/_form_in_page.html.erb
159
+ - app/views/comments/_form_in_commentable.html.erb
158
160
  - app/views/comments/_list_of_comments.html.erb
161
+ - app/views/comments/_new_comment_section.html.erb
159
162
  - app/views/comments/_status_buttons.html.erb
160
163
  - app/views/comments/_tab_admin_menu.html.erb
161
164
  - app/views/comments/accepted.html.erb
@@ -171,10 +174,8 @@ files:
171
174
  - app/views/contacts/show.html.erb
172
175
  - app/views/pages/_admin_context_menu.html.erb
173
176
  - app/views/pages/_blog_post_meta.html.erb
174
- - app/views/pages/_comment_section.html.erb
175
177
  - app/views/pages/_form.html.erb
176
178
  - app/views/pages/_individual_blog_post_in_list.html.erb
177
- - app/views/pages/_new_comment_section.html.erb
178
179
  - app/views/pages/_tab_admin_menu.html.erb
179
180
  - app/views/pages/edit.html.erb
180
181
  - app/views/pages/index.html.erb
@@ -204,6 +205,7 @@ files:
204
205
  - lib/generators/tkh_content/create_or_update_migrations/templates/create_pages.rb
205
206
  - lib/generators/tkh_content/create_or_update_migrations/templates/create_taggings.rb
206
207
  - lib/generators/tkh_content/create_or_update_migrations/templates/create_tags.rb
208
+ - lib/generators/tkh_content/create_or_update_migrations/templates/make_comments_polymorphic.rb
207
209
  - lib/tasks/tkh_content_tasks.rake
208
210
  - lib/tkh_content.rb
209
211
  - lib/tkh_content/version.rb
@@ -1,5 +0,0 @@
1
- <div id="comment-section">
2
- <h2><%= pluralize @page.comments.showable.for_locale(I18n.locale.to_s).count, t('activerecord.models.comment') %></h2>
3
- <%= render 'comments/list_of_comments' %>
4
- <%= render 'new_comment_section' %>
5
- </div>