5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-28 11:36:21 +00:00

refactor: usar constantes

This commit is contained in:
f 2023-10-06 17:40:14 -03:00
parent df3989a187
commit 2ac91e4faf
No known key found for this signature in database

View file

@ -1,5 +1,11 @@
# frozen_string_literal: true # frozen_string_literal: true
module MetadataTemplateConstants
ALLOWED_ATTRIBUTES = %w[style href src alt controls data-align data-multimedia data-multimedia-inner id name].freeze
ALLOWED_TAGS = %w[strong em del u mark p h1 h2 h3 h4 h5 h6 ul ol li img iframe audio video div figure blockquote
figcaption a sub sup small].freeze
end
# Representa la plantilla de un campo en los metadatos del artículo # Representa la plantilla de un campo en los metadatos del artículo
# #
# TODO: Validar el tipo de valor pasado a value= según el :type # TODO: Validar el tipo de valor pasado a value= según el :type
@ -8,6 +14,7 @@
MetadataTemplate = Struct.new(:site, :document, :name, :label, :type, MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
:value, :help, :required, :errors, :post, :value, :help, :required, :errors, :post,
:layout, keyword_init: true) do :layout, keyword_init: true) do
include MetadataTemplateConstants
include Metadata::FrontMatterConcern include Metadata::FrontMatterConcern
# @return [String] # @return [String]
@ -222,8 +229,8 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
sanitizer sanitizer
.sanitize(string.tr("\r", '').unicode_normalize, .sanitize(string.tr("\r", '').unicode_normalize,
tags: allowed_tags, tags: ALLOWED_TAGS,
attributes: allowed_attributes) attributes: ALLOWED_ATTRIBUTES)
.strip .strip
.html_safe .html_safe
end end
@ -233,16 +240,6 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
@sanitizer ||= Rails::Html::Sanitizer.safe_list_sanitizer.new @sanitizer ||= Rails::Html::Sanitizer.safe_list_sanitizer.new
end end
def allowed_attributes
@allowed_attributes ||= %w[style href src alt controls data-align data-multimedia data-multimedia-inner id
name].freeze
end
def allowed_tags
@allowed_tags ||= %w[strong em del u mark p h1 h2 h3 h4 h5 h6 ul ol li img iframe audio video div figure blockquote
figcaption a sub sup small].freeze
end
# Decifra el valor # Decifra el valor
# #
# @todo Agregar el error de decifrado en self.errors # @todo Agregar el error de decifrado en self.errors