mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-23 01:06:52 +00:00
Extend icon plugin with title attribute (#36004)
This commit is contained in:
parent
3c845818ca
commit
79596530bc
@ -5,7 +5,8 @@ module Jekyll
|
|||||||
def initialize(tag_name, args, tokens)
|
def initialize(tag_name, args, tokens)
|
||||||
super
|
super
|
||||||
if args.strip =~ SYNTAX
|
if args.strip =~ SYNTAX
|
||||||
@icon = Regexp.last_match(1).downcase
|
@icon = Regexp.last_match[:icon].downcase
|
||||||
|
@title = Regexp.last_match[:title]
|
||||||
else
|
else
|
||||||
raise SyntaxError, <<~MSG
|
raise SyntaxError, <<~MSG
|
||||||
Syntax error in tag 'icon' while parsing the following options:
|
Syntax error in tag 'icon' while parsing the following options:
|
||||||
@ -13,18 +14,29 @@ module Jekyll
|
|||||||
#{args}
|
#{args}
|
||||||
|
|
||||||
Valid syntax:
|
Valid syntax:
|
||||||
{% icon "<icon-set>:<icon-name>" %}
|
{% icon "<icon-set>:<icon-name>" [title="<title>"] %}
|
||||||
MSG
|
MSG
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def default_title(icon)
|
||||||
|
# split away "mdi:" part
|
||||||
|
icon_name = icon.split(':').last
|
||||||
|
|
||||||
|
# remove dashes and capitalize e.g. "water-polo" to "Water polo"
|
||||||
|
parts = icon_name.split('-')
|
||||||
|
parts[0] = parts[0].capitalize
|
||||||
|
parts.join(' ')
|
||||||
|
end
|
||||||
|
|
||||||
def render(_context)
|
def render(_context)
|
||||||
"<iconify-icon inline icon='#{@icon}'></iconify-icon>"
|
title = @title || default_title(@icon)
|
||||||
|
"<iconify-icon inline icon='#{@icon}' title='#{title}'></iconify-icon>"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
SYNTAX = %r!^"([a-z0-9]+(?:-[a-z0-9]+)*:[a-z0-9]+(?:-[a-z0-9]+)*)"$!.freeze
|
SYNTAX = %r!^"(?<icon>[a-z0-9]+(?:-[a-z0-9]+)*:[a-z0-9]+(?:-[a-z0-9]+)*)"(?:\s+title="(?<title>[^"]+)")?$!.freeze
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user