From 906ec102eb69c1b424cb59e85bd48287f3d5e871 Mon Sep 17 00:00:00 2001 From: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com> Date: Wed, 31 Jul 2024 16:20:42 +0200 Subject: [PATCH] Terminology tooltip in tables: fix display issue (#34046) --- plugins/terminology_tooltip.rb | 48 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/plugins/terminology_tooltip.rb b/plugins/terminology_tooltip.rb index aeae162e8a3..9fa6482393b 100644 --- a/plugins/terminology_tooltip.rb +++ b/plugins/terminology_tooltip.rb @@ -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 [] %} - MSG - end + Valid syntax: + {% term [] %} + 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"] - - if glossary.key?("link") - rendered_link = Liquid::Template.parse(glossary["link"]).render(context).strip - link = "[Learn more]" + definition = glossary['excerpt'] || glossary['definition'] + + if glossary.key?('link') + rendered_link = Liquid::Template.parse(glossary['link']).render(context).strip + link = " [Learn more]" + definition = "#{definition.strip}#{link}".strip end - tooltip = "#{definition}#{link || ""}" + tooltip = "#{definition.strip}" "#{@text || @term}#{tooltip}" end private - SYNTAX = %r!^(\w+?|".+?")(?:\s+(\w+|".+"))?$!.freeze - + SYNTAX = /^(\w+?|".+?")(?:\s+(\w+|".+"))?$/ end end end