gemojione-2.2.1/0000755000004100000410000000000012672233321013521 5ustar www-datawww-datagemojione-2.2.1/Rakefile0000644000004100000410000000026012672233321015164 0ustar www-datawww-datarequire "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/Gemfile0000644000004100000410000000013612672233321015014 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in gemojione.gemspec gemspec gemojione-2.2.1/LICENSE.txt0000644000004100000410000000220612672233321015344 0ustar www-datawww-dataCopyright (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.yml0000644000004100000410000000027412672233321015635 0ustar www-datawww-datalanguage: 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/0000755000004100000410000000000012672233321014267 5ustar www-datawww-datagemojione-2.2.1/lib/gemojione.rb0000644000004100000410000000312112672233321016565 0ustar www-datawww-datarequire '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{#{moji}} 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/0000755000004100000410000000000012672233321016243 5ustar www-datawww-datagemojione-2.2.1/lib/gemojione/string_ext.rb0000644000004100000410000000044212672233321020756 0ustar www-datawww-dataclass 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.rb0000644000004100000410000000211112672233321017672 0ustar www-datawww-datamodule 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.rb0000644000004100000410000000005112672233321020251 0ustar www-datawww-datamodule Gemojione VERSION = "2.2.1" end gemojione-2.2.1/lib/gemojione/tasks/0000755000004100000410000000000012672233321017370 5ustar www-datawww-datagemojione-2.2.1/lib/gemojione/tasks/install.rake0000644000004100000410000000150012672233321021676 0ustar www-datawww-datanamespace :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.rb0000644000004100000410000000054612672233321020226 0ustar www-datawww-datarequire '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/0000755000004100000410000000000012672233321014500 5ustar www-datawww-datagemojione-2.2.1/test/index_test.rb0000644000004100000410000000133212672233321017172 0ustar www-datawww-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.rb0000644000004100000410000000016512672233321017345 0ustar www-datawww-datarequire 'rubygems' require 'bundler/setup' require 'gemojione' require 'minitest/autorun' require 'minitest/pride' gemojione-2.2.1/test/string_ext_test.rb0000644000004100000410000000154212672233321020254 0ustar www-datawww-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.rb0000644000004100000410000001017512672233321020044 0ustar www-datawww-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('❤