poder ocultar campos por defecto

This commit is contained in:
f 2018-07-23 16:48:34 -03:00
parent c0590164f0
commit 0dc9d1d157
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
2 changed files with 51 additions and 40 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[has_content date draft categories layout title ext tags date slug].freeze
REJECT_FROM_TEMPLATE = %w[draft categories layout title ext tags date slug].freeze
DEFAULT_PARAMS = [:title, :date, :content, :slug, :cover,
:layout, :permalink, :dir,
{ lang: {} }, { tags: [] }, { categories: [] }]
@ -187,7 +187,11 @@ class Post
# Determina si el post lleva contenido o es solo front_matter
def content?
template && template.fetch_front_matter('has_content', true)
has_field? :content
end
def has_field?(field)
template && template.fetch_front_matter("has_#{field.to_s}", true)
end
# imita Model.update_attributes de ActiveRecord
@ -300,6 +304,7 @@ class Post
return [] unless template
@template_fields ||= template.front_matter.map do |key, contents|
next if REJECT_FROM_TEMPLATE.include? key
next if key.start_with? 'has_'
Post::TemplateField.new(self, key, contents)
end.compact

View file

@ -35,44 +35,50 @@
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'),
class: 'form-control'
%small.text-muted.form-text= t('posts.date_help')
.form-group
= render 'layouts/help', help: t('help.autocomplete_html')
= label_tag 'post_categories', t('posts.categories')
= select_tag 'post[categories][]',
options_for_select(@site.categories(lang: @lang), @post.categories),
{ class: 'form-control select2', multiple: 'multiple',
data: { tags: true,
placeholder: t('posts.select.placeholder'),
'allow-clear': true } }
.form-group
= label_tag 'post_tags', t('posts.tags')
= select_tag 'post[tags][]',
options_for_select(@site.tags(lang: @lang), @post.tags),
{ class: 'form-control select2', multiple: 'multiple',
data: { tags: true,
placeholder: t('posts.select.placeholder'),
'allow-clear': true } }
.form-group
= label_tag 'post_slug', t('posts.slug')
= text_field 'post', 'slug', value: @post.slug,
class: 'form-control'
%small.text-muted.form-text= t('posts.slug_help')
.form-group
= label_tag 'post_permalink', t('posts.permalink')
= text_field 'post', 'permalink', value: @post.get_front_matter('permalink'),
class: 'form-control'
%small.text-muted.form-text= t('posts.permalink_help')
.form-group
= label_tag 'post_layout', t('posts.layout')
= select_tag 'post[layout]',
options_for_select(@site.layouts, @post.get_front_matter('layout')),
{ class: 'form-control select2' }
%small.text-muted.form-text= t('posts.layout_help')
- if @post.has_field? :date
.form-group
= label_tag 'post_date', t('posts.date')
= date_field 'post', 'date', value: @post.date.try(:strftime, '%F'),
class: 'form-control'
%small.text-muted.form-text= t('posts.date_help')
= render 'layouts/help', help: t('help.autocomplete_html')
- if @post.has_field? :categories
.form-group
= label_tag 'post_categories', t('posts.categories')
= select_tag 'post[categories][]',
options_for_select(@site.categories(lang: @lang), @post.categories),
{ class: 'form-control select2', multiple: 'multiple',
data: { tags: true,
placeholder: t('posts.select.placeholder'),
'allow-clear': true } }
- if @post.has_field? :tags
.form-group
= label_tag 'post_tags', t('posts.tags')
= select_tag 'post[tags][]',
options_for_select(@site.tags(lang: @lang), @post.tags),
{ class: 'form-control select2', multiple: 'multiple',
data: { tags: true,
placeholder: t('posts.select.placeholder'),
'allow-clear': true } }
- if @post.has_field? :slug
.form-group
= label_tag 'post_slug', t('posts.slug')
= text_field 'post', 'slug', value: @post.slug,
class: 'form-control'
%small.text-muted.form-text= t('posts.slug_help')
- if @post.has_field? :permalink
.form-group
= label_tag 'post_permalink', t('posts.permalink')
= text_field 'post', 'permalink', value: @post.get_front_matter('permalink'),
class: 'form-control'
%small.text-muted.form-text= t('posts.permalink_help')
- if @post.has_field? :layout
.form-group
= label_tag 'post_layout', t('posts.layout')
= select_tag 'post[layout]',
options_for_select(@site.layouts, @post.get_front_matter('layout')),
{ class: 'form-control select2' }
%small.text-muted.form-text= t('posts.layout_help')
- if @site.i18n?
- @site.translations.each do |lang|
- next if lang == @lang