5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2025-03-14 20:08:19 +00:00

Merge branch 'issue-17333' into 'rails'

feat: poder configurar la fecha por defecto #17333

Closes #17593, #17530, #17575, #17576, #17577, #17580, #17581, #17582, #17584, #17586, #17588, #17589, and #17590

See merge request sutty/sutty!281
This commit is contained in:
fauno 2025-01-26 06:48:38 +00:00
commit 9a61511d4c
3 changed files with 27 additions and 3 deletions

View file

@ -1,8 +1,30 @@
# frozen_string_literal: true # frozen_string_literal: true
class MetadataDate < MetadataTemplate class MetadataDate < MetadataTemplate
# La fecha de hoy si no hay nada. Podemos traer un valor por defecto
# desde el esquema, siempre y cuando pueda considerarse una fecha
# válida.
#
# @return [Date,nil]
def default_value def default_value
Date.today if (dv = super.presence)
begin
Date.parse(dv)
# XXX: Notificar para que sepamos que el esquema no es válido.
# TODO: Validar el valor por defecto en sutty-schema-validator.
rescue Date::Error => e
ExceptionNotifier.notify_exception(e, data: { site: site.name, post: post.id, name:, type: })
nil
end
end
end
# Delegar el formato al valor, para uso dentro de date_field()
#
# @param format [String]
# @return [String,nil]
def strftime(format)
value&.strftime(format)
end end
# Devuelve una fecha, si no hay ninguna es la fecha de hoy. # Devuelve una fecha, si no hay ninguna es la fecha de hoy.

View file

@ -1,3 +1,5 @@
%tr{ id: attribute } %tr{ id: attribute }
%th= post_label_t(attribute, post: post) %th= post_label_t(attribute, post: post)
%td{ dir: dir, lang: locale }= l metadata.value.to_date %td{ dir: dir, lang: locale }
- if metadata.value
= l metadata.value

View file

@ -1,6 +1,6 @@
.form-group .form-group
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post) = label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post)
= date_field base, attribute, value: metadata.value.to_date.strftime('%F'), = date_field base, attribute, value: metadata.value&.strftime('%F'),
**field_options(attribute, metadata), pattern: '\d{4}-\d{2}-\d{2}', **field_options(attribute, metadata), pattern: '\d{4}-\d{2}-\d{2}',
data: { 'pattern-mismatch': t('metadata.date.invalid_format') } data: { 'pattern-mismatch': t('metadata.date.invalid_format') }
= render 'posts/attribute_feedback', = render 'posts/attribute_feedback',