5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-24 12:56:21 +00:00

feat: poder configurar la fecha por defecto #17333

This commit is contained in:
f 2024-09-09 11:02:27 -03:00
parent 11e2353c2f
commit b4027e6686
No known key found for this signature in database
3 changed files with 20 additions and 3 deletions

View file

@ -1,9 +1,26 @@
# frozen_string_literal: true
class MetadataDate < MetadataTemplate
# La fecha de hoy si no hay nada
#
# @return [Date,nil]
def default_value
case (dv = super)
when String
if dv.present?
begin
Date.parse(dv)
rescue Date::Error => e
ExceptionNotifier.notify_exception(e, data: { site: site.name, post: post.id, name:, type: })
nil
end
else
nil
end
else
Date.today
end
end
# Devuelve una fecha, si no hay ninguna es la fecha de hoy.
#

View file

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

View file

@ -1,6 +1,6 @@
.form-group
= 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}',
data: { 'pattern-mismatch': t('metadata.date.invalid_format') }
= render 'posts/attribute_feedback',