Skip to content

Instantly share code, notes, and snippets.

@frankie-loves-jesus
Last active August 29, 2015 14:03
Show Gist options
  • Save frankie-loves-jesus/2a0ab7920b1e232a557d to your computer and use it in GitHub Desktop.
Save frankie-loves-jesus/2a0ab7920b1e232a557d to your computer and use it in GitHub Desktop.
def forem_emojify(content)
h(content).to_str
# Convert regular emoticons
.gsub(' :)', ' :smile:')
.gsub(' ;)', ' :wink:')
.gsub(' :D', ' :laughing:')
.gsub(' :P', ' :stuck_out_tongue:')
.gsub(' :p', ' :stuck_out_tongue:')
.gsub(' :O', ' :open_mouth:')
.gsub(' :o', ' :open_mouth:')
.gsub(' :|', ' :expressionless:')
.gsub(' :/', ' :disappointed:')
.gsub(' :(', ' :disappointed:')
# Match emojis
.gsub(/:([a-z0-9\+\-_]+):/) do |match|
if Emoji.names.include?($1)
'<img alt="' + $1 + '" height="20" src="' + asset_path("emoji/#{$1}.png") + '" style="vertical-align:middle" width="20" />'
else
match
end
end.html_safe if content.present?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment