mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-22 08:46:51 +00:00
Terminology tooltip in tables: fix display issue (#34046)
This commit is contained in:
parent
fe382f2126
commit
906ec102eb
@ -1,51 +1,51 @@
|
||||
module Jekyll
|
||||
module HomeAssistant
|
||||
class TerminologyTooltip < Liquid::Tag
|
||||
|
||||
def initialize(tag_name, args, tokens)
|
||||
super
|
||||
if args.strip =~ SYNTAX
|
||||
@term = Regexp.last_match(1)
|
||||
@text = Regexp.last_match(2)
|
||||
else
|
||||
raise SyntaxError, <<~MSG
|
||||
Syntax error in tag 'term' while parsing the following options:
|
||||
raise SyntaxError, <<~MSG unless args.strip =~ SYNTAX
|
||||
Syntax error in tag 'term' while parsing the following options:
|
||||
|
||||
#{args}
|
||||
#{args}
|
||||
|
||||
Valid syntax:
|
||||
{% term <term> [<text>] %}
|
||||
MSG
|
||||
end
|
||||
Valid syntax:
|
||||
{% term <term> [<text>] %}
|
||||
MSG
|
||||
|
||||
@term = Regexp.last_match(1)
|
||||
@text = Regexp.last_match(2)
|
||||
end
|
||||
|
||||
def render(context)
|
||||
@term.gsub!(/\"/, "")
|
||||
entries = context.registers[:site].data["glossary"].select do |entry|
|
||||
entry.key?("term") and (@term.casecmp(entry["term"]).zero? or (entry.key?("aliases") and entry["aliases"].any?{ |s| s.casecmp(@term)==0 }))
|
||||
@term.gsub!(/"/, '')
|
||||
entries = context.registers[:site].data['glossary'].select do |entry|
|
||||
entry.key?('term') and (@term.casecmp(entry['term']).zero? or (entry.key?('aliases') and entry['aliases'].any? do |s|
|
||||
s.casecmp(@term) == 0
|
||||
end))
|
||||
end
|
||||
|
||||
raise ArgumentError, "Term #{@term} was not found in the glossary" if entries.length == 0
|
||||
raise ArgumentError, "Term #{@term} is in the glossary multiple times" if entries.length > 1
|
||||
raise ArgumentError, "Term #{@term} is missing a definition" unless entries[0].key?("definition")
|
||||
raise ArgumentError, "Term #{@term} is missing a definition" unless entries[0].key?('definition')
|
||||
|
||||
glossary = entries[0]
|
||||
|
||||
definition = glossary["excerpt"] || glossary["definition"]
|
||||
definition = glossary['excerpt'] || glossary['definition']
|
||||
|
||||
if glossary.key?("link")
|
||||
rendered_link = Liquid::Template.parse(glossary["link"]).render(context).strip
|
||||
link = "<small><a class='terminology-link' href='#{rendered_link}'>[Learn more]</a></small>"
|
||||
if glossary.key?('link')
|
||||
rendered_link = Liquid::Template.parse(glossary['link']).render(context).strip
|
||||
link = "<a class='terminology-link' href='#{rendered_link}'> [Learn more]</a>"
|
||||
definition = "#{definition.strip}#{link}".strip
|
||||
end
|
||||
|
||||
tooltip = "<span class='terminology-tooltip'>#{definition}#{link || ""}</span>"
|
||||
tooltip = "<span class='terminology-tooltip'>#{definition.strip}</span>"
|
||||
|
||||
"<span class='terminology'>#{@text || @term}#{tooltip}</span>"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
SYNTAX = %r!^(\w+?|".+?")(?:\s+(\w+|".+"))?$!.freeze
|
||||
|
||||
SYNTAX = /^(\w+?|".+?")(?:\s+(\w+|".+"))?$/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user