diff --git a/app/helpers/notifier_helper.rb b/app/helpers/notifier_helper.rb index 582e80115..3f841fdb5 100644 --- a/app/helpers/notifier_helper.rb +++ b/app/helpers/notifier_helper.rb @@ -1,4 +1,8 @@ module NotifierHelper + + # @param post [Post] The post object. + # @param opts [Hash] Optional hash. Accepts :length and :process_newlines parameters. + # @return [String] The truncated and formatted post. def post_message(post, opts={}) opts[:length] ||= 200 if post.respond_to? :formatted_message @@ -9,4 +13,14 @@ module NotifierHelper I18n.translate 'notifier.a_post_you_shared' end end + + # @param comment [Comment] The comment to process. + # @param opts [Hash] Optional hash. Accepts :length and :process_newlines parameters. + # @return [String] The truncated and formatted comment. + def comment_message(comment, opts={}) + opts[:length] ||= 600 + text = truncate(@comment.text, :length => opts[:length]) + text = process_newlines(text) if opts[:process_newlines] + text + end end diff --git a/app/views/notifier/also_commented.html.haml b/app/views/notifier/also_commented.html.haml index ee9cf451c..9b37b4d73 100644 --- a/app/views/notifier/also_commented.html.haml +++ b/app/views/notifier/also_commented.html.haml @@ -1,4 +1,4 @@ %p - = post_message(@comment, :process_newlines => true, :length => 600) + = comment_message(@comment.text, :process_newlines => true) %p = link_to t('notifier.comment_on_post.reply', :name => @comment.post.author.first_name), post_url(@comment.post) diff --git a/app/views/notifier/also_commented.text.haml b/app/views/notifier/also_commented.text.haml index cbb52570a..7bc518d95 100644 --- a/app/views/notifier/also_commented.text.haml +++ b/app/views/notifier/also_commented.text.haml @@ -1 +1 @@ -!= truncate(@comment.text, :length => 600) +!= comment_message(@comment.text) diff --git a/app/views/notifier/comment_on_post.html.haml b/app/views/notifier/comment_on_post.html.haml index c5209611a..407aea032 100644 --- a/app/views/notifier/comment_on_post.html.haml +++ b/app/views/notifier/comment_on_post.html.haml @@ -1,4 +1,4 @@ %p - = post_message(@comment, :process_newlines => true, :length => 600) + = comment_message(@comment.text, :process_newlines => true) %p = link_to t('notifier.comment_on_post.reply', :name => @comment.post.author.name), post_url(@comment.post) diff --git a/app/views/notifier/comment_on_post.text.haml b/app/views/notifier/comment_on_post.text.haml index cbb52570a..7bc518d95 100644 --- a/app/views/notifier/comment_on_post.text.haml +++ b/app/views/notifier/comment_on_post.text.haml @@ -1 +1 @@ -!= truncate(@comment.text, :length => 600) +!= comment_message(@comment.text) diff --git a/spec/helpers/notifier_helper_spec.rb b/spec/helpers/notifier_helper_spec.rb new file mode 100644 index 000000000..d7ee368cb --- /dev/null +++ b/spec/helpers/notifier_helper_spec.rb @@ -0,0 +1,20 @@ +# Copyright (c) 2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' + +describe NotifierHelper do + include MarkdownifyHelper + + describe '#comment_message' do + before do + @comment = Factory(:comment) + end + + it 'truncates the comment' do + opts = {:length => 2} + comment_message(@comment, opts).should == truncate(@comment.text, opts) + end + end +end