jekyll-emoji 0.1.5 → 0.1.6

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: fa05cb9d3d721a154defea59300d2091a943aace
4
- data.tar.gz: 5cdfae6341a486064fa2ab6abcdb05d3a6501d1d
3
+ metadata.gz: 8fe913ad1a9849a6e354d27643eec013aef80fac
4
+ data.tar.gz: c47e5653f01a0b650726fc6484354e60125b8782
5
5
  SHA512:
6
- metadata.gz: 5279d5dd2b413b01fda17517d0b5a2402d29b99a2b444487d888bddb4fb1c9fa01b2689dfa00c8363283442d1096cd9ba41e22c7b7703b54835106444dcc58b2
7
- data.tar.gz: 680a167683ebec39347fc7fe10d50f936ecff530b9caf00bb55a39538b0d7577f1d26fd24898e8c83243135766ebb0bf0bfbe225dc6caa0592c7e3043e21aa56
6
+ metadata.gz: 9b0b278e3279d9e0177ea0a1c3cf41246203128e73c72a924df4653b96afe1f55a3bc3f5f3738848ecf823398298031eead44406a1180e9af8a378181b144fc1
7
+ data.tar.gz: 4b70b621ae16fc7c56b8759c793f75e1e3fabc1904be9314f77fd7d156d76ff57c69003fb245c9d185a0dfb0b55e2689454478a099310190d15eaa366574cbdb
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.2
4
+ - 1.9.3
4
5
  before_install: gem install bundler -v 1.10.5
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Jekyll::Emoji
2
2
 
3
+ [![Build Status](https://travis-ci.org/omninonsense/jekyll-emoji.svg?branch=master)](https://travis-ci.org/omninonsense/jekyll-emoji)
4
+ [![Gem Version](https://badge.fury.io/rb/jekyll-emoji.svg)](http://badge.fury.io/rb/jekyll-emoji)
5
+ [![Code Climate](https://codeclimate.com/github/omninonsense/jekyll-emoji/badges/gpa.svg)](https://codeclimate.com/github/omninonsense/jekyll-emoji)
6
+ [![Inline docs](http://inch-ci.org/github/omninonsense/jekyll-emoji.svg?branch=master)](http://inch-ci.org/github/omninonsense/jekyll-emoji)
7
+
8
+
3
9
  ## Installation
4
10
 
5
11
  Add this line to your application's Gemfile:
@@ -30,7 +36,9 @@ emoji:
30
36
 
31
37
  The following formats are supported: `html`, `unicode`, `emojione-png`, and ` emojione-svg`.
32
38
 
33
- For a list of all available shortnames and asciimojis (I hope I coined this, so I can be cool) you can consult the [emoji.codes](http://emoji.codes), [Emoji One](http://emojione.com), and [Emoji Cheat Sheet](http://www.emoji-cheat-sheet.com/) websites.
39
+ For a list of all available shortnames and asciimojis (I hope I coined this, so I can be cool) you can consult the [emoji.codes](http://emoji.codes),
40
+ [Emoji One](http://emojione.com), and
41
+ [Emoji Cheat Sheet](http://www.emoji-cheat-sheet.com/) websites.
34
42
 
35
43
  Elements matching the following (CSS selector) will be excluded from the emojification:
36
44
 
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.description = %q{
16
16
  A plug-n-play Jekyll plugin to enable emoji support in your site.
17
17
 
18
- See documentation for more inforamtion on how to use it.
18
+ See documentation for more information on how to use it.
19
19
  }
20
20
  spec.homepage = "https://github.com/omninonsense/jekyll-emoji"
21
21
  spec.license = "MIT"
@@ -58,8 +58,8 @@ module Jekyll
58
58
  # @param [Hash] conf
59
59
  #
60
60
  def initialize(conf = {'emoji' => DEFAULTS})
61
- @@site_conf = conf
62
- configure(@@site_conf)
61
+ @initialized = false
62
+ configure(@initial_conf = conf)
63
63
 
64
64
  validate_format
65
65
 
@@ -71,8 +71,8 @@ module Jekyll
71
71
 
72
72
  load_emoji_data
73
73
  build_emoji_regexp
74
-
75
- @encoding_regexp = Regexp.new (@encoding_map.keys.map{|k| Regexp.quote(k) }).join('|')
74
+ build_encoding_regexp
75
+ @initialized = true
76
76
  end
77
77
 
78
78
  ##
@@ -106,29 +106,121 @@ module Jekyll
106
106
  data = load_emoji_json(path)
107
107
 
108
108
  data.each do |v|
109
- codepoints = v['unicode'].split('-')
109
+ codepoints = v['unicode']
110
110
  unicode = codepoints_to_unicode(codepoints)
111
111
 
112
- @shortname_aliases << v['shortname']
113
- @emoji_map[v['shortname']] = v['unicode']
114
-
115
- v['aliases'].each do |emoji_alias|
116
- @shortname_aliases << emoji_alias
117
- @emoji_map[emoji_alias] = v['unicode']
118
- end
112
+ add_shortname_alias(v['shortname'], codepoints)
113
+ v['aliases'].each {|a| add_shortname_alias(a, codepoints) }
114
+ v['aliases_ascii'].each {|a| add_ascii_alias(a, codepoints) }
119
115
 
120
- v['aliases_ascii'].each do |emoji_alias|
121
- @ascii_aliases << emoji_alias
122
- @emoji_map[emoji_alias] = v['unicode']
123
- end
124
-
125
- @encoding_map[unicode] = codepoints.map{|cp| "&#x#{cp};" }.join
126
- @emoji_map[unicode] = v['unicode']
116
+ map_emoji(unicode, codepoints)
117
+ map_encoding(unicode, codepoints)
127
118
  end
128
119
 
129
120
  return nil
130
121
  end
131
122
 
123
+ ##
124
+ # Map an key to an HTML Entity string for faster encoding.
125
+ # The keys also serve as an array of strings used in the emoji regexp.
126
+ #
127
+ # - `k` is the unicode string
128
+ # - `v` is a dash(`-`)-delimited string of hex-formated codepoints
129
+ #
130
+ # @param [String] k
131
+ # @param [String] v
132
+ #
133
+ def map_encoding(k, v)
134
+ @encoding_map[k] = v.split('-').map{|cp| "&#x#{cp};" }.join
135
+
136
+ build_encoding_regexp if @initialized
137
+ end
138
+
139
+ ##
140
+ # Add an emoji to the map of all supported emojis.
141
+ # - `k` is an string corresponding to the emoji.
142
+ # - `v` is a dash(`-`)-delimited string of hex-formated codepoints.
143
+ #
144
+ # Returns true if the key was added, false if it already existed.
145
+ #
146
+ # @example
147
+ # conv = Converter.new()
148
+ # conv.map_emoji("\u{1F609}", '1F609')
149
+ #
150
+ #
151
+ # **NOTE**: Keys added through `map_encoding`, `map_emoji`,
152
+ # `add_shortname_alias`, and `add_ascii_alias` are all used in the same
153
+ # fashion during the lookup of the emoji. So, the code below would work,
154
+ # but the `:wink:` key would be added to the wrong lookup table, which
155
+ # would mean this key wouldn't be converted to an emoji if ASCII keys
156
+ # were disabled.
157
+ #
158
+ # This is a design choice added on purpose to allow addition of different
159
+ # types of emoji aliases, which aren't limited to `:shortcode` or the
160
+ # traditional smiley faces (`:)`, or `:P`), but also allowing the ability
161
+ # to toggle them off if needed.
162
+ #
163
+ # @example
164
+ # conv = Converter.new()
165
+ # conv.add_ascii_alias(":wink:", '1F609')
166
+ #
167
+ #
168
+ # @param [String] k
169
+ # @param [String] v
170
+ # @return [FalseClass|TrueClass]
171
+ #
172
+ def map_emoji(k, v)
173
+ return false if @emoji_map.has_key? k
174
+ @emoji_map[k] = v
175
+
176
+ build_emoji_regexp if @initialized
177
+ return true
178
+ end
179
+
180
+ ##
181
+ # Add a shortname alias for an emoji
182
+ # Used similarly to `map_emoji`, except that `k` is a string alias:
183
+ #
184
+ # Returns true if the key was added, false if it already existed.
185
+ #
186
+ # @example
187
+ # conv = Converter.new()
188
+ # conv.add_shortname_alias(":wink:", '1F609')
189
+ #
190
+ # @param [String] k
191
+ # @param [String] v
192
+ # @return [FalseClass|TrueClass]
193
+ #
194
+ def add_shortname_alias(emoji_alias, codepoints)
195
+ return false unless map_emoji(emoji_alias, codepoints)
196
+ @shortname_aliases << emoji_alias
197
+
198
+ build_emoji_regexp if @initialized
199
+ return true
200
+ end
201
+
202
+ ##
203
+ # Add an ASCII alias for an emoji
204
+ # Used similarly to `add_shortname_alias`.
205
+ #
206
+ # Returns true if the key was added, false if it already existed.
207
+ #
208
+ # @example
209
+ # conv = Converter.new()
210
+ # conv.add_shortname_alias(";-)", '1F609')
211
+ #
212
+ # @param [String] k
213
+ # @param [String] v
214
+ # @return [FalseClass|TrueClass]
215
+ #
216
+ def add_ascii_alias(emoji_alias, codepoints)
217
+ return false unless map_emoji(emoji_alias, codepoints)
218
+ @ascii_aliases << emoji_alias
219
+
220
+ build_emoji_regexp if @initialized
221
+ return true
222
+ end
223
+
132
224
  ##
133
225
  # Validates if desired format is supported. If it isn't supported
134
226
  # an exception is raised.
@@ -151,8 +243,8 @@ module Jekyll
151
243
  # @param [Hash|NilClass]
152
244
  # @return [Regexp]
153
245
  #
154
- def build_emoji_regexp(previous_conf = nil)
155
- return if previous_conf == @conf
246
+ def build_emoji_regexp(oc = nil)
247
+ return if oc['ascii'] == @conf['ascii'] && oc['shortname'] == @conf['shortname'] unless oc.nil?
156
248
 
157
249
  valid = @encoding_map.keys
158
250
  valid += @shortname_aliases if @conf['shortname']
@@ -161,6 +253,10 @@ module Jekyll
161
253
  @emoji_regexp = Regexp.union(valid)
162
254
  end
163
255
 
256
+ def build_encoding_regexp
257
+ @encoding_regexp = Regexp.new (@encoding_map.keys.map{|k| Regexp.quote(k) }).join('|')
258
+ end
259
+
164
260
  ##
165
261
  # Configure the internal state.
166
262
  #
@@ -183,7 +279,7 @@ module Jekyll
183
279
  #
184
280
  def reconfigure(h)
185
281
  previous_conf = @conf
186
- @conf = configure(@@site_conf).merge(h){|k, o, n| n.nil? ? o : n }
282
+ @conf = configure(@initial_conf).merge(h){|k, o, n| n.nil? ? o : n }
187
283
  validate_format
188
284
  build_emoji_regexp(previous_conf)
189
285
 
@@ -320,20 +416,6 @@ module Jekyll
320
416
  return [node_before, node_after ]
321
417
  end
322
418
 
323
- ##
324
- # Convert `unicode` string into a `"HHHH-HHHH"` string, which represents
325
- # the codepoints of the unicode string, but only if `unicode`
326
- # is a valid emoji.
327
- #
328
- #
329
- # @param [String] unicode
330
- # @return [String]
331
- #
332
- def unicode_to_codepoints(unicode)
333
- return unicode unless @encoding_map.key? unicode
334
- unicode.codepoints.map {|cp| cp.to_s 16}.join('-')
335
- end
336
-
337
419
  ##
338
420
  # Convert `codepoints` into an unicode string.
339
421
  #
@@ -355,7 +437,7 @@ module Jekyll
355
437
  # won't be emojified. Check the `BLACKLIST_*`` constants, or the docs for
356
438
  # more information.
357
439
  #
358
- # @param [String] convert
440
+ # @param [String] content
359
441
  # @return [String]
360
442
  #
361
443
  def convert(content)
@@ -371,16 +453,16 @@ module Jekyll
371
453
  return docstr
372
454
  end # convert
373
455
 
374
- def self.site_conf
375
- @@site_conf
456
+ def initial_conf
457
+ @initial_conf
376
458
  end
377
459
 
378
460
  private :load_emoji_json, :load_emoji_data
379
461
  private :validate_format
380
- private :build_emoji_regexp
462
+ private :build_emoji_regexp, :build_encoding_regexp
381
463
  private :process_node
382
464
  private :emojione_img_node, :split_to_nodes
383
- private :unicode_to_codepoints, :codepoints_to_unicode
465
+ private :codepoints_to_unicode
384
466
  end #Converter
385
467
  end #Emoji
386
468
  end
@@ -13,13 +13,15 @@ module Jekyll
13
13
  # @return [String]
14
14
  #
15
15
  def emojify(input, output_format = nil, ascii = nil, shortname = nil)
16
- @@emoji_converter ||= Converter.new(Converter.site_conf)
17
- @@emoji_converter.reconfigure('format' => output_format, 'ascii' => ascii, 'shortname' => shortname)
16
+ # Liquid/Jekyll seem to re-create the class where filters are included
17
+ @@__emoji_converter__ ||= Converter.new(@context.registers[:site].config)
18
+ @@__emoji_converter__.reconfigure('format' => output_format, 'ascii' => ascii, 'shortname' => shortname)
18
19
 
19
- output = @@emoji_converter.convert(input)
20
+ output = @@__emoji_converter__.convert(input)
20
21
 
22
+ # Revert back to old configuration
21
23
  # NOTE: This impacts performance in certain cases
22
- @@emoji_converter.reconfigure(Converter.site_conf)
24
+ @@__emoji_converter__.reconfigure(@@__emoji_converter__.initial_conf)
23
25
 
24
26
  return output
25
27
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Emoji
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
@@ -5,7 +5,7 @@ require_relative '../lib/jekyll-emoji'
5
5
  class TestConversion < MiniTest::Test
6
6
  def setup
7
7
  @converter = Jekyll::Emoji::Converter.new('emoji' => {
8
- 'format': 'html',
8
+ 'format' => 'html',
9
9
  'ascii' => true,
10
10
  'shortname' => true
11
11
  })
@@ -26,7 +26,7 @@ class TestConversion < MiniTest::Test
26
26
 
27
27
  def test_svg
28
28
  @converter.reconfigure 'format' => 'emojione-svg'
29
- img = %q{the number <img class="emojione" alt="3" src="https://cdn.jsdelivr.net/emojione/assets/svg/0033-20E3.svg" /> is smaller than 4}
29
+ img = %Q{the number <img class="emojione" alt="3\u{20E3}" src="https://cdn.jsdelivr.net/emojione/assets/svg/0033-20E3.svg" /> is smaller than 4}
30
30
  assert_equal img, @converter.convert("the number \u{0033}\u{20E3} is smaller than 4")
31
31
  assert_equal img, @converter.convert("the number :three: is smaller than 4")
32
32
  assert_equal "the number 3 is smaller than 4", @converter.convert("the number 3 is smaller than 4")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-emoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nino Miletich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -107,7 +107,7 @@ dependencies:
107
107
  - !ruby/object:Gem::Version
108
108
  version: 1.2.0
109
109
  description: "\n A plug-n-play Jekyll plugin to enable emoji support in your site.\n\n
110
- \ See documentation for more inforamtion on how to use it.\n "
110
+ \ See documentation for more information on how to use it.\n "
111
111
  email:
112
112
  - nino@miletich.me
113
113
  executables: []