Class: CommentPresenter
- Inherits:
-
BasePresenter
- Object
- BasePresenter
- CommentPresenter
- Defined in:
- app/presenters/comment_presenter.rb
Instance Attribute Summary
Attributes inherited from BasePresenter
Instance Method Summary (collapse)
- - (Object) avatar
- - (Object) comment_class
- - (Object) link_to_destroy
- - (Object) link_to_edit
- - (Object) render_comment
- - (Object) title_and_link(group = 1)
- - (Object) user_and_time
- - (Object) user_time_and_ip
Methods inherited from BasePresenter
Constructor Details
This class inherits a constructor from BasePresenter
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class BasePresenter
Instance Method Details
- (Object) avatar
18 19 20 21 22 23 24 |
# File 'app/presenters/comment_presenter.rb', line 18 def avatar if user=comment.user image_tag( user.avatar_url(:thumb), :class => 'without-shadow', :style => 'float: right;') else image_tag( '/images/avatars/thumb/missing.png', :class => 'without-shadow', :style => 'float: right;') end end |
- (Object) comment_class
45 46 47 |
# File 'app/presenters/comment_presenter.rb', line 45 def comment_class comment.created_at||Time::now > current_user_field(:last_sign_in_at,Time::now()-1.hour) ? "new_comment" : "old_comment" end |
- (Object) link_to_destroy
58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/presenters/comment_presenter.rb', line 58 def link_to_destroy if can?( :destroy, session[:comments] ) raw link_to( I18n.translate(:destroy), comment_path(comment, (comment.commentable.class.to_s.underscore.downcase+"_id").to_sym => comment.commentable.id.to_s ), :method => :delete, :remote => true, :confirm => t(:are_you_sure), :class => "button delete tiny" ).gsub("rel=\"nofollow\"","") end end |
- (Object) link_to_edit
49 50 51 52 53 54 55 56 |
# File 'app/presenters/comment_presenter.rb', line 49 def link_to_edit link_to( comment.time_left_to_edit > 0 ? \ I18n.translate(:edit_for_another_count_minutes,:count => comment.time_left_to_edit) :\ I18n.translate(:edit), edit_comment_path(comment, (comment.commentable.class.to_s.underscore.downcase+"_id").to_sym => comment.commentable.id.to_s ), :remote => true, :class => "button edit tiny" ) if can?( :manage, comment, session[:comments] ) end |
- (Object) render_comment
37 38 39 40 41 42 43 |
# File 'app/presenters/comment_presenter.rb', line 37 def render_comment if comment.commentable comment.commentable.render_for_html(comment.comment||'').html_safe else markdown(comment.comment||'') end end |
- (Object) title_and_link(group = 1)
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/presenters/comment_presenter.rb', line 5 def title_and_link(group=1) if group == 1 link_to( comment.commentable.title, commentable_show_path(comment.commentable) ) + content_tag( :small ) do " (" + comment.commentable.class.to_s.humanize + ")" end else content_tag( :small, :style => 'font-size: 0.7em;' ) do I18n.translate(:orphanded_comment).html_safe end end end |
- (Object) user_and_time
26 27 28 29 |
# File 'app/presenters/comment_presenter.rb', line 26 def user_and_time I18n.translate(:user_wrote_a_comment_at, :user => comment.name || 'Anonymous', :at => distance_of_time_in_words_to_now(comment.created_at)).html_safe end |
- (Object) user_time_and_ip
31 32 33 34 35 |
# File 'app/presenters/comment_presenter.rb', line 31 def user_time_and_ip user_and_time + " (" + comment.created_at + ", " + I18n.translate(:posted_from_ip, :ip => (comment.from_ip || "n/a") ) end |