Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

moved comments sort order to the settings/options

  • Loading branch information...
commit 348ac99de6572f3e465a0f2d4956bb7ee10c2864 1 parent 442f74a
authored March 28, 2012
2  app/views/opinio/comments/create.js.erb
@@ -7,7 +7,7 @@ $('#no_comments').hide();
7 7
     $('#commentable_id').val('<%= @comment.commentable.commentable_id %>');
8 8
     $('#commentable_type').val('<%= @comment.commentable.commentable_type %>');
9 9
   <% else %>
10  
-    $('#comments').prepend("<%= escape_javascript( render @comment, :locals => {:reply => @reply} ) %>");
  10
+    $('#comments').<%= Opinio.sort_order == 'ASC' ? 'append' : 'prepend'%>("<%= escape_javascript( render @comment, :locals => {:reply => @reply} ) %>");
11 11
   <% end %>
12 12
   $('textarea#comment_body').val('');
13 13
 <% else %>
3  lib/generators/opinio/install/templates/initializers/opinio.erb
@@ -17,4 +17,7 @@ Opinio.setup do |config|
17 17
   # Strip html tags on save comment
18 18
   config.strip_html_tags_on_save = true
19 19
 
  20
+  # Comments sort order by created_at (DESC or ASC)
  21
+  config.sort_order = 'DESC'
  22
+
20 23
 end
3  lib/opinio.rb
@@ -34,6 +34,9 @@ module Controllers
34 34
   mattr_accessor :strip_html_tags_on_save
35 35
   @@strip_html_tags_on_save = true
36 36
 
  37
+  mattr_accessor :sort_order
  38
+  @@sort_order = 'DESC'
  39
+
37 40
   def self.setup
38 41
     yield self
39 42
   end
2  lib/opinio/opinio_subjectum.rb
@@ -12,7 +12,7 @@ def opinio_subjectum(*args)
12 12
         has_many :comments,
13 13
                  :class_name => Opinio.model_name,
14 14
                  :as => :commentable,
15  
-                 :order => options.reverse_merge(:order => "created_at DESC")[:order],
  15
+                 :order => options.reverse_merge(:order => "created_at #{Opinio.sort_order}")[:order],
16 16
                  :dependent => :destroy
17 17
 
18 18
 
1  spec/opinio_spec.rb
@@ -14,6 +14,7 @@
14 14
     Opinio.use_title = true
15 15
     Opinio.use_title.should == true
16 16
     Opinio.strip_html_tags_on_save.should == true
  17
+    Opinio.sort_order.should == "DESC"
17 18
   end
18 19
 
19 20
   it "should accept identifiers" do

0 notes on commit 348ac99

Please sign in to comment.
Something went wrong with that request. Please try again.