Sha256: d9b41dbf8d290858d0a89a5e55213b086e4a9ae520033466e8b8be97dd365ee6

Contents?: true

Size: 791 Bytes

Versions: 2

Compression:

Stored size: 791 Bytes

Contents

module RailsEmoji
  class << self

    def render(text, *args)
      options = args.extract_options!

      host = options[:host] || ""
      size = options[:size] || 20
      class_name = options[:class] || "emoji"

      # Replace
      text.gsub(/:([a-z0-9_\-\+]+):/) do |emoji|
        emoji_code = emoji
        emoji = emoji_code.gsub(":", "")

        if RailsEmoji::EMOJI.include?(emoji)
          %{<img src="#{ host }/assets/emojis/#{ emoji.gsub('+', 'plus') }.png" } +
            %{width="#{ size }" height="#{ size }" } +
            %{title="#{ emoji_code }" alt="#{ emoji_code }" class="#{ class_name }" />}
        else
          emoji_code
        end
      end
    end

  end
end

# extend to String class
class String

  def emojify
    RailsEmoji.render(self)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails_emoji-1.4 lib/rails_emoji/render.rb
rails_emoji-1.3 lib/rails_emoji/render.rb