diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a599438a147f23fb1b63525c030b04c9c224045f..be469ff32321e183d0bd7453bdd164a51bfa4851 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -169,21 +169,17 @@ module ApplicationHelper def markdownify(message, options = {}) message = h(message).html_safe - if !options.has_key?(:newlines) - options[:newlines] = true - end + options[:newlines] = true if !options.has_key?(:newlines) + options[:emoticons] = true if !options.has_key?(:emoticons) message = process_links(message) message = process_autolinks(message) message = process_emphasis(message) message = process_youtube(message, options[:youtube_maps]) message = process_vimeo(message, options[:vimeo_maps]) + message = process_emoticons(message) if options[:emoticons] - message.gsub!(/<3/, "♥") - - if options[:newlines] - message.gsub!(/\n+/, '<br />') - end + message.gsub!(/\n+/, '<br />') if options[:newlines] return message end @@ -279,6 +275,24 @@ module ApplicationHelper return processed_message end + def process_emoticons(message) + map = { + "<3" => "♥", + ":(" => "☹", + ":-(" => "☹", + ":)" => "☺", + ":-)" => "☺", + "->" => "→", + "<-" => "←", + "..." => "…" + } + + map.each do |search, replace| + message.gsub!(search, replace) + end + message + end + def info_text(text) image_tag 'icons/monotone_question.png', :class => 'what_is_this', :title => text end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 6660ace48d8a1fcf0de9dd7198e096ef66aecd17..d86e64e004165385d78fe8e6550b5776d8c9f1ed 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -161,11 +161,21 @@ describe ApplicationHelper do end end - describe "hearts" do + describe "emoticons" do it "replaces <3 with ♥" do message = "i <3 you" markdownify(message).should == "i ♥ you" end + + it "replaces various things with (their) HTML entities" do + message = ":) :-) :( :-( ... -> <-" + markdownify(message).should == "☺ ☺ ☹ ☹ … → ←" + end + + it "skips doing it if you say so" do + message = ":) :-) :( :-( ... -> <-" + markdownify(message, :emoticons => false).should == ":) :-) :( :-( ... -> <-" + end end describe "weak emphasis" do