diaspora/app/helpers/notifier_helper.rb
Jonne Haß 8280556a47 Introduce message renderer
This new class replaces all existing server side message
rendering helpers and is the new global entry point for such
needs. All models with relevant fields now expose an instance
of MessageRenderer for those. MessageRenderer acts as
gateway between the existing processing solutions for markdown,
mentions and tags and provides a very flexible interface for
all output needs. This makes the API to obtain a message
in a certain format clear. As a result of centralizing the
processing a lot of duplication is eliminated. Centralizing
the message processing also makes it clear where to change
its behaviour, add new representations and what options
are already available.
2014-03-15 17:16:17 +01:00

20 lines
719 B
Ruby

module NotifierHelper
# @param post [Post] The post object.
# @param opts [Hash] Optional hash. Accepts :length parameters.
# @return [String] The truncated and formatted post.
def post_message(post, opts={})
if post.respond_to? :message
post.message.plain_text_without_markdown truncate: opts.fetch(:length, 200)
else
I18n.translate 'notifier.a_post_you_shared'
end
end
# @param comment [Comment] The comment to process.
# @param opts [Hash] Optional hash. Accepts :length parameters.
# @return [String] The truncated and formatted comment.
def comment_message(comment, opts={})
comment.message.plain_text_without_markdown truncate: opts.fetch(:length, 600)
end
end