Module: RenderingHelper
- Defined in:
- app/helpers/rendering_helper.rb
Constant Summary collapse
- AUTO_LINK_MESSAGE_RE =
%r{message://<[^>]+>}
Instance Method Summary collapse
-
#auto_link_message(text) ⇒ Object
Converts message:// links to href.
- #render_text(text) ⇒ Object
- #textile(text) ⇒ Object
Instance Method Details
#auto_link_message(text) ⇒ Object
Converts message:// links to href. This URL scheme is used on Mac OS X to link to a mail message in Mail.app.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/rendering_helper.rb', line 6 def (text) text.gsub(AUTO_LINK_MESSAGE_RE) do href = $& left = $` right = $' # detect already linked URLs and URLs in the middle of a tag if left =~ /<[^>]+$/ && right =~ /^[^>]*>/ # do not change string; URL is already linked href else content_tag(:a, h(href), :href => href) end end end |
#render_text(text) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/rendering_helper.rb', line 21 def render_text(text) rendered = (text) rendered = textile(rendered) rendered = auto_link(rendered, link: :urls, html: { target: '_blank' }) relaxed_config = Sanitize::Config::RELAXED config = relaxed_config # add onenote and message protocols, allow a target a_href_config = relaxed_config[:protocols]['a']['href'] + %w[onenote message obsidian] a_attributes = relaxed_config[:attributes]['a'] + ['target'] config = Sanitize::Config.merge(config, protocols: { 'a' => { 'href' => a_href_config } }, :attributes => { 'a' => a_attributes }) rendered = Sanitize.fragment(rendered, config) return rendered.html_safe end |
#textile(text) ⇒ Object
38 39 40 |
# File 'app/helpers/rendering_helper.rb', line 38 def textile(text) RedCloth.new(text).to_html end |