class Jekyll::Mentions
Constants
- BODY_START_TAG
- GITHUB_DOT_COM
- InvalidJekyllMentionConfig
Public Class Methods
Public: Create or fetch the filter for the given {{src}} base URL.
src - the base URL (e.g. github.com)
Returns an HTML::Pipeline instance for the given base URL.
# File lib/jekyll-mentions.rb, line 31 def filter_with_mention(src) filters[src] ||= HTML::Pipeline.new([ HTML::Pipeline::MentionFilter ], { :base_url => src }) end
Public: Filters hash where the key is the mention base URL. Effectively a cache.
# File lib/jekyll-mentions.rb, line 39 def filters @filters ||= {} end
Public: Calculate the base URL to use for mentioning. The custom base URL can be defined in the config as jekyll-mentions.base_url or jekyll-mentions, and must be a valid URL (i.e. it must include a protocol and valid domain) It should not have a trailing slash.
config - the hash-like configuration of the document's site
Returns a URL to use as the base URL for mentions. Defaults to the github.com.
# File lib/jekyll-mentions.rb, line 53 def mention_base(config = {}) mention_config = config['jekyll-mentions'] case mention_config when nil, NilClass GITHUB_DOT_COM when String mention_config.to_s when Hash mention_config.fetch('base_url', GITHUB_DOT_COM) else raise InvalidJekyllMentionConfig, "Your jekyll-mentions config has to either be a" " string or a hash. It's a #{mention_config.class} right now." 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/jekyll-mentions.rb, line 74 def mentionable?(doc) (doc.is_a?(Jekyll::Page) || doc.write?) && doc.output_ext == ".html" || (doc.permalink && doc.permalink.end_with?("/")) end
# File lib/jekyll-mentions.rb, line 13 def mentionify(doc) return unless doc.output.include?("@") src = mention_base(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_mention(src).call(body.inner_html)[:output].to_s doc.output = parsed_doc.to_html else doc.output = filter_with_mention(src).call(doc.output)[:output].to_s end end