jemoji 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jemoji.rb +49 -26
  3. metadata +5 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 663058ad7ebe61f765f95c3da385b9e5780d07e1
4
- data.tar.gz: 5992147ae0e202c123c843dcae1dc46e22bf2954
3
+ metadata.gz: 863bbb0e3fc417fe221613909e76d946ab5a5fce
4
+ data.tar.gz: 434939b213fc37b2d6772c3938c27e9d281b16ab
5
5
  SHA512:
6
- metadata.gz: b4d565306021a98894f279bc87a4fe253148414739890c190371d6161febde32c7001812d416941e7daa014bee1704ca2ea16509c3c19aedaf7a49a8c523deb9
7
- data.tar.gz: b4c9df47459b92d109ade6c5e68fe4732360d86c0ce0f2ebd5792ef61fb1c0de6744004a2f6c05f5267100fd4864108378b6c40c045d83080f8992ed906a91bd
6
+ metadata.gz: feb452169907fb003decc0890429047806f24216483b2eb2b572d6ded58d907cd4656d9f8f289ed7a020899ed5e032da576230f3454ebccd867aebac6941068a
7
+ data.tar.gz: 7e63fa351ece10c4b5f4d85ff8dde2be1157775a09f5057ae8019b2ec850529ccad6873f58ea1c9c2d073abae11090fa2148c2db2e158f3fae2bd5ba5cedd3c6
@@ -3,39 +3,62 @@ require 'gemoji'
3
3
  require 'html/pipeline'
4
4
 
5
5
  module Jekyll
6
- class Emoji < Jekyll::Generator
7
- attr_reader :config
8
- safe true
6
+ class Emoji
7
+ GITHUB_DOT_COM_ASSET_ROOT = "https://assets.github.com/images/icons/".freeze
9
8
 
10
- def initialize(config = {})
11
- @config = config
12
- end
9
+ class << self
10
+ def emojify(doc)
11
+ src = emoji_src(doc.site.config)
12
+ doc.output = filter_with_emoji(src).call(doc.output)[:output].to_s
13
+ end
14
+
15
+ # Public: Create or fetch the filter for the given {{src}} asset root.
16
+ #
17
+ # src - the asset root URL (e.g. https://assets.github.com/images/icons/)
18
+ #
19
+ # Returns an HTML::Pipeline instance for the given asset root.
20
+ def filter_with_emoji(src)
21
+ filters[src] ||= HTML::Pipeline.new([
22
+ HTML::Pipeline::EmojiFilter
23
+ ], { :asset_root => src })
24
+ end
25
+
26
+ # Public: Filters hash where the key is the asset root source.
27
+ # Effectively a cache.
28
+ def filters
29
+ @filters ||= {}
30
+ end
13
31
 
14
- def src
15
- @src ||=
32
+ # Public: Calculate the asset root source for the given config.
33
+ # The custom emoji asset root can be defined in the config as
34
+ # emoji.src, and must be a valid URL (i.e. it must include a
35
+ # protocol and valid domain)
36
+ #
37
+ # config - the hash-like configuration of the document's site
38
+ #
39
+ # Returns a full URL to use as the asset root URL. Defaults to
40
+ # the assets.github.com emoji root.
41
+ def emoji_src(config = {})
16
42
  if config.key?("emoji") && config["emoji"].key?("src")
17
43
  config["emoji"]["src"]
18
44
  else
19
- "https://assets.github.com/images/icons/"
45
+ GITHUB_DOT_COM_ASSET_ROOT
20
46
  end
21
- end
22
-
23
- def filter
24
- @filter ||= HTML::Pipeline::EmojiFilter.new(nil, { :asset_root => src })
25
- end
47
+ end
26
48
 
27
- def generate(site)
28
- site.posts.each { |doc| emojify doc } unless v3?
29
- site.pages.each { |doc| emojify doc }
30
- site.docs_to_write.each { |doc| emojify doc }
31
- end
32
-
33
- def emojify(page)
34
- page.content = filter.emoji_image_filter(page.content)
35
- end
36
-
37
- def v3?
38
- ::Jekyll::VERSION.to_f >= 3.0
49
+ # Public: Defines the conditions for a document to be emojiable.
50
+ #
51
+ # doc - the Jekyll::Document or Jekyll::Page
52
+ #
53
+ # Returns true if the doc is written & is HTML.
54
+ def emojiable?(doc)
55
+ (doc.class == Jekyll::Page || doc.write?) &&
56
+ doc.output_ext == ".html" || (doc.permalink && doc.permalink.end_with?("/"))
57
+ end
39
58
  end
40
59
  end
41
60
  end
61
+
62
+ Jekyll::Hooks.register [:pages, :documents], :post_render do |doc|
63
+ Jekyll::Emoji.emojify(doc) if Jekyll::Emoji.emojiable?(doc)
64
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jemoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-01 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: html-pipeline
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -121,9 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 2.4.8
124
+ rubygems_version: 2.5.1
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: GitHub-flavored emoji plugin for Jekyll
128
128
  test_files: []
129
- has_rdoc: