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