gemojione-2.2.1/ 0000755 0000041 0000041 00000000000 12672233321 013521 5 ustar www-data www-data gemojione-2.2.1/Rakefile 0000644 0000041 0000041 00000000260 12672233321 015164 0 ustar www-data www-data require "bundler/gem_tasks"
require 'rake/testtask'
Rake::TestTask.new do |t|
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
end
task :default => :test
gemojione-2.2.1/Gemfile 0000644 0000041 0000041 00000000136 12672233321 015014 0 ustar www-data www-data source 'https://rubygems.org'
# Specify your gem's dependencies in gemojione.gemspec
gemspec
gemojione-2.2.1/LICENSE.txt 0000644 0000041 0000041 00000002206 12672233321 015344 0 ustar www-data www-data Copyright (c) 2013 Jonathan Wiesel
Original work by Steve Klabnik on [emoji gem](https://github.com/steveklabnik/emoji)
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
gemojione-2.2.1/.travis.yml 0000644 0000041 0000041 00000000274 12672233321 015635 0 ustar www-data www-data language: ruby
sudo: false
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- jruby-19mode
- rbx-2
- ruby-head
- jruby-head
matrix:
allow_failures:
- rvm: ruby-head
- rvm: jruby-head
gemojione-2.2.1/lib/ 0000755 0000041 0000041 00000000000 12672233321 014267 5 ustar www-data www-data gemojione-2.2.1/lib/gemojione.rb 0000644 0000041 0000041 00000003121 12672233321 016565 0 ustar www-data www-data require 'gemojione/version'
require 'json'
# Optionally load EscapeUtils if it's available
begin
require 'escape_utils'
rescue LoadError
require 'cgi'
end
require 'gemojione/index'
require "gemojione/railtie" if defined?(Rails)
module Gemojione
@asset_host = nil
@asset_path = nil
@escaper = defined?(EscapeUtils) ? EscapeUtils : CGI
def self.asset_host
@asset_host || 'http://localhost:3000'
end
def self.asset_host=(host)
@asset_host = host
end
def self.asset_path
@asset_path || '/'
end
def self.asset_path=(path)
@asset_path = path
end
def self.image_url_for_name(name)
emoji = index.find_by_name(name)
"#{asset_host}#{ File.join(asset_path, emoji['unicode']) }.png"
end
def self.image_url_for_unicode_moji(moji)
emoji = index.find_by_moji(moji)
image_url_for_name(emoji['name'])
end
def self.replace_unicode_moji_with_images(string)
return string unless string
unless string.match(index.unicode_moji_regex)
return safe_string(string)
end
safe_string = safe_string(string.dup)
safe_string.gsub!(index.unicode_moji_regex) do |moji|
%Q{
}
end
safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)
safe_string
end
def self.safe_string(string)
if string.respond_to?(:html_safe?) && string.html_safe?
string
else
escape_html(string)
end
end
def self.escape_html(string)
@escaper.escape_html(string)
end
def self.index
@index ||= Index.new
end
end
gemojione-2.2.1/lib/gemojione/ 0000755 0000041 0000041 00000000000 12672233321 016243 5 ustar www-data www-data gemojione-2.2.1/lib/gemojione/string_ext.rb 0000644 0000041 0000041 00000000442 12672233321 020756 0 ustar www-data www-data class String
def with_emoji_images
Gemojione.replace_unicode_moji_with_images(self)
end
def image_url
Gemojione.image_url_for_name(self.emoji_data['name'])
end
def emoji_data
index = Gemojione.index
index.find_by_moji(self) || index.find_by_name(self)
end
end
gemojione-2.2.1/lib/gemojione/index.rb 0000644 0000041 0000041 00000002111 12672233321 017672 0 ustar www-data www-data module Gemojione
class Index
def initialize(emoji_list=nil)
emoji_list ||= begin
emoji_json = File.read(File.absolute_path(File.dirname(__FILE__) + '/../../config/index.json'))
JSON.parse(emoji_json)
end
@emoji_by_name = {}
@emoji_by_moji = {}
emoji_list.each do |key, emoji_hash|
emoji_hash["description"] = emoji_hash["name"]
emoji_hash["name"] = key
@emoji_by_name[key] = emoji_hash if key
emoji_hash["aliases"].each do |emoji_alias|
aliased = emoji_alias.tr(':','')
@emoji_by_name[aliased] = emoji_hash if aliased
end
moji = emoji_hash['moji']
@emoji_by_moji[moji] = emoji_hash if moji
end
@emoji_moji_regex = /#{@emoji_by_moji.keys.join('|')}/
end
def find_by_moji(moji)
@emoji_by_moji[moji]
end
def find_by_name(name)
@emoji_by_name[name]
end
def unicode_moji_regex
@emoji_moji_regex
end
def images_path
File.expand_path("../../assets/images", File.dirname(__FILE__))
end
end
end
gemojione-2.2.1/lib/gemojione/version.rb 0000644 0000041 0000041 00000000051 12672233321 020251 0 ustar www-data www-data module Gemojione
VERSION = "2.2.1"
end
gemojione-2.2.1/lib/gemojione/tasks/ 0000755 0000041 0000041 00000000000 12672233321 017370 5 ustar www-data www-data gemojione-2.2.1/lib/gemojione/tasks/install.rake 0000644 0000041 0000041 00000001500 12672233321 021676 0 ustar www-data www-data namespace :gemojione do
desc "Install Emoji Image Assets"
task :install_assets do
target_dir = ENV['TARGET'] ||= File.join(Rails.root, 'app/assets/images/emoji')
source_dir = File.absolute_path(File.dirname(__FILE__) + '/../../../assets/images')
puts "===================================================================="
puts "= emoji image assets install"
puts "= Target: #{target_dir}"
puts "= Source: #{source_dir}"
puts "===================================================================="
unless File.exists?(target_dir)
puts "- Creating #{target_dir}..."
FileUtils.mkdir_p(target_dir)
end
puts "- Installing assets..."
Dir.glob("#{source_dir}/*").entries.each do |asset|
FileUtils.cp_r(asset, target_dir, verbose: true, preserve: false)
end
end
end
gemojione-2.2.1/lib/gemojione/railtie.rb 0000644 0000041 0000041 00000000546 12672233321 020226 0 ustar www-data www-data require 'gemojione'
require 'rails'
module Gemojione
class Railtie < Rails::Railtie
initializer "gemojione.defaults" do
Gemojione.asset_host = ActionController::Base.asset_host
Gemojione.asset_path = '/assets/emoji'
end
rake_tasks do
load File.absolute_path(File.dirname(__FILE__) + '/tasks/install.rake')
end
end
end
gemojione-2.2.1/test/ 0000755 0000041 0000041 00000000000 12672233321 014500 5 ustar www-data www-data gemojione-2.2.1/test/index_test.rb 0000644 0000041 0000041 00000001332 12672233321 017172 0 ustar www-data www-data # encoding: UTF-8
require File.absolute_path File.dirname(__FILE__) + '/test_helper'
describe Gemojione::Index do
let(:index) { Gemojione::Index.new }
describe "find_by_name" do
it 'should find cyclone emoji' do
assert index.find_by_name('cyclone')
end
end
describe "find_by_moji" do
it 'should find cyclone emoji by moji character' do
assert index.find_by_moji('🌀')
end
end
describe "unicode_moji_regex" do
it "should return complex moji regex" do
regex = index.unicode_moji_regex
assert "🌀".match(regex)
end
end
describe "images_path" do
it "returns a valid path" do
path = index.images_path
assert Dir.exist?(path)
end
end
end
gemojione-2.2.1/test/test_helper.rb 0000644 0000041 0000041 00000000165 12672233321 017345 0 ustar www-data www-data require 'rubygems'
require 'bundler/setup'
require 'gemojione'
require 'minitest/autorun'
require 'minitest/pride'
gemojione-2.2.1/test/string_ext_test.rb 0000644 0000041 0000041 00000001542 12672233321 020254 0 ustar www-data www-data # encoding: UTF-8
require 'gemojione/string_ext'
describe String, 'with Emoji extensions' do
describe '#with_emoji_images' do
it 'should replace unicode moji with an img tag' do
base_string = "I ❤ Emoji"
replaced_string = base_string.with_emoji_images
assert_equal "I
Emoji", replaced_string
end
end
describe '#image_url' do
it 'should generate image_url' do
assert_equal 'http://localhost:3000/1F300.png', '🌀'.image_url
assert_equal 'http://localhost:3000/1F300.png', 'cyclone'.image_url
end
end
describe '#emoji_data' do
it 'should find data for a name or a moji' do
data_from_moji = '❤'.emoji_data
data_from_string = 'heart'.emoji_data
assert_equal data_from_moji, data_from_string
end
end
end
gemojione-2.2.1/test/gemojione_test.rb 0000644 0000041 0000041 00000010175 12672233321 020044 0 ustar www-data www-data # encoding: UTF-8
require File.absolute_path File.dirname(__FILE__) + '/test_helper'
describe Gemojione do
describe "image_url_for_name" do
it 'should generate url' do
assert_equal 'http://localhost:3000/1F300.png', Gemojione.image_url_for_name('cyclone')
end
it 'should generate url' do
assert_equal 'http://localhost:3000/1F44D.png', Gemojione.image_url_for_name('+1')
end
end
describe "image_url_for_unicode_moji" do
it 'should generate url' do
assert_equal 'http://localhost:3000/1F300.png', Gemojione.image_url_for_unicode_moji('🌀')
end
end
describe "asset_host" do
it 'should default to localhost' do
assert_equal 'http://localhost:3000', Gemojione.asset_host
end
it 'should be configurable' do
with_emoji_config(:asset_host, 'emoji') do
assert_equal 'emoji', Gemojione.asset_host
end
end
end
describe "asset_path" do
it 'should default to /' do
assert_equal '/', Gemojione.asset_path
end
it 'should be configurable' do
with_emoji_config(:asset_path, '/emoji') do
assert_equal '/emoji', Gemojione.asset_path
end
end
end
describe "replace_unicode_moji_with_images" do
it 'should return original string without emoji' do
assert_equal "foo", Gemojione.replace_unicode_moji_with_images('foo')
end
it 'should escape html in non html_safe aware strings' do
replaced_string = Gemojione.replace_unicode_moji_with_images('❤