MorningPeak/app/helpers/tickets_helper.rb
Arthur Poulet 3821b72b16 improve ticket description display
Now, ticket description display the images with <img>, links with <a>
and <br> when \n is inputed
- remove helper: html_with_br
- add helpers: descriptionize, linkize, imagize, brize
2015-08-01 15:10:49 +02:00

47 lines
964 B
Ruby

module TicketsHelper
def link_to_creator ticket
if ticket.creator_type == "User"
return link_to ticket.creator_name, ticket.creator.client
else
return ticket.creator_name
end
end
def admin_tickets_unview_count
return if not admin_signed_in?
return current_admin.tickets_unview.count
end
def brize text
texts = text.split("\n")
texts.join(tag(:br))
end
def imagize text, uris
uris.each do |uri|
text.gsub!(uri, "<a href='#{uri}'><img src='#{uri}' alt='#{uri}'/></a>")
end
text
end
def linkize text, uris
uris.each do |uri|
text.gsub!(uri, "<a href='#{uri}'>#{uri}</a>")
end
text
end
def descriptionize text
uris = URI.extract(text)
imgs = uris.select{|e| e.match(/\.(jpg|png|jpeg|gif)\Z/)}
links = uris - imgs
text = raw text
text = brize text
text = imagize text, imgs
text = linkize text, links
text.html_safe
end
end