mirror of
https://github.com/foo-dogsquared/website.git
synced 2025-01-31 04:58:26 +00:00
Update helper with kebab-case conversion
This commit is contained in:
parent
69ad8fb4de
commit
d4afb91e49
@ -24,7 +24,7 @@ class ChatBlock < Asciidoctor::Extensions::BlockProcessor
|
||||
|
||||
attrs['avatarsdir'] ||= File.expand_path('./avatars', attrs['iconsdir'])
|
||||
|
||||
avatar_sticker = "#{attrs['avatar'].to_snake}/#{attrs['state'].to_snake}.#{attrs['avatarstype']}"
|
||||
avatar_sticker = "#{attrs['avatar'].to_kebab}/#{attrs['state'].to_kebab}.#{attrs['avatarstype']}"
|
||||
avatar_img_attrs = {
|
||||
'target' => parent.image_uri(avatar_sticker, 'avatarsdir'),
|
||||
'alt' => attrs['name']
|
||||
|
@ -1,10 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Code copied from https://gist.github.com/komasaru/b3f22d5bcb8555deea1707b84d294045.
|
||||
class String
|
||||
def to_snake
|
||||
self.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
||||
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
||||
def to_kebab
|
||||
self.gsub(/\s+/, '-') # Replace all spaces with dashes.
|
||||
.gsub(/[^a-zA-Z0-9-]/, '') # Remove all non-alphanumerical (and dashes) characters.
|
||||
.gsub(/-+/, '-') # Reduce all dashes into only one.
|
||||
.gsub(/^-|-+$/, '') # Remove all leading and trailing dashes.
|
||||
.downcase
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user