Skip to content

Commit cdd910a

Browse files
committed
add comment quote function
1 parent f337d02 commit cdd910a

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

TODO

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
- Next
2-
* comment editor preview
3-
* reply quote commenter's name
42
* replace weibo_2 with my own weibo auth code
53

64
- Someday

app/controllers/blog.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# encoding: utf-8
2+
13
RobbinSite.controllers :blog do
24

35
get :index do
@@ -46,8 +48,17 @@
4648
end
4749
end
4850

51+
get :quote_comment, :map => '/comment/quote' do
52+
return false unless account_login?
53+
return false unless params[:id]
54+
comment = BlogComment.find params[:id].to_i
55+
body = "\n> #{comment.account.name} 评论:\n"
56+
comment.content.gsub(/\n{3,}/, "\n\n").split("\n").each {|line| body << "> #{line}\n"}
57+
body
58+
end
59+
4960
post :comment_preview, :map => '/comment/preview' do
50-
halt 401 unless account_login?
61+
return false unless account_login?
5162
Sanitize.clean(GitHub::Markdown.to_html(params[:term], :gfm), Sanitize::Config::RELAXED) if params[:term]
5263
end
5364

app/views/blog/_comment.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
<span class="user_name"><%= commenter_link(comment.account) %></span>
66
<span class="time"><%= time_ago_in_words(comment.created_at) %></span>
77
<% if account_admin? || (account_commenter? && comment.account == current_account) %>
8+
<span><a href="#" title="引用" class="quote_comment"><%= image_tag 'quote.png', :alt => '引用' %></a></span>
89
<span><%= link_to "删除", url(:blog, :comment, :id => comment.id), :method => :delete, :remote => true, :confirm => '要删除评论吗?' %></span>
910
<% end %>
1011
</div>
11-
<p><%= comment.md_content.html_safe %></p>
12+
<div class="comment_content"><%= comment.md_content.html_safe %></div>
1213
</div>
1314
</li>

app/views/blog/show.erb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@
132132
});
133133
return false;
134134
});
135+
136+
// quote comment
137+
$('div.cot_con a.quote_comment').click(function(){
138+
var commentBlock = $(this).closest('li');
139+
$.get('<%= url(:blog, :quote_comment) %>', {id: commentBlock.attr('id')}, function(data){
140+
var body = $('textarea#blog_comment_content').val() + data;
141+
$('textarea#blog_comment_content').val(body);
142+
$('textarea#blog_comment_content').focus();
143+
});
144+
return false;
145+
});
135146
});
136147
</script>
137148
<% end %>

public/images/quote.png

1.49 KB
Loading

0 commit comments

Comments
 (0)