bemoji 1.0.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 +7 -0
  2. data/lib/bemoji.rb +64 -0
  3. metadata +128 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b1b2659bf9936da35cf19b6afc89f42da590364
4
+ data.tar.gz: 38284c17499209a288173d53e4f6a76d57dbc7fd
5
+ SHA512:
6
+ metadata.gz: 4ce38c174472968471dbc1013b76548116ed43bd28a65bfb49de41093a30c7d66171a14f54a03b24bfb1c0ea4f5b7348f209123e6a5dc818d50ddd78a87d2dcf
7
+ data.tar.gz: 5d9ce6593b350d79a4b3efe74a08e0ee7a8ef8ccea2aaa15e4f80ce7ded29b74187c71e2ae31cbbcaeae9aff174851c6fe45911fa711eeb48147b77e3b720c85
@@ -0,0 +1,64 @@
1
+ require 'bunto'
2
+ require 'gemoji'
3
+ require 'html/pipeline'
4
+
5
+ module Bunto
6
+ class Emoji
7
+ GITHUB_DOT_COM_ASSET_ROOT = "https://assets.github.com/images/icons/".freeze
8
+
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
31
+
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 = {})
42
+ if config.key?("emoji") && config["emoji"].key?("src")
43
+ config["emoji"]["src"]
44
+ else
45
+ GITHUB_DOT_COM_ASSET_ROOT
46
+ end
47
+ end
48
+
49
+ # Public: Defines the conditions for a document to be emojiable.
50
+ #
51
+ # doc - the Bunto::Document or Bunto::Page
52
+ #
53
+ # Returns true if the doc is written & is HTML.
54
+ def emojiable?(doc)
55
+ (doc.is_a?(Bunto::Page) || doc.write?) &&
56
+ doc.output_ext == ".html" || (doc.permalink && doc.permalink.end_with?("/"))
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ Bunto::Hooks.register [:pages, :documents], :post_render do |doc|
63
+ Bunto::Emoji.emojify(doc) if Bunto::Emoji.emojiable?(doc)
64
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bemoji
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - GitHub, Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bunto
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: html-pipeline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: gemoji
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rdoc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description:
98
+ email: support@github.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - lib/bemoji.rb
104
+ homepage: https://github.com/bunto/bemoji
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: GitHub-flavored emoji plugin for Bunto
128
+ test_files: []