Skip to content

Commit

Permalink
add comment quote function
Browse files Browse the repository at this point in the history
  • Loading branch information
robbin committed Feb 24, 2013
1 parent f337d02 commit cdd910a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
- Next
* comment editor preview
* reply quote commenter's name
* replace weibo_2 with my own weibo auth code

- Someday
Expand Down
13 changes: 12 additions & 1 deletion app/controllers/blog.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: utf-8

RobbinSite.controllers :blog do

get :index do
Expand Down Expand Up @@ -46,8 +48,17 @@
end
end

get :quote_comment, :map => '/comment/quote' do
return false unless account_login?
return false unless params[:id]
comment = BlogComment.find params[:id].to_i
body = "\n> #{comment.account.name} 评论:\n"
comment.content.gsub(/\n{3,}/, "\n\n").split("\n").each {|line| body << "> #{line}\n"}
body
end

post :comment_preview, :map => '/comment/preview' do
halt 401 unless account_login?
return false unless account_login?
Sanitize.clean(GitHub::Markdown.to_html(params[:term], :gfm), Sanitize::Config::RELAXED) if params[:term]
end

Expand Down
3 changes: 2 additions & 1 deletion app/views/blog/_comment.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<span class="user_name"><%= commenter_link(comment.account) %></span>
<span class="time"><%= time_ago_in_words(comment.created_at) %></span>
<% if account_admin? || (account_commenter? && comment.account == current_account) %>
<span><a href="#" title="引用" class="quote_comment"><%= image_tag 'quote.png', :alt => '引用' %></a></span>
<span><%= link_to "删除", url(:blog, :comment, :id => comment.id), :method => :delete, :remote => true, :confirm => '要删除评论吗?' %></span>
<% end %>
</div>
<p><%= comment.md_content.html_safe %></p>
<div class="comment_content"><%= comment.md_content.html_safe %></div>
</div>
</li>
11 changes: 11 additions & 0 deletions app/views/blog/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@
});
return false;
});

// quote comment
$('div.cot_con a.quote_comment').click(function(){
var commentBlock = $(this).closest('li');
$.get('<%= url(:blog, :quote_comment) %>', {id: commentBlock.attr('id')}, function(data){
var body = $('textarea#blog_comment_content').val() + data;
$('textarea#blog_comment_content').val(body);
$('textarea#blog_comment_content').focus();
});
return false;
});
});
</script>
<% end %>
Binary file added public/images/quote.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cdd910a

Please sign in to comment.