emoji 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85b117fc2248c58f4b7c1b271121cefcc58ecd7a
4
- data.tar.gz: 1b78b3e8d1d096e644110f03d41fdaf64d6ddf50
3
+ metadata.gz: 51aa082de115428a1e87faf901e48086d154ce29
4
+ data.tar.gz: 8be5856bfe94ea3767e65155c61e706c463c5529
5
5
  SHA512:
6
- metadata.gz: 10e36d5aab8e0a94fc2f28cf9ab8b0b59786127089dd6c86f876a10821480a9be6f0103a9ecc1cc15357097cfaed232c0a945d3194099737b5f1258a3b092a5e
7
- data.tar.gz: 0ae62138344caec64c023abfd93731e31202bfbc4ff0d3df241e04c6fc21fe02715403c2d657bd7262587667dc80e3173886a05577dad024c0c795b32a623211
6
+ metadata.gz: 277599578461ed7f39f8904b25ac513f029368cfeeb07e761dd77f690be86b8042281cad3e0c190e637bd5d20c1d20c5b24537b197fe3e18e49af9c2f020fc43
7
+ data.tar.gz: ece245951377000b90ec40ea13f5cd01790219c218795a1de44a9889feb32bd45e0d7836f860f923868ef84c8bf63c68b9e8dfe5142723c458de6e344db457d4
@@ -1,5 +1,11 @@
1
1
  # Releases / Changes
2
2
 
3
+ ## 1.0.7
4
+
5
+ * Adds `Emoji.replace_named_moji_with_unicode()` for Markdown
6
+ * Use configured Rails asset `path_prefix` for `Emoji.asset_path` prefix
7
+
8
+
3
9
  ## 1.0.6
4
10
 
5
11
  * Adds `Emoji.replace_unicode_moji_with_name()` for Markdown
@@ -36,7 +36,7 @@ module Emoji
36
36
  return '' unless asset_host_spec.size >= 1
37
37
 
38
38
  # Special Case for 'hostname:port' style URIs, not parse properly by URI.parse
39
- if asset_host_spec.match(/^[^:]+:\d+$/)
39
+ if asset_host_spec.match(/^[^:\/]+:\d+$/)
40
40
  components = asset_host_spec.split(':')
41
41
  scheme_string = 'http://'
42
42
  hostname = components.first
@@ -132,6 +132,24 @@ module Emoji
132
132
  safe_string
133
133
  end
134
134
 
135
+ def self.replace_named_moji_with_unicode(string)
136
+ return string unless string
137
+ unless string.match(index.named_moji_regex)
138
+ return safe_string(string)
139
+ end
140
+
141
+ safe_string = safe_string(string.dup)
142
+ safe_string.gsub!(index.named_moji_regex) do |name_exp|
143
+ name = name_exp[1..-2] # Convert :heart: to heart, strips first/last chars
144
+ emoji = index.find_by_name(name)
145
+
146
+ emoji['moji']
147
+ end
148
+ safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)
149
+
150
+ safe_string
151
+ end
152
+
135
153
  def self.replace_unicode_moji_with_name(string)
136
154
  return string unless string
137
155
  unless string.match(index.unicode_moji_regex)
@@ -141,7 +159,7 @@ module Emoji
141
159
  safe_string = safe_string(string.dup)
142
160
  safe_string.gsub!(index.unicode_moji_regex) do |moji|
143
161
  emoji = index.find_by_moji(moji)
144
- %Q{:#{emoji['name']}:}
162
+ ":#{emoji['name']}:"
145
163
  end
146
164
  safe_string = safe_string.html_safe if safe_string.respond_to?(:html_safe)
147
165
 
@@ -4,7 +4,7 @@ module Emoji
4
4
  class Index
5
5
  extend Forwardable
6
6
 
7
- attr_reader :unicode_moji_regex
7
+ attr_reader :unicode_moji_regex, :named_moji_regex
8
8
 
9
9
  def_delegator :@emoji_by_moji, :[], :find_by_moji
10
10
  def_delegator :@emoji_by_name, :[], :find_by_name
@@ -31,7 +31,9 @@ module Emoji
31
31
  @emoji_by_unicode[unicode] = emoji_hash if unicode
32
32
  end
33
33
 
34
- @unicode_moji_regex = /#{@emoji_by_moji.keys.join('|')}/
34
+ annotated_name_strings = @emoji_by_name.keys.map{|name| ":#{name}:" }
35
+ @named_moji_regex = /#{ annotated_name_strings.join('|') }/
36
+ @unicode_moji_regex = /#{ @emoji_by_moji.keys.join('|') }/
35
37
  end
36
38
  end
37
39
  end
@@ -1,11 +1,13 @@
1
1
  require 'emoji'
2
2
  require 'rails'
3
+ require 'sprockets'
3
4
 
4
5
  module Emoji
5
6
  class Railtie < Rails::Railtie
6
7
  initializer "emoji.defaults" do
7
8
  Emoji.asset_host = ActionController::Base.asset_host
8
- Emoji.asset_path = '/assets/emoji'
9
+ asset_prefix = Rails.application.config.assets.prefix rescue '/assets'
10
+ Emoji.asset_path = File.join(asset_prefix, '/emoji')
9
11
  Emoji.use_plaintext_alt_tags = false
10
12
  end
11
13
 
@@ -1,3 +1,3 @@
1
1
  module Emoji
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
@@ -50,6 +50,12 @@ describe Emoji do
50
50
  end
51
51
  end
52
52
 
53
+ it 'should allow protocol relative UR with port' do
54
+ with_emoji_config(:asset_host, '//emoji:3000') do
55
+ assert_equal '//emoji:3000', Emoji.asset_host
56
+ end
57
+ end
58
+
53
59
  it 'should respect protocol scheme' do
54
60
  with_emoji_config(:asset_host, 'https://emoji') do
55
61
  assert_equal 'https://emoji', Emoji.asset_host
@@ -114,6 +120,22 @@ describe Emoji do
114
120
  end
115
121
  end
116
122
 
123
+ describe 'replace_named_moji_with_unicode' do
124
+ it 'should return the original string without emoji' do
125
+ assert_equal "foo", Emoji.replace_named_moji_with_unicode('foo')
126
+ end
127
+
128
+ it 'should replace the markdown-esque emoji name with its unicode equivalent' do
129
+ base_string = "I :heart: Emoji"
130
+ assert_equal "I ❤ Emoji", Emoji.replace_named_moji_with_unicode(base_string)
131
+ end
132
+
133
+ it 'should be able to replace multiple emoji in one go' do
134
+ base_string = "I :heart: :invalid: Emoji"
135
+ assert_equal "I ❤ :invalid: Emoji", Emoji.replace_named_moji_with_unicode(base_string)
136
+ end
137
+ end
138
+
117
139
  describe "replace_unicode_moji_with_images" do
118
140
  it 'should return original string without emoji' do
119
141
  assert_equal "foo", Emoji.replace_unicode_moji_with_images('foo')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Klabnik
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-01 00:00:00.000000000 Z
12
+ date: 2016-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -605,7 +605,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
605
605
  version: '0'
606
606
  requirements: []
607
607
  rubyforge_project:
608
- rubygems_version: 2.0.3
608
+ rubygems_version: 2.4.8
609
609
  signing_key:
610
610
  specification_version: 4
611
611
  summary: 'A Ruby gem. For emoji. For everyone. :heart:'