class Jekyll::GlossaryTooltip::Tag
Custom liquid tag implementation.
Constants
- LOG_TAG
Public Class Methods
new(tag_name, args, tokens)
click to toggle source
Calls superclass method
# File lib/jekyll-glossary_tooltip/tag.rb, line 10 def initialize(tag_name, args, tokens) super @opts = OptionsParser.parse(args) end
Public Instance Methods
render(context)
click to toggle source
# File lib/jekyll-glossary_tooltip/tag.rb, line 15 def render(context) entry = lookup_entry(context.registers[:site], @opts[:term_query]) @opts[:display] ||= @opts[:term_query] <<~HTML <span class="jekyll-glossary"> #{@opts[:display]} <span class="jekyll-glossary-tooltip">#{entry["definition"]}#{render_tooltip_url(entry)}</span> </span> HTML end
Private Instance Methods
lookup_entry(site, term_name)
click to toggle source
# File lib/jekyll-glossary_tooltip/tag.rb, line 37 def lookup_entry(site, term_name) entry = read_term_entry_from_config(site, term_name) raise Errors::MissingTermDefinition, term_name unless entry["definition"] entry["url"] = nil unless entry.key?("url") entry end
read_term_entry_from_config(site, term_name)
click to toggle source
Retrieve a term from the glossary via the site.
# File lib/jekyll-glossary_tooltip/tag.rb, line 46 def read_term_entry_from_config(site, term_name) raise Errors::NoGlossaryFile unless site.data["glossary"] entries = site.data["glossary"].select do |entry| entry.key?("term") and term_name.casecmp(entry["term"]).zero? end case entries.length when 0 raise Errors::MissingTermEntry, term_name when 1 entries[0] else raise Errors::MultipleTermEntries, term_name end end
render_tooltip_url(entry)
click to toggle source
# File lib/jekyll-glossary_tooltip/tag.rb, line 30 def render_tooltip_url(entry) # The content of the anchor is set from the CSS class jekyll-glossary-source-link, # so that the plugin user can customize the text without touching ruby source. anchor = "<br><a class=\"jekyll-glossary-source-link\" href=\"#{entry["url"]}\" target=\"_blank\"></a>" entry["url"] ? anchor : "" end