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

feat: ignorar algunos campos

(cherry picked from commit 9b3db70bf4)
This commit is contained in:
f 2024-05-23 18:19:59 -03:00
parent d5d31a6d94
commit c1f1571891
No known key found for this signature in database
4 changed files with 23 additions and 14 deletions

View file

@ -247,18 +247,6 @@ class Post
@metadata[:created_at] ||= MetadataCreatedAt.new(document: document, site: site, layout: layout, name: :created_at, type: :created_at, post: self, required: true)
end
# Detecta si es un atributo válido o no, a partir de la tabla de la
# plantilla
def attribute?(mid)
included = DEFAULT_ATTRIBUTES.include?(mid) ||
PRIVATE_ATTRIBUTES.include?(mid) ||
PUBLIC_ATTRIBUTES.include?(mid)
included = attributes.include? mid if !included && singleton_class.method_defined?(:attributes)
included
end
# Devuelve los strong params para el layout.
#
# XXX: Nos gustaría no tener que instanciar Metadata acá, pero depende
@ -430,6 +418,18 @@ class Post
@nested_attributes ||= attributes.map { |a| self[a] }.select(&:nested?).map(&:name)
end
# Detecta si es un atributo válido o no, a partir de la tabla de la
# plantilla
def attribute?(mid)
included = DEFAULT_ATTRIBUTES.include?(mid) ||
PRIVATE_ATTRIBUTES.include?(mid) ||
PUBLIC_ATTRIBUTES.include?(mid)
included = attributes.include? mid if !included && singleton_class.method_defined?(:attributes)
included
end
private
# Levanta un error si al construir el artículo no pasamos un atributo.

View file

@ -4,7 +4,8 @@
@param post [Post]
@param site [Site]
@param dir [String]
- post.attributes.each do |attribute|
@param except [Array<Symbol>]
- (post.attributes - local_assigns[:except].to_a).each do |attribute|
- metadata = post[attribute]
- type = metadata.type

View file

@ -6,6 +6,12 @@
@param :locale [Symbol, String]
@param :dir [Symbol, String]
:ruby
except = %i[date]
if (inverse = params.permit(:inverse).try(:[], :inverse).presence)
except << inverse.to_sym
end
options = {
id: base,
multipart: true,
@ -33,4 +39,4 @@
= hidden_field_tag "#{base}[layout]", post.layout.name
-# Dibuja cada atributo
= render 'posts/attributes', site: site, post: post, dir: dir, base: base, locale: locale
= render 'posts/attributes', site: site, post: post, dir: dir, base: base, locale: locale, except: except

View file

@ -86,6 +86,8 @@
%input{ type: 'hidden', name: 'swap', value: 'beforeend' }
%input{ type: 'hidden', name: 'base', value: id }
%input{ type: 'hidden', name: 'name', value: name }
- if metadata.inverse?
%input{ type: 'hidden', name: 'inverse', value: metadata.inverse }
%div{ id: post_modal_id, data: { controller: 'modal' } }
= render 'bootstrap/modal', id: post_id, modal_content_attributes: { class: 'h-100' } do
- content_for :"#{post_id}_body" do