diff --git a/app/views/layouts/_details.haml b/app/views/layouts/_details.haml new file mode 100644 index 00000000..9f8a4658 --- /dev/null +++ b/app/views/layouts/_details.haml @@ -0,0 +1,17 @@ +-# + Detail Cola de Moderación + + @param :id [String] El ID opcional sirve para mantener el historial de + cuál estaba abierto y recuperarlo al cargar la página + @param :summary [String] El resumen + @param :summary_class [String] Clases para el summary + +- local_assigns[:summary_class] ||= 'h3' +- local_assigns[:details_class] ||= 'py-2' + +%details.details{ id: local_assigns[:id], class: local_assigns[:details_class], data: { controller: 'details', action: 'toggle->details#store' } } + %summary.d-flex.flex-row.align-items-center.justify-content-between{ class: local_assigns[:summary_class] } + %span= summary + %span.hide-when-open ▶ + %span.show-when-open ▼ + = yield diff --git a/app/views/posts/_table.haml b/app/views/posts/_table.haml new file mode 100644 index 00000000..ff35aace --- /dev/null +++ b/app/views/posts/_table.haml @@ -0,0 +1,34 @@ +-# + Muestra una tabla con todos los atributos de un post + + @param site [Site] + @param locale [Symbol] + @param dir [String] + @param post [Post] + @param title [String] + +%table.table.table-condensed + %thead + %tr + %th.text-center{ colspan: 2 }= title + %tbody + - post.attributes.each do |attr| + - metadata = post[attr] + - next unless metadata.front_matter? + + - cache [post, metadata, I18n.locale] do + = render("posts/attribute_ro/#{metadata.type}", + post: post, attribute: attr, + metadata: metadata, + site: site, + locale: locale, + dir: dir) + +-# Mostrar todo lo que no va en el front_matter (el contenido) +- post.attributes.each do |attr| + - metadata = post[attr] + - next if metadata.front_matter? + + - cache [post, metadata, I18n.locale] do + %section.content.pb-3{ id: attr, dir: dir } + = metadata.to_s.html_safe diff --git a/app/views/posts/attribute_ro/_has_one_nested.haml b/app/views/posts/attribute_ro/_has_one_nested.haml index 425e659e..1c89474e 100644 --- a/app/views/posts/attribute_ro/_has_one_nested.haml +++ b/app/views/posts/attribute_ro/_has_one_nested.haml @@ -1,6 +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) + %td{ dir: dir, lang: locale, colspan: 2 } + - if (p = metadata.has_one) + = render 'layouts/details', details_class: '', summary_class: 'font-weight-bold', summary: post_label_t(attribute, post: post) do + .mt-3 + = render 'posts/table', site: site, post: p, dir: dir, locale: locale, title: p.layout.humanized_name diff --git a/app/views/posts/show.haml b/app/views/posts/show.haml index 10900d67..6798c41c 100644 --- a/app/views/posts/show.haml +++ b/app/views/posts/show.haml @@ -1,4 +1,5 @@ - dir = @site.data.dig(params[:locale], 'dir') + .row.justify-content-center .col-md-8 %article.content.table-responsive-md @@ -6,29 +7,4 @@ edit_site_post_path(@site, @post.id), class: 'btn btn-secondary btn-block' - %table.table.table-condensed - %thead - %tr - %th.text-center{ colspan: 2 }= t('.front_matter') - %tbody - - @post.attributes.each do |attr| - - metadata = @post[attr] - - next unless metadata.front_matter? - - - cache [metadata, I18n.locale] do - = render("posts/attribute_ro/#{metadata.type}", - post: @post, attribute: attr, - metadata: metadata, - site: @site, - tags: all_html_tags, - locale: @locale, - dir: dir) - - -# Mostrar todo lo que no va en el front_matter (el contenido) - - @post.attributes.each do |attr| - - metadata = @post[attr] - - next if metadata.front_matter? - - - cache [metadata, I18n.locale] do - %section.content.pb-3{ id: attr, dir: dir } - = @post.public_send(attr).to_s.html_safe + = render 'table', dir: dir, site: @site, locale: @locale, post: @post, title: t('.front_matter')