Sha256: 0652fd43e6c91d30e446e7b2bc3a629d6c1a95a9227c189a5d08940a3bb80d6f
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
module RailsEmoji class << self def render(*args) options = args.extract_options!.stringify_keys host = options['host'] return if args[0].blank? if options.key? 'size' if options['size'] =~ %r{\A\d+x\d+\z} options['width'], options['height'] = options['size'].split('x') else options['width'] = options['height'] = options['size'] end end options.slice! 'class', 'width', 'height', 'title', 'alt' options.reverse_merge! 'class' => 'emoji', 'width' => 20, 'height' => 20 # replace emoji code to image tag args[0].gsub(/:([a-z0-9_+-]+):/) do |emoji| return emoji unless RailsEmoji::EMOJI.include? emoji[1..-2] attrs = options.reverse_merge( 'src' => "#{host}/assets/emojis/#{emoji[1..-2]}.png", 'alt' => emoji, 'title' => emoji ).select{ |k, v| !v.blank? }.collect{ |k, v| %(#{k}="#{v}") } %(<img #{attrs * ' '} />) end end end end # extend to String class class String def emojify RailsEmoji.render(self) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails_emoji-1.7.0 | lib/rails_emoji/render.rb |