Update chat block attributes

This commit is contained in:
Gabriel Arazas 2023-11-16 20:15:57 +08:00
parent 5cb366fb2a
commit 586cc8daee
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
2 changed files with 8 additions and 9 deletions

View File

@ -12,16 +12,15 @@ module Asciidoctor::Foodogsquared::Converter
attributes << %(id="#{node.id}") if node.id
attributes << %(class="#{node.role}") if node.role
avatar_sticker = node.attributes['avatarsticker']
avatar_uri = node.parent.image_uri avatar_sticker, 'avatarsdir'
avatar_uri = node.parent.image_uri "#{node.attr 'avatarsticker'}/#{node.attr 'state'}.#{node.attr 'avatarstype'}", 'avatarsdir'
<<~HTML
<div role="figure" #{attributes.join ' '}>
<div class="dialogblock-avatar">
<img src="#{avatar_uri}" alt="#{node.attributes['name']}">
<img src="#{avatar_uri}" alt="#{node.attributes['avatar']}">
</div>
<div class="dialogblock-text">
<small>#{node.attributes['name']}</small>
<small>#{node.attributes['avatar']}</small>
#{node.content}
</div>
</div>

View File

@ -9,13 +9,13 @@ module Asciidoctor::Foodogsquared::Extensions
name_positional_attributes 'avatar', 'state'
default_attributes 'state' => 'default'
def process(parent, reader, attrs)
attrs['name'] ||= attrs['avatar']
def process(parent, _, attrs)
doc_attrs = parent.document.attributes
# Configuring the avatar-related attributes.
attrs['avatarsdir'] ||= File.expand_path('./avatars', attrs['iconsdir'])
attrs['avatarstype'] ||= parent.attributes['avatarstype'] || 'avif'
attrs['avatarsticker'] = "#{attrs['avatar'].to_kebab}/#{attrs['state'].to_kebab}.#{attrs['avatarstype']}"
attrs['avatarsdir'] ||= doc_attrs['avatarsdir'] || File.expand_path('./avatars', attrs['iconsdir'])
attrs['avatarstype'] ||= doc_attrs['avatarstype'] || 'avif'
attrs['avatarsticker'] = attrs['avatar'].to_kebab
block = create_block parent, :chat, nil, attrs, content_model: :compound
block.add_role 'dialogblock'