Skip to content

Commit

Permalink
moved comments sort order to the settings/options
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Kotlyar committed Mar 28, 2012
1 parent 442f74a commit 348ac99
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/views/opinio/comments/create.js.erb
Expand Up @@ -7,7 +7,7 @@ $('#no_comments').hide();
$('#commentable_id').val('<%= @comment.commentable.commentable_id %>');
$('#commentable_type').val('<%= @comment.commentable.commentable_type %>');
<% else %>
$('#comments').prepend("<%= escape_javascript( render @comment, :locals => {:reply => @reply} ) %>");
$('#comments').<%= Opinio.sort_order == 'ASC' ? 'append' : 'prepend'%>("<%= escape_javascript( render @comment, :locals => {:reply => @reply} ) %>");
<% end %>
$('textarea#comment_body').val('');
<% else %>
Expand Down
Expand Up @@ -17,4 +17,7 @@ Opinio.setup do |config|
# Strip html tags on save comment
config.strip_html_tags_on_save = true

# Comments sort order by created_at (DESC or ASC)
config.sort_order = 'DESC'

end
3 changes: 3 additions & 0 deletions lib/opinio.rb
Expand Up @@ -34,6 +34,9 @@ module Controllers
mattr_accessor :strip_html_tags_on_save
@@strip_html_tags_on_save = true

mattr_accessor :sort_order
@@sort_order = 'DESC'

def self.setup
yield self
end
Expand Down
2 changes: 1 addition & 1 deletion lib/opinio/opinio_subjectum.rb
Expand Up @@ -12,7 +12,7 @@ def opinio_subjectum(*args)
has_many :comments,
:class_name => Opinio.model_name,
:as => :commentable,
:order => options.reverse_merge(:order => "created_at DESC")[:order],
:order => options.reverse_merge(:order => "created_at #{Opinio.sort_order}")[:order],
:dependent => :destroy


Expand Down
1 change: 1 addition & 0 deletions spec/opinio_spec.rb
Expand Up @@ -14,6 +14,7 @@
Opinio.use_title = true
Opinio.use_title.should == true
Opinio.strip_html_tags_on_save.should == true
Opinio.sort_order.should == "DESC"
end

it "should accept identifiers" do
Expand Down

0 comments on commit 348ac99

Please sign in to comment.