emoji_for_jekyll 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbbdbe32efad1804a61ace9d8424f7bb05f2bf51
4
- data.tar.gz: 00b6ac6894383459710ec55c5f579ae66799d63f
3
+ metadata.gz: 003ce4864712b5e090e7cfda26bfe8d66d4f3235
4
+ data.tar.gz: 2cb9c8cfe8d85981a8a2176260ce94da78fe48b5
5
5
  SHA512:
6
- metadata.gz: 5dcf80b3e41e0a52a9dc52d8ea6d80624e5385497d9808e11f2f1395e7d3483fb32bc6fab82c9d894d17950cac291a0955899139f1ad0a0fca1fd860d05f3be8
7
- data.tar.gz: b02a149651fd599d9074519a50a5ca6f0721d57f7aa1a29af896589d86dc94c0bcc38c5cb1525e84dff54c0b3fe443a660a09de787ba90873eec3d96e46aacc2
6
+ metadata.gz: 23a962166010f4ccbeeb4bac7959c0a1ebbf5f1544fb096c1a3e7614fa1036b42bcc808b6d437c09e831cfed8692646c1e17738a7e1b20ca2f3edf96db97c90b
7
+ data.tar.gz: 7b603b03cb8e70240180a7e4a7aaf4039978e85a0448c9eab88116cecdbee0e687bb8fd24bf170e8e74ead9484cd7335af9df92a4dd057141f2448a7f22cc0bd
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Yihang Ho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # Emoji for Jekyll
2
+ Seamlessly enable emoji for Jekyll.
3
+
4
+ ## Installation
5
+ 1. Install the `emoji_for_jekyll` gem:
6
+
7
+ gem install emoji_for_jekyll
8
+ 2. Add `emoji_for_jekyll` to the list of gems in `config.yml`:
9
+
10
+ ```yaml
11
+ gems: ["emoji_for_jekyll"]
12
+ ```
13
+ 3. See beautiful emoji!
14
+
15
+ _or_
16
+
17
+ 1. Copy `emoji_for_jekll.rb` and `emoji.json` into the `_plugins` directory
18
+
19
+
20
+ ## Options
21
+ ### Whitelist and blacklist
22
+ You can also whitelist or blacklist certain emojis. On the posts or pages that you want to whitelist or blacklist certain emojis, add `emoji-whitelist` or `emoji-blacklist` follow by a list of emojis __without__ the colons to the front matter. For example:
23
+
24
+ ```yaml
25
+ emoji-whitelist:
26
+ - bowtie
27
+ - blush
28
+ ```
29
+
30
+ or
31
+
32
+ ```yaml
33
+ emoji-blacklist:
34
+ - smile
35
+ ```
36
+
37
+ When both `emoji-whitelist` and `emoji-blacklist` are declared, the effect will be the same as when only the whitelist is declared.
38
+
39
+ ### Disabling
40
+ You may choose to disable this plugin for certain posts or pages by adding `emoji: false` to the front matter of these posts and pages.
41
+
42
+ If, for some reason, you want to disable this plugin for the entire site, you can either remove `emoji-for-jekyll.rb` from `_plugins`, or just add `emoji: false` to `_config.yml`.
43
+
44
+ ### Emojify front-matter items
45
+ If you need to emojify certain items in your front-matter, like `title` or `caption` that is needed for some templates, you can do so by setting `emoji-additional-keys` in `_config.yml`. This setting is optional and expects an array:
46
+
47
+ ```yaml
48
+ emoji-additional-keys: ["title", "caption"]
49
+ ```
50
+
51
+ ### Custom images
52
+ By default the images are sourced from GitHub CDN but should you want to use other images you can by choosing a directory with the setting `emoji-images-path` in `_config.yml`. For example: `emoji-images-path: 'img/emoji'`
53
+
54
+ Images copied into this directory will be added the whitelist. E.g.: `custom.png` would whitelist `:custom:`. Any images with the same name as the emoji list will overwrite the default GitHub emoji image.
55
+
56
+ ## Updating Emoji for Jekyll
57
+ Updating Emoji for Jekyll is very easy:
58
+
59
+ ```
60
+ gem update emoji_for_jekyll
61
+ ```
File without changes
@@ -1,65 +1,101 @@
1
1
  require 'json'
2
2
 
3
3
  module EmojiForJekyll
4
- class EmojiGenerator < Jekyll::Generator
5
- def generate(site)
6
- if site.config.has_key?("emoji") and !site.config["emoji"]
7
- return
8
- end
9
-
10
- if site.config.has_key?("emoji-additional-keys")
11
- additional_keys = site.config["emoji-additional-keys"]
12
- else
13
- additional_keys = []
14
- end
15
-
16
- get_master_whitelist
17
-
18
- site.pages.each { |p| substitute(p, additional_keys) }
19
-
20
- site.posts.each { |p| substitute(p, additional_keys) }
21
- end
22
-
23
- private
24
- def get_master_whitelist
25
- # @master_whitelist is an array of all supported emojis
26
- @master_whitelist = JSON.parse(IO.readlines(File.expand_path("emojis.json", File.dirname(__FILE__))).join)
27
- end
28
-
29
- def substitute(obj, additional_keys)
30
- if obj.data.has_key?("emoji") and !obj.data["emoji"]
31
- return
32
- end
33
-
34
- whitelist = obj.data.has_key?("emoji-whitelist") ? obj.data["emoji-whitelist"] : false
35
- blacklist = obj.data.has_key?("emoji-blacklist") ? obj.data["emoji-blacklist"] : false
36
-
37
- # When both the whitelist and blacklist are defined, whitelist will be prioritized
38
- blacklist = whitelist ? false : blacklist
39
-
40
- obj.content.gsub!(/:([\w\+\-]+):/) do |s|
41
- if (whitelist and whitelist.include?($1)) or (blacklist and !blacklist.include?($1)) or (!whitelist and !blacklist) and @master_whitelist.bsearch { |i| i >= $1 } == $1
42
- img_tag $1
43
- else
44
- s
45
- end
46
- end
47
-
48
- additional_keys.each do |key|
49
- if obj.data.has_key?(key)
50
- obj.data[key].gsub!(/:([\w\+\-]+):/) do |s|
51
- if (whitelist and whitelist.include?($1)) or (blacklist and !blacklist.include?($1)) or (!whitelist and !blacklist) and @master_whitelist.bsearch { |i| i >= $1 } == $1
52
- img_tag $1
53
- else
54
- s
55
- end
56
- end
57
- end
58
- end
59
- end
60
-
61
- def img_tag(name)
62
- "<img class=\"emoji\" title=\"#{name}\" alt=\"#{name}\" src=\"https://github.global.ssl.fastly.net/images/icons/emoji/#{name}.png\" height=\"20\" width=\"20\" align=\"absmiddle\">"
63
- end
64
- end
4
+
5
+ class EmojiGenerator < Jekyll::Generator
6
+ def generate(site)
7
+ if site.config.has_key?("emoji") and !site.config["emoji"]
8
+ return
9
+ end
10
+
11
+ if site.config.has_key?("emoji-additional-keys")
12
+ additional_keys = site.config["emoji-additional-keys"]
13
+ else
14
+ additional_keys = []
15
+ end
16
+
17
+ get_master_whitelist
18
+
19
+ get_images_path(site)
20
+
21
+ site.pages.each { |p| substitute(p, additional_keys) }
22
+
23
+ site.posts.each { |p| substitute(p, additional_keys) }
24
+ end
25
+
26
+ private
27
+ def get_master_whitelist
28
+ # @master_whitelist is an array of all supported emojis
29
+ @master_whitelist = JSON.parse(IO.readlines(File.expand_path("emoji.json", File.dirname(__FILE__))).join)
30
+ end
31
+
32
+ def get_images_path(site)
33
+ @images_path = {}
34
+ if site.config["emoji-images-path"]
35
+
36
+ images_path = site.config["emoji-images-path"]
37
+ images_dir = File.join(site.source, images_path)
38
+ Dir.foreach(images_dir) do |image_filename|
39
+ if /^(?<tag>.*)\.(?:png|jpg|jpeg|gif)/ =~ image_filename
40
+ @master_whitelist << tag
41
+ @images_path[tag] = File.join("/", images_path, image_filename)
42
+ end
43
+ end
44
+
45
+ end
46
+ @master_whitelist.sort!
47
+ end
48
+
49
+ def substitute(obj, additional_keys)
50
+ if obj.data.has_key?("emoji") and !obj.data["emoji"]
51
+ return
52
+ end
53
+
54
+ whitelist = obj.data.has_key?("emoji-whitelist") ? obj.data["emoji-whitelist"] : false
55
+ blacklist = obj.data.has_key?("emoji-blacklist") ? obj.data["emoji-blacklist"] : false
56
+
57
+ # When both the whitelist and blacklist are defined, whitelist will be prioritized
58
+ blacklist = whitelist ? false : blacklist
59
+
60
+ filter = Proc.new do |key|
61
+ (whitelist and whitelist.include?($1)) or
62
+ (blacklist and !blacklist.include?($1)) or
63
+ (!whitelist and !blacklist) and
64
+ @master_whitelist.bsearch { |i| i >= key } == key
65
+ end
66
+
67
+ obj.content.gsub!(/:([\w\+\-]+):/) do |s|
68
+ convert($1, filter)
69
+ end
70
+
71
+ additional_keys.each do |key|
72
+ if obj.data.has_key?(key)
73
+ obj.data[key].gsub!(/:([\w\+\-]+):/) do |s|
74
+ convert($1, filter)
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ # convert takes in the key to the emoji to be converted and an optional block
81
+ # If block is provided, conversion will be done only if this block evaluates to true.
82
+ def convert(key, block = nil)
83
+ if block.nil? or block.call(key)
84
+ img_tag(key)
85
+ else
86
+ ":#{key}:"
87
+ end
88
+ end
89
+
90
+ def img_tag(name)
91
+ # if there is an image in the custom images path
92
+ if @images_path[name]
93
+ img_src = @images_path[name]
94
+ else # otherwise use fallback CDN
95
+ img_src = "https://github.global.ssl.fastly.net/images/icons/emoji/#{name}.png"
96
+ end
97
+
98
+ "<img class='emoji' title='#{name}' alt='#{name}' src='#{img_src}' height='20' width='20' align='absmiddle' >"
99
+ end
100
+ end
65
101
  end
metadata CHANGED
@@ -1,23 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emoji_for_jekyll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yihang Ho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-22 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A plugin for Jekyll that seamlessly enable emoji.
14
14
  email: me@yihangho.com
15
15
  executables: []
16
16
  extensions: []
17
- extra_rdoc_files: []
17
+ extra_rdoc_files:
18
+ - README.md
19
+ - LICENSE
18
20
  files:
21
+ - LICENSE
22
+ - README.md
23
+ - lib/emoji.json
19
24
  - lib/emoji_for_jekyll.rb
20
- - lib/emojis.json
21
25
  homepage: https://github.com/yihangho/emoji-for-jekyll
22
26
  licenses:
23
27
  - MIT
@@ -39,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
43
  version: '0'
40
44
  requirements: []
41
45
  rubyforge_project:
42
- rubygems_version: 2.2.0.rc.1
46
+ rubygems_version: 2.2.2
43
47
  signing_key:
44
48
  specification_version: 4
45
49
  summary: Seamlessly enable emoji in Jekyll.