mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 09:56:21 +00:00
feat: poder anidar un artículo #15066
This commit is contained in:
parent
5e2bddf7cc
commit
0cf2ec04ba
6 changed files with 59 additions and 10 deletions
11
app/models/metadata_has_one_nested.rb
Normal file
11
app/models/metadata_has_one_nested.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MetadataHasOneNested < MetadataHasOne
|
||||
def nested
|
||||
@nested ||= layout.metadata.dig(name, 'nested')
|
||||
end
|
||||
|
||||
def nested?
|
||||
true
|
||||
end
|
||||
end
|
16
app/views/posts/_attributes.haml
Normal file
16
app/views/posts/_attributes.haml
Normal file
|
@ -0,0 +1,16 @@
|
|||
-#
|
||||
@param base [String]
|
||||
@param locale [String]
|
||||
@param post [Post]
|
||||
@param site [Site]
|
||||
@param dir [String]
|
||||
- post.attributes.each do |attribute|
|
||||
- metadata = post[attribute]
|
||||
- type = metadata.type
|
||||
|
||||
- cache [metadata, I18n.locale] do
|
||||
= render("posts/attributes/#{type}",
|
||||
base: base, post: post, attribute: attribute,
|
||||
metadata: metadata, site: site,
|
||||
dir: dir, locale: locale,
|
||||
autofocus: (post.attributes.first == attribute))
|
19
app/views/posts/_attributes_nested.haml
Normal file
19
app/views/posts/_attributes_nested.haml
Normal file
|
@ -0,0 +1,19 @@
|
|||
-#
|
||||
@param inverse [Symbol]
|
||||
@param base [String]
|
||||
@param locale [String]
|
||||
@param post [Post]
|
||||
@param site [Site]
|
||||
@param dir [String]
|
||||
- post.attributes.each do |attribute|
|
||||
- next if attribute == :date
|
||||
- next if attribute == :draft
|
||||
- next if attribute == inverse
|
||||
- metadata = post[attribute]
|
||||
- type = metadata.type
|
||||
|
||||
- cache [metadata, I18n.locale] do
|
||||
= render "posts/attributes/#{type}",
|
||||
base: base, post: post, attribute: attribute,
|
||||
metadata: metadata, site: site,
|
||||
dir: dir, locale: locale, autofocus: false
|
|
@ -41,16 +41,7 @@
|
|||
= hidden_field_tag 'post[layout]', post.layout.name
|
||||
|
||||
-# Dibuja cada atributo
|
||||
- post.attributes.each do |attribute|
|
||||
- metadata = post[attribute]
|
||||
- type = metadata.type
|
||||
|
||||
- cache [metadata, I18n.locale] do
|
||||
= render("posts/attributes/#{type}",
|
||||
base: 'post', post: post, attribute: attribute,
|
||||
metadata: metadata, site: site,
|
||||
dir: dir, locale: @locale,
|
||||
autofocus: (post.attributes.first == attribute))
|
||||
= render 'posts/attributes', site: site, post: post, dir: dir, base: 'post', locale: @locale
|
||||
|
||||
-# Botones de guardado
|
||||
= render 'posts/submit', site: site, post: post
|
||||
|
|
6
app/views/posts/attribute_ro/_has_one_nested.haml
Normal file
6
app/views/posts/attribute_ro/_has_one_nested.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
%tr{ id: attribute }
|
||||
%th= post_label_t(attribute, post: post)
|
||||
%td{ dir: dir, lang: locale }
|
||||
- p = metadata.has_one
|
||||
- if p
|
||||
= link_to p.title.value, site_post_path(site, p.id)
|
6
app/views/posts/attributes/_has_one_nested.haml
Normal file
6
app/views/posts/attributes/_has_one_nested.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
- new_post = site.posts(lang: locale).build(layout: metadata.nested)
|
||||
- base = "#{base}[#{metadata.name}]"
|
||||
|
||||
.form-group
|
||||
= render 'layouts/details', id: metadata.nested, summary: site.layouts[metadata.nested].humanized_name do
|
||||
= render 'posts/attributes_nested', site: site, post: new_post, dir: dir, base: base, locale: locale, inverse: metadata.inverse
|
Loading…
Reference in a new issue