gemojione-3.3.0/0000755000004100000410000000000013151107717013524 5ustar www-datawww-datagemojione-3.3.0/Rakefile0000644000004100000410000000263313151107717015175 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 task :resprite do require 'sprite_factory' require 'rmagick' base_selector = 'emojione' separator = '-' SpriteFactory.run!('assets/png', layout: 'packed', selector: 'emojione', nocomments: true) do |images| rules = [".#{base_selector} { text-indent: -9999em;image-rendering: optimizeQuality;font-size: inherit;height: 64px;width: 64px;top: -3px;position: relative;display: inline-block;margin: 0 .15em;line-height: normal;vertical-align: middle;background-image: url(image-path('emojione.sprites.png'));background-repeat: no-repeat}"] images.each_pair do |key, val| cssx = "#{val[:cssx] == 0 ? 0 : '-'+val[:cssx].to_s+'px'}" cssy = "#{val[:cssy] == 0 ? 0 : '-'+val[:cssy].to_s+'px'}" rules << ".#{base_selector}#{separator}#{key.to_s.downcase}{background-position: #{cssx} #{cssy};}" end rules.join("\n") end FileUtils.mv('assets/png.css', "assets/sprites/emojione.sprites.scss", verbose: true) #Optimize png sprite if system("which pngcrush") system('pngcrush', '-q', '-rem alla', '-reduce', '-brute', 'assets/png.png', 'assets/sprites/emojione.sprites.png') FileUtils.rm "assets/png.png" else FileUtils.mv('assets/png.png', "assets/sprites/emojione.sprites.png", verbose: true) end endgemojione-3.3.0/Gemfile0000644000004100000410000000013513151107717015016 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in gemojione.gemspec gemspecgemojione-3.3.0/.ruby-version0000644000004100000410000000000513151107717016164 0ustar www-datawww-data2.3.1gemojione-3.3.0/LICENSE.txt0000644000004100000410000000220613151107717015347 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-3.3.0/.travis.yml0000644000004100000410000000056313151107717015641 0ustar www-datawww-datalanguage: ruby sudo: false rvm: - 2.0.0 - 2.1.0 - 2.2.5 - 2.3.1 - 2.4.0 - rbx-2 - ruby-head - jruby-head matrix: allow_failures: - rvm: ruby-head - rvm: jruby-head - rvm: rbx-2 addons: code_climate: repo_token: 418bd243b301fd0d29e8762626cc63ee2b3d2c41124c2d880e0e00d59057f639 after_success: - bundle exec codeclimate-test-reporter gemojione-3.3.0/lib/0000755000004100000410000000000013151107717014272 5ustar www-datawww-datagemojione-3.3.0/lib/gemojione.rb0000644000004100000410000000712213151107717016575 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::Railtie) module Gemojione @asset_host = nil @asset_path = nil @default_size = nil @use_svg = false @use_sprite = false @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.default_size @default_size end def self.default_size=(size) @default_size = size end def self.use_svg @use_svg end def self.use_svg=(useit) @use_svg = useit end def self.use_sprite @use_sprite end def self.use_sprite=(useit) @use_sprite = useit end def self.image_url_for_name(name) emoji = index.find_by_name(name) "#{asset_host}#{ File.join(asset_path, emoji['unicode']) }.#{ use_svg ? 'svg' : '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.image_tag_for_moji(moji) if use_sprite emoji = index.find_by_moji(moji) %Q{#{ moji }} else %Q{#{moji}} end 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| Gemojione.image_tag_for_moji(moji) end safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe) safe_string end def self.replace_named_moji_with_images(string) return string unless string unless string.match(index.shortname_moji_regex) return safe_string(string) end safe_string = safe_string(string.dup) safe_string.gsub!(index.shortname_moji_regex) do |code| name = code.tr(':','') moji = index.find_by_name(name)['moji'] Gemojione.image_tag_for_moji(moji) end safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe) safe_string end def self.replace_ascii_moji_with_images(string) return string unless string unless string.match(index.ascii_moji_regex) return safe_string(string) end string.gsub!(index.ascii_moji_regex) do |code| moji = index.find_by_ascii(code)['moji'] Gemojione.image_tag_for_moji(moji) end unless string.respond_to?(:html_safe?) && string.html_safe? safe_string = CGI::unescapeElement(CGI.escape_html(string), %w[span img]) 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 def self.images_path File.expand_path("../assets/#{ use_svg ? 'svg' : 'png' }", File.dirname(__FILE__)) end def self.sprites_path File.expand_path("../assets/sprites", File.dirname(__FILE__)) end end gemojione-3.3.0/lib/gemojione/0000755000004100000410000000000013151107717016246 5ustar www-datawww-datagemojione-3.3.0/lib/gemojione/string_ext.rb0000644000004100000410000000056313151107717020765 0ustar www-datawww-dataclass String def with_emoji_images Gemojione.replace_unicode_moji_with_images(self) end def with_emoji_names Gemojione.replace_named_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-3.3.0/lib/gemojione/index.rb0000644000004100000410000000457413151107717017714 0ustar www-datawww-datamodule Gemojione class Index attr_reader :all 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_by_ascii = {} @emoji_by_code = {} @emoji_by_keyword = {} @emoji_by_category = {} @all = emoji_list 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 @emoji_by_code[emoji_alias] = emoji_hash if aliased end emoji_hash['aliases_ascii'].each do |emoji_ascii| @emoji_by_ascii[emoji_ascii] = emoji_hash if emoji_ascii end code = emoji_hash['shortname'] @emoji_by_code[code] = emoji_hash if code moji = emoji_hash['moji'] @emoji_by_moji[moji] = emoji_hash if moji emoji_hash['keywords'].each do |emoji_keyword| @emoji_by_keyword[emoji_keyword] ||= [] @emoji_by_keyword[emoji_keyword] << emoji_hash end category = emoji_hash['category'] if category @emoji_by_category[category] ||= {} @emoji_by_category[category][key] = emoji_hash end end @emoji_code_regex = /#{@emoji_by_code.keys.map{|ec| Regexp.escape(ec)}.join('|')}/ @emoji_moji_regex = /#{@emoji_by_moji.keys.map{|ec| Regexp.escape(ec)}.join('|')}/ @emoji_ascii_regex = /#{@emoji_by_ascii.keys.map{|ec| Regexp.escape(ec)}.join('|')}/ end def find_by_moji(moji) @emoji_by_moji[moji] end def find_by_name(name) @emoji_by_name[name] end def find_by_ascii(ascii) @emoji_by_ascii[ascii] end def find_by_keyword(keyword) @emoji_by_keyword[keyword] end def find_by_category(category) @emoji_by_category[category] end def find_by_shortname(shortname) @emoji_by_code[shortname] end def unicode_moji_regex @emoji_moji_regex end def shortname_moji_regex @emoji_code_regex end def ascii_moji_regex @emoji_ascii_regex end end end gemojione-3.3.0/lib/gemojione/version.rb0000644000004100000410000000005113151107717020254 0ustar www-datawww-datamodule Gemojione VERSION = "3.3.0" end gemojione-3.3.0/lib/gemojione/tasks/0000755000004100000410000000000013151107717017373 5ustar www-datawww-datagemojione-3.3.0/lib/gemojione/tasks/install.rake0000644000004100000410000000147213151107717021711 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') 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-3.3.0/lib/gemojione/railtie.rb0000644000004100000410000000054613151107717020231 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-3.3.0/test/0000755000004100000410000000000013151107717014503 5ustar www-datawww-datagemojione-3.3.0/test/index_test.rb0000644000004100000410000000274313151107717017204 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 "all" do it "return emoji_list" do assert index.all, index.instance_variable_get(:@emoji_by_name) end end 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 "find_by_keyword" do it 'should find all emoji with glasses keyword' do glasses_emoji = index.find_by_keyword('glasses') assert glasses_emoji assert glasses_emoji.length == 5 glasses_emoji.each do |emoji_hash| assert_includes(emoji_hash['keywords'], 'glasses') end end end describe 'find by ascii' do it 'returns the heart emoji' do assert index.find_by_ascii('<3')['unicode'] == "2764" end end describe 'find by shortname' do it 'returns the heart emoji' do assert index.find_by_shortname(':heart:')['unicode'] == '2764' end end describe 'find by category' do it 'should find people category by category name' do assert index.find_by_category('people') end end describe "unicode_moji_regex" do it "should return complex moji regex" do regex = index.unicode_moji_regex assert "๐ŸŒ€".match(regex) end end end gemojione-3.3.0/test/test_helper.rb0000644000004100000410000000023213151107717017343 0ustar www-datawww-datarequire 'simplecov' SimpleCov.start require 'rubygems' require 'bundler/setup' require 'gemojione' require 'minitest/autorun' require 'minitest/pride' gemojione-3.3.0/test/string_ext_test.rb0000644000004100000410000000223313151107717020255 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 '#with_emoji_names' do it 'should replace named moji with an img tag' do base_string = "I :heart: Emoji" replaced_string = base_string.with_emoji_names 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-3.3.0/test/gemojione_test.rb0000644000004100000410000002573213151107717020054 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 it 'should generate url' do with_emoji_config(:use_svg, true) do assert_equal 'http://localhost:3000/1F44D.svg', Gemojione.image_url_for_name('+1') end 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 'default size' do it 'should default to nil' do assert_equal nil, Gemojione.default_size end it 'should be configurable' do with_emoji_config(:default_size, '32px') do assert_equal '32px', Gemojione.default_size end end end describe 'image_tag_for_moji' do it 'should generate a clean img tag if default_size undefined' do assert_equal '๐ŸŒ€', Gemojione.image_tag_for_moji('๐ŸŒ€') end it 'should generate a img tag with style tag if default_size is defined' do Gemojione.default_size='42px' assert_equal '๐ŸŒ€', Gemojione.image_tag_for_moji('๐ŸŒ€') Gemojione.default_size=nil end it 'should generate spritesheet tag' do with_emoji_config(:use_sprite, true) do assert_equal "๐ŸŒ€", Gemojione.image_tag_for_moji('๐ŸŒ€') 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('โค