diff --git a/app/helpers/notifier_helper.rb b/app/helpers/notifier_helper.rb index 582e80115a3cbdf2ebdfb5456410307371b1649a..3f841fdb5768387ecfeb10e09ef176d098a37752 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 ee9cf451c355478c36c8da56ef85daee955c6ce0..9b37b4d73af8820b34048a085680d130a0d30536 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 cbb52570a6f2a4de916f74f64e1cceea2b5664fc..7bc518d954fe70a438af4c8776ab66d2e029d2e5 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 c5209611afea766d0378c73a85995d91317472c8..407aea0326d21d912692cc4f107ac96883ae1e2b 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 cbb52570a6f2a4de916f74f64e1cceea2b5664fc..7bc518d954fe70a438af4c8776ab66d2e029d2e5 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 0000000000000000000000000000000000000000..d7ee368cb67b59390a48eebcd31adf6a4eb9ff38 --- /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