Sha256: bb47137a62d555a3ee952e6bb50712970a2e37894372cdf27e7315dda0deda89

Contents?: true

Size: 782 Bytes

Versions: 1

Compression:

Stored size: 782 Bytes

Contents

module Emojify
  def self.included(klass)
    klass.extend ClassMethods
  end

  def emojify(text)
    text.gsub(/:(.*?):/) do |word| 
      "<image src='#{Emojify::Config.image_directory}/#{$1}.png' height='#{Emojify::Config.height}' width='#{Emojify::Config.width}'/>"
    end
  end

  module ClassMethods
    def emoji(options={})
      Config.image_directory  = options[:directory]
      Config.width            = options[:width]
      Config.height           = options[:height]
    end

  end

  class Config
    class << self
      attr_writer :image_directory, :width, :height
      def image_directory
        @image_directory || '/assets/emojis'
      end

      def width
        @width || 20
      end

      def height
        @height || 20
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
emojify-0.0.7 lib/emojify.rb