class Bunto::Emoji
Constants
- 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/bemoji.rb, line 41 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 Bunto::Document or Bunto::Page
Returns true if the doc is written & is HTML.
# File lib/bemoji.rb, line 54 def emojiable?(doc) (doc.is_a?(Bunto::Page) || doc.write?) && doc.output_ext == ".html" || (doc.permalink && doc.permalink.end_with?("/")) end
# File lib/bemoji.rb, line 10 def emojify(doc) src = emoji_src(doc.site.config) doc.output = filter_with_emoji(src).call(doc.output)[:output].to_s 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/bemoji.rb, line 20 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/bemoji.rb, line 28 def filters @filters ||= {} end