Module: MongoidForums::FormattingHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/mongoid_forums/formatting_helper.rb

Instance Method Summary collapse

Instance Method Details

#as_formatted_html(text) ⇒ Object

override with desired markup formatter, e.g. textile or markdown



4
5
6
7
8
9
10
# File 'app/helpers/mongoid_forums/formatting_helper.rb', line 4

def as_formatted_html(text)
  if MongoidForums.formatter
    MongoidForums.formatter.format(as_sanitized_text(text))
  else
    MongoidForums::Sanitizer.sanitize(text).html_safe
  end
end

#as_quoted_text(text) ⇒ Object



12
13
14
15
16
17
18
# File 'app/helpers/mongoid_forums/formatting_helper.rb', line 12

def as_quoted_text(text)
  if MongoidForums.formatter && MongoidForums.formatter.respond_to?(:blockquote)
    MongoidForums.formatter.blockquote(as_sanitized_text(text)).html_safe
  else
     "<blockquote>#{(h(text))}</blockquote>\n\n".html_safe
  end
end

#as_sanitized_text(text) ⇒ Object



20
21
22
23
24
25
26
# File 'app/helpers/mongoid_forums/formatting_helper.rb', line 20

def as_sanitized_text(text)
  if MongoidForums.formatter.respond_to?(:sanitize)
    MongoidForums.formatter.sanitize(text)
  else
    MongoidForums::Sanitizer.sanitize(text)
  end
end

#emojify(content) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'app/helpers/mongoid_forums/formatting_helper.rb', line 28

def emojify(content)
  h(content).to_str.gsub(/:([\w+-]+):/) do |match|
    if emoji = Emoji.find_by_alias($1)
      %(<img alt="#$1" src="#{asset_path("emoji/#{emoji.image_filename}", type: :image)}" style="vertical-align:middle" width="20" height="20" />)
    else
      match
    end
  end.html_safe if content.present?
end