class Jekyll::Emoji
Constants
- BODY_START_TAG
- GITHUB_DOT_COM_ASSET_ROOT
Public Class Methods
Public: Calculate the asset root source for the given config. The custom emoji asset root can be defined in the config as emoji.src, and must be a valid URL (i.e. it must include a protocol and valid domain)
config - the hash-like configuration of the document's site
Returns a full URL to use as the asset root URL. Defaults to the assets.github.com emoji root.
# File lib/jemoji.rb, line 50 def emoji_src(config = {}) if config.key?("emoji") && config["emoji"].key?("src") config["emoji"]["src"] else GITHUB_DOT_COM_ASSET_ROOT end end
Public: Defines the conditions for a document to be emojiable.
doc - the Jekyll::Document or Jekyll::Page
Returns true if the doc is written & is HTML.
# File lib/jemoji.rb, line 63 def emojiable?(doc) (doc.is_a?(Jekyll::Page) || doc.write?) && doc.output_ext == ".html" || (doc.permalink && doc.permalink.end_with?("/")) end
# File lib/jemoji.rb, line 11 def emojify(doc) return unless doc.output =~ HTML::Pipeline::EmojiFilter.emoji_pattern src = emoji_src(doc.site.config) if doc.output.include? BODY_START_TAG parsed_doc = Nokogiri::HTML::Document.parse(doc.output) body = parsed_doc.at_css('body') body.children = filter_with_emoji(src).call(body.inner_html)[:output].to_s doc.output = parsed_doc.to_html else doc.output = filter_with_emoji(src).call(doc.output)[:output].to_s end end
Public: Create or fetch the filter for the given {{src}} asset root.
src - the asset root URL (e.g. assets.github.com/images/icons/)
Returns an HTML::Pipeline instance for the given asset root.
# File lib/jemoji.rb, line 29 def filter_with_emoji(src) filters[src] ||= HTML::Pipeline.new([ HTML::Pipeline::EmojiFilter ], { :asset_root => src }) end
Public: Filters hash where the key is the asset root source. Effectively a cache.
# File lib/jemoji.rb, line 37 def filters @filters ||= {} end