5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-15 02:11:42 +00:00

esconder el contenido si la ficha es solo metadatos #51

This commit is contained in:
f 2018-06-25 17:44:47 -03:00
parent 1219bd2ff1
commit 7e7b7e7450
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
2 changed files with 18 additions and 7 deletions

View file

@ -22,7 +22,7 @@ class Post
# datos que no tienen que terminar en el front matter
REJECT_FROM_FRONT_MATTER = %w[date slug draft ext].freeze
# datos que no traemos del template
REJECT_FROM_TEMPLATE = %w[date draft categories layout title ext tags date slug].freeze
REJECT_FROM_TEMPLATE = %w[has_content date draft categories layout title ext tags date slug].freeze
DEFAULT_PARAMS = [:title, :date, :content, :slug, :cover,
:layout, :permalink, :dir,
{ lang: {} }, { tags: [] }, { categories: [] }]
@ -185,6 +185,11 @@ class Post
@content ||= @post.try(:content) || template.try(:content)
end
# Determina si el post lleva contenido o es solo front_matter
def content?
template.fetch_front_matter('has_content', true)
end
# imita Model.update_attributes de ActiveRecord
def update_attributes(attrs)
# el cuerpo se maneja por separado
@ -225,6 +230,11 @@ class Post
@front_matter.dig(name.to_s)
end
# Como get_front_matter pero con un valor por defecto
def fetch_front_matter(name, default)
@front_matter.fetch(name, default)
end
# Trae el template a partir del layout
def template_from_layout
@site.templates.find do |t|

View file

@ -28,12 +28,13 @@
.form-group
= label_tag 'post_title', t('posts.title')
= text_field 'post', 'title', value: @post.title, class: field_class, required: true
.form-group{class: direction}
= render 'layouts/help', help: [ t('help.markdown.intro'),
t('help.distraction_free_html'),
t('help.preview_html') ]
= text_area_tag 'post[content]', @post.content, autofocus: true,
class: 'post-content'
- if @post.content?
.form-group{class: direction}
= render 'layouts/help', help: [ t('help.markdown.intro'),
t('help.distraction_free_html'),
t('help.preview_html') ]
= text_area_tag 'post[content]', @post.content, autofocus: true,
class: 'post-content'
.form-group
= label_tag 'post_date', t('posts.date')
= date_field 'post', 'date', value: @post.date.try(:strftime, '%F'),