This commit is contained in:
f 2019-11-07 13:06:40 -03:00
parent 5c48a2da5e
commit 7ddc4e6150
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
4 changed files with 32 additions and 2 deletions

View file

@ -9,8 +9,10 @@ class PostsController < ApplicationController
authorize Post
@site = find_site
@category = session[:category] = params.dig(:category)
@layout = params.dig(:layout).try :to_sym
# TODO: Aplicar policy_scope
@posts = @site.posts(lang: I18n.locale)
@posts = @site.posts(lang: I18n.locale)
@posts.sort_by! :order, :date
end
def show

View file

@ -1,4 +1,7 @@
# frozen_string_literal: true
class MetadataDate < MetadataTemplate
def default_value
Date.today
end
end

View file

@ -31,6 +31,22 @@ class PostRelation < Array
post
end
alias sort_by_generic! sort_by!
# Permite ordenar los artículos por sus atributos
#
# XXX: Prestar atención cuando estamos mezclando artículos con
# diferentes tipos de atributos.
def sort_by!(*attrs)
sort_by_generic! do |post|
attrs.map do |attr|
return 0 unless post.attributes.include? attr
post.public_send(attr).value
end
end
end
alias find_generic find
# Encontra un post por su id convertido a SHA1

View file

@ -37,6 +37,8 @@
- if @category
- next unless post.attributes.include? :categories
- next unless post.categories.value.include?(@category)
- if @layout
- next unless post.layout.name == @layout
- next unless policy(post).show?
%tr
%td
@ -45,6 +47,10 @@
= hidden_field 'post[reorder]', post.sha1,
value: i, class: 'reorder'
%td
%small
= link_to post.layout.name.to_s.humanize,
site_posts_path(@site, layout: post.layout.name)
%br/
= link_to post.title.value,
site_post_path(@site, post.id)
- if post.attributes.include? :draft
@ -58,7 +64,10 @@
- post.categories.value.each do |c|
= link_to c, site_posts_path(@site, category: c)
%td= post.date.value.strftime('%F')
%td
= post.date.value.strftime('%F')
%br/
= post.try(:order).try(:value)
%td
- if policy(post).edit?
= link_to t('posts.edit'),