tkh_content 0.2.1 → 0.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
 
4
4
 
5
+ ## 0.3
6
+
7
+ * Added a comment resource and integrated it with the page show views.
8
+ * Added a few translations. Many more to do
9
+
10
+
5
11
  ## 0.2.1
6
12
 
7
13
  * Debugged, and therefore enabled, the autocomplete of the parent page title in pages form
@@ -0,0 +1,81 @@
1
+ class CommentsController < ApplicationController
2
+
3
+ before_filter :authenticate
4
+ before_filter :authenticate_with_admin, :except => 'create'
5
+
6
+ def index
7
+ @comments = Comment.by_recent
8
+ switch_to_admin_layout
9
+ end
10
+
11
+ # comments are shown within a page
12
+ # new comments are created by users from within a page
13
+
14
+ def edit
15
+ @comment = Comment.find params[:id]
16
+ switch_to_admin_layout
17
+ end
18
+
19
+ def create
20
+ @comment = Comment.new params[:comment]
21
+ @comment.author_id = current_user.id
22
+ @comment.locale = I18n.locale.to_s
23
+ @comment.status = 'pending' # translation not done with globalize3 but with locale files upon showing status to user
24
+ if @comment.save
25
+ redirect_to @comment.page, notice: t('comments.create.notice')
26
+ else
27
+ redirect_to @comment.page, warning: t('comments.create.warning')
28
+ end
29
+ end
30
+
31
+ def update
32
+ @comment = Comment.find(params[:id])
33
+ if @comment.update_attributes(params[:comment])
34
+ redirect_to comments_path, notice: t('comments.update.notice')
35
+ else
36
+ render action: "edit", warning: t('comments.update.warning'), layout: 'admin'
37
+ end
38
+ end
39
+
40
+ def destroy
41
+ @comment = Comment.find(params[:id])
42
+ @comment.destroy
43
+ redirect_to comments_url, notice: t('comments.destroy.notice')
44
+ end
45
+
46
+ def accept
47
+ @comment = Comment.find params[:id]
48
+ @comment.status = 'accepted'
49
+ if @comment.save
50
+ redirect_to :back, notice: t('comments.moderation.accept.notice')
51
+ else
52
+ redirect_to comments_path, warning: t('comments.moderation.accept.warning')
53
+ end
54
+ end
55
+
56
+ def block
57
+ @comment = Comment.find params[:id]
58
+ @comment.status = 'blocked'
59
+ if @comment.save
60
+ redirect_to :back, notice: t('comments.moderation.block.notice')
61
+ else
62
+ redirect_to comments_path, warning: t('comments.moderation.block.warning')
63
+ end
64
+ end
65
+
66
+ def pending
67
+ @comments = Comment.pending
68
+ switch_to_admin_layout
69
+ end
70
+
71
+ def accepted
72
+ @comments = Comment.accepted.by_recent
73
+ switch_to_admin_layout
74
+ end
75
+
76
+ def blocked
77
+ @comments = Comment.blocked.by_recent
78
+ switch_to_admin_layout
79
+ end
80
+
81
+ end
@@ -0,0 +1,25 @@
1
+ # this is needed for now to make mass assignment security compatible with the translation of globalize3
2
+ Globalize::ActiveRecord::Translation.class_eval do
3
+ attr_accessible :locale
4
+ end
5
+
6
+ class Comment < ActiveRecord::Base
7
+
8
+ belongs_to :author, class_name: 'User', foreign_key: 'author_id'
9
+ belongs_to :page
10
+
11
+ # non-accessible attributes: author_id, :status, :locale
12
+ attr_accessible :body, :page_id
13
+
14
+ validates_presence_of :page_id, :body
15
+
16
+ scope :showable, where('status = ? OR status = ?', 'pending', 'accepted')
17
+ scope :pending, where('status = ?', 'pending')
18
+ scope :accepted, where('status = ?', 'accepted')
19
+ scope :blocked, where('status = ?', 'blocked')
20
+ scope :for_locale, lambda { |locale| where('locale = ?', locale) }
21
+ scope :by_recent, order('updated_at desc')
22
+ scope :by_created, order('created_at')
23
+ scope :by_recently_created, order('created_at desc')
24
+
25
+ end
data/app/models/page.rb CHANGED
@@ -6,6 +6,7 @@ end
6
6
  class Page < ActiveRecord::Base
7
7
 
8
8
  belongs_to :author, class_name: 'User', foreign_key: 'author_id'
9
+ has_many :comments, :dependent => :destroy
9
10
 
10
11
  attr_accessible :title, :short_title, :description, :body, :for_blog, :parent_id, :tag_list, :parent_page_title
11
12
 
@@ -0,0 +1,16 @@
1
+ <%= simple_form_for @comment, :html => { class: 'form-horizontal' } do |f| %>
2
+ <%= f.error_notification %>
3
+
4
+ <div class="form-inputs">
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 />
9
+ <%= f.input :body, :input_html => { :rows => 3 } %>
10
+ </div>
11
+
12
+ <div class="form-actions">
13
+ <%= f.button :submit, :class => 'btn btn-primary' %>
14
+ </div>
15
+
16
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <%= simple_form_for Comment.new do |f| %>
2
+ <%= f.error_notification %>
3
+
4
+ <div class="form-inputs">
5
+ <%= f.input :body, label: false, :input_html => { :rows => 8 } %>
6
+ <%= f.hidden_field :page_id, value: @page.id %>
7
+ <%= f.button :submit, :class => 'btn btn-primary' %>
8
+ </div>
9
+
10
+ <% end %>
@@ -0,0 +1,10 @@
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">
3
+ <p>
4
+ <span class="comment-index"><%= index + 1 %></span>
5
+ <span class="comment-author-name"><%= comment.author.name %></span>
6
+ <span class="comment-created-date"><%= l comment.created_at, format: :tkh_default %></span>
7
+ <span class="comment-body"><%= sanitize comment.body.gsub(/\r\n?/, "<br>"), :tags => %w(br), :attributes => %w() %></span>
8
+ </p>
9
+ </div>
10
+ <% end %>
@@ -0,0 +1,7 @@
1
+ <% if comment.status == 'pending' %>
2
+ <%= link_to t('comments.moderation.actions.accept'), accept_comment_path(comment), method: :post, class: 'btn btn-mini btn-primary' %><%= link_to t('comments.moderation.actions.block'), block_comment_path(comment), method: :post, class: 'btn btn-mini btn-danger' %>
3
+ <% elsif comment.status == 'accepted' %>
4
+ <%= link_to t('comments.moderation.actions.block'), block_comment_path(comment), method: :post, class: 'btn btn-mini btn-danger' %>
5
+ <% elsif comment.status == 'blocked' %>
6
+ <%= link_to t('comments.moderation.actions.accept'), accept_comment_path(comment), method: :post, class: 'btn btn-mini btn-primary' %>
7
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ <h1>Edit a Comment</h1>
2
+ <%= render 'form' %>
3
+ <%= render 'shared/admin_sidebar' %>
@@ -0,0 +1,29 @@
1
+ <h1>List of Comments</h1>
2
+
3
+ <table class='table table-striped'>
4
+ <thead>
5
+ <tr>
6
+ <th><%= t 'activerecord.attributes.comments.author' %></th>
7
+ <th><%= t 'activerecord.attributes.comments.page' %></th>
8
+ <th><%= t 'activerecord.attributes.comments.body' %></th>
9
+ <th><%= t 'activerecord.attributes.comments.status' %></th>
10
+ <th><%= t 'activerecord.attributes.comments.locale' %></th>
11
+ <th>Actions</th>
12
+ </tr>
13
+ </thead>
14
+
15
+ <tbody>
16
+ <% @comments.each do |comment| %>h
17
+ <tr>
18
+ <td><%= comment.author.name %></td>
19
+ <td><%= link_to comment.page.title, comment.page %></td>
20
+ <td><%= truncate comment.body, length: 75, separator: ' ...' %></td>
21
+ <td><%= comment.status %><%= t 'colon' %><%= render 'comments/status_buttons', comment: comment %></td>
22
+ <td><%= comment.locale %></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>
25
+ <% end %>
26
+ </tbody>
27
+ </table>
28
+
29
+ <%= render 'shared/admin_sidebar' %>
@@ -1,4 +1,4 @@
1
1
  <p class="meta-info">
2
- by <%= post.author.name %> <%= post.published_at ? "on #{l(post.published_at, format: :tkh_default)}" : "- not published yet" %> | <%= link_to 'Permalink', post %>
2
+ by <%= post.author.name %> <%= post.published_at ? "on #{l(post.published_at, format: :tkh_default)}" : "- not published yet" %> | <%= link_to 'Permalink', post %> | <%= pluralize post.comments.showable.for_locale(I18n.locale.to_s).count, 'comments' %>
3
3
  <%="| #{link_to 'edit', edit_page_path(post), class: 'btn btn-mini'}".html_safe if administrator? %>
4
4
  </p>
@@ -0,0 +1,7 @@
1
+ <div id="comment-section">
2
+ <h2><%= pluralize @page.comments.showable.for_locale(I18n.locale.to_s).count, 'Comment' %></h2>
3
+ <%= render 'comments/list_of_comments' %>
4
+ <%= render 'new_comment_section' %>
5
+ </div>
6
+
7
+ <%= render( 'admin_context_menu', page: @page) if administrator? %>
@@ -0,0 +1,9 @@
1
+ <div id="new-comment-section">
2
+ <h3>What do you think?</h3>
3
+ <% if current_user %>
4
+ <%= render 'comments/form_in_page' %>
5
+ <% else %>
6
+ <p><label class="label label-info">You need to be logged in to leave a comment</label></p>
7
+ <%= render 'shared/embedded_login_module' %>
8
+ <% end -%>
9
+ </div>
@@ -2,15 +2,14 @@
2
2
  <% content_for :meta_description, @page.description %>
3
3
 
4
4
  <% unless @page.for_blog? %>
5
-
6
5
  <%= raw tkhed(@page.body) %>
7
- <%= render( 'admin_context_menu', page: @page) if administrator? %>
8
-
6
+ <%= render 'comment_section' if Setting.first.enable_comments_in_pages? %>
9
7
  <% else %>
10
8
 
11
9
  <%= content_tag(:h1, @page.title) %>
12
10
  <%= render '/pages/blog_post_meta', post: @page %>
13
11
  <%= raw tkhed(@page.body) %>
12
+ <%= render 'comment_section' if Setting.first.enable_comments_in_blog? %>
14
13
 
15
14
  <% end -%>
16
15
 
data/config/routes.rb CHANGED
@@ -10,8 +10,22 @@ Rails.application.routes.draw do
10
10
  post :sort
11
11
  end
12
12
  end
13
+
14
+ resources :contacts
15
+
16
+ resources :comments do
17
+ collection do
18
+ get :pending
19
+ get :accepted
20
+ get :blocked
21
+ end
22
+ member do
23
+ post :accept
24
+ post :block
25
+ end
26
+ end
13
27
  get 'blog' => 'blog#index', as: :blog
14
28
  get 'tags/:tag', to: 'blog#index', as: :tag
15
- resources :contacts
29
+
16
30
  end
17
31
  end
@@ -1,4 +1,11 @@
1
1
  de:
2
+
3
+ are_you_sure: 'Bist Du sicher?'
4
+ colon: ':'
5
+ delete: 'löschen'
6
+ edit: 'bearbeiten'
7
+ pages: 'Seiten'
8
+ sections: 'Abschnitte'
2
9
 
3
10
  time:
4
11
  formats:
@@ -41,10 +48,11 @@ de:
41
48
  notice: 'Die Seite wurde gelöscht.'
42
49
  root_warning: "Du kannst diese Seite nicht löschen, da es die Root-Seite ist. Du kannst sie nur bearbeiten."
43
50
 
44
- contacts:
51
+ contacts:
52
+ messages_from_forms: 'messages from contact form'
45
53
  send_message: 'Nachricht senden'
46
54
  sent: 'Gesendet am'
47
55
 
48
56
  create:
49
57
  notice: 'Die Nachricht wurde gesendet.'
50
- warning: 'Beim Versenden der Nachricht gab es ein Problem.'
58
+ warning: 'Beim Versenden der Nachricht gab es ein Problem.'
@@ -19,8 +19,15 @@ en:
19
19
  sender_name: "sender name"
20
20
  sender_email: 'sender email'
21
21
  body: 'message'
22
+
23
+ comments:
24
+ author: 'author'
25
+ body: "body text"
26
+ locale: 'language'
27
+ status: 'status'
22
28
 
23
29
  are_you_sure: 'are you sure?'
30
+ colon: ':'
24
31
  delete: 'delete'
25
32
  edit: 'edit'
26
33
  pages: 'pages'
@@ -40,11 +47,36 @@ en:
40
47
  destroy:
41
48
  notice: 'The page was deleted'
42
49
  root_warning: "You cannot delete this page as this is the root page of the site. You should only modify it."
43
-
50
+
44
51
  contacts:
52
+ messages_from_forms: 'messages from contact form'
45
53
  send_message: 'send message'
46
54
  sent: 'Sent at'
47
-
55
+
48
56
  create:
49
57
  notice: 'Your message has been sent'
50
58
  warning: 'There was a problem sending your message.'
59
+
60
+ comments:
61
+ create:
62
+ notice: 'The comment was successfully created.'
63
+ warning: 'There was a problem saving the comment to the database'
64
+ update:
65
+ notice: 'The comment was successfully updated.'
66
+ warning: 'There was a problem saving this comment'
67
+ destroy:
68
+ notice: 'The comment was deleted'
69
+ moderation:
70
+ accept:
71
+ notice: "This comment has been accepted"
72
+ warning: "Some error occurred and the comment could not be moderated and accepted"
73
+ block:
74
+ notice: "This comment has been blocked"
75
+ warning: "Some error occurred and the comment could not be moderated and blocked"
76
+ actions:
77
+ accept: "accept!"
78
+ block: "block!"
79
+ status:
80
+ pending: 'pending'
81
+ accepted: 'accepted'
82
+ blocked: 'blocked'
@@ -7,6 +7,7 @@ es:
7
7
  tkh_default: "%d de %B de %Y %H:%M"
8
8
 
9
9
  are_you_sure: '¿estás seguro?'
10
+ colon: ':'
10
11
  delete: 'borrar'
11
12
  edit: 'editar'
12
13
  pages: 'paginas'
@@ -41,7 +42,8 @@ es:
41
42
  notice: 'la página se ha eliminado'
42
43
  root_warning: "No se puede eliminar la página, ya que es la bienvenida principal. Por favor, cámbialo."
43
44
 
44
- contacts:
45
+ contacts:
46
+ messages_from_forms: 'mensajes del formulario de contacto'
45
47
  send_message: 'enviar el mensaje'
46
48
  sent: 'Enviado a las'
47
49
 
@@ -7,6 +7,7 @@ fr:
7
7
  tkh_default: "%d %b %Y à %H:%M"
8
8
 
9
9
  are_you_sure: 'êtes vous sûr ?'
10
+ colon: ' :'
10
11
  delete: 'supprimer'
11
12
  edit: 'modifier'
12
13
  pages: 'pages'
@@ -41,10 +42,11 @@ fr:
41
42
  notice: 'La page a été supprimée.'
42
43
  root_warning: "Vous ne pouvez pas supprimer cette page parce que c'est la page principale de bienvenue. Veuillez la modifier."
43
44
 
44
- contacts:
45
+ contacts:
46
+ messages_from_forms: 'messages du formulaire de contact'
45
47
  send_message: 'envoyez le message'
46
48
  sent: 'Envoyé le'
47
49
 
48
50
  create:
49
51
  notice: 'Votre message a bien été envoyé.'
50
- warning: "Il y'a eu un probleme en envoyant votre message."
52
+ warning: "Il y'a eu un probleme en envoyant votre message."
@@ -25,6 +25,7 @@ module TkhContent
25
25
  migration_template "create_taggings.rb", "db/migrate/create_taggings.rb"
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
+ migration_template "create_comments.rb", "db/migrate/create_comments.rb"
28
29
  end
29
30
 
30
31
  end
@@ -0,0 +1,25 @@
1
+ class CreateComments < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :comments do |t|
5
+ t.text :body
6
+ t.integer :page_id
7
+ t.integer :author_id
8
+ t.string :locale
9
+ t.string :status, :default => 'pending'
10
+ t.timestamps
11
+ end
12
+ add_index :comments, :page_id
13
+ add_index :comments, :author_id
14
+ add_index :comments, :locale
15
+ add_index :comments, :status
16
+ end
17
+
18
+ def self.down
19
+ drop_table :comments
20
+ remove_index :comments, :page_id
21
+ remove_index :comments, :author_id
22
+ remove_index :comments, :locale
23
+ remove_index :comments, :status
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module TkhContent
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tkh_content
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: '0.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-27 00:00:00.000000000 Z
12
+ date: 2013-01-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -165,24 +165,34 @@ files:
165
165
  - app/assets/javascripts/ckeditor/config.js.coffee
166
166
  - app/assets/javascripts/pages.js.coffee
167
167
  - app/controllers/blog_controller.rb
168
+ - app/controllers/comments_controller.rb
168
169
  - app/controllers/contacts_controller.rb
169
170
  - app/controllers/pages_controller.rb
170
171
  - app/helpers/blog_helper.rb
171
172
  - app/helpers/pages_helper.rb
172
173
  - app/mailers/contact_mailer.rb
174
+ - app/models/comment.rb
173
175
  - app/models/contact.rb
174
176
  - app/models/page.rb
175
177
  - app/models/tag.rb
176
178
  - app/models/tagging.rb
177
179
  - app/views/blog/index.html.erb
178
180
  - app/views/blog/index.rss.builder
181
+ - app/views/comments/_form.html.erb
182
+ - app/views/comments/_form_in_page.html.erb
183
+ - app/views/comments/_list_of_comments.html.erb
184
+ - app/views/comments/_status_buttons.html.erb
185
+ - app/views/comments/edit.html.erb
186
+ - app/views/comments/index.html.erb
179
187
  - app/views/contact_mailer/message_from_contact_form.text.erb
180
188
  - app/views/contacts/_form.html.erb
181
189
  - app/views/contacts/index.html.erb
182
190
  - app/views/pages/_admin_context_menu.html.erb
183
191
  - app/views/pages/_blog_post_meta.html.erb
192
+ - app/views/pages/_comment_section.html.erb
184
193
  - app/views/pages/_form.html.erb
185
194
  - app/views/pages/_individual_blog_post_in_list.html.erb
195
+ - app/views/pages/_new_comment_section.html.erb
186
196
  - app/views/pages/edit.html.erb
187
197
  - app/views/pages/index.html.erb
188
198
  - app/views/pages/new.html.erb
@@ -201,6 +211,7 @@ files:
201
211
  - lib/generators/tkh_content/create_or_update_migrations/templates/add_parent_id_to_pages.rb
202
212
  - lib/generators/tkh_content/create_or_update_migrations/templates/add_short_title_to_pages.rb
203
213
  - lib/generators/tkh_content/create_or_update_migrations/templates/add_various_indices_to_pages.rb
214
+ - lib/generators/tkh_content/create_or_update_migrations/templates/create_comments.rb
204
215
  - lib/generators/tkh_content/create_or_update_migrations/templates/create_contacts.rb
205
216
  - lib/generators/tkh_content/create_or_update_migrations/templates/create_pages.rb
206
217
  - lib/generators/tkh_content/create_or_update_migrations/templates/create_taggings.rb
@@ -256,7 +267,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
256
267
  version: '0'
257
268
  segments:
258
269
  - 0
259
- hash: -3916766060710411944
270
+ hash: 3348047770526547114
260
271
  required_rubygems_version: !ruby/object:Gem::Requirement
261
272
  none: false
262
273
  requirements:
@@ -265,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
265
276
  version: '0'
266
277
  segments:
267
278
  - 0
268
- hash: -3916766060710411944
279
+ hash: 3348047770526547114
269
280
  requirements: []
270
281
  rubyforge_project:
271
282
  rubygems_version: 1.8.23