mirror of
https://0xacab.org/sutty/sutty
synced 2025-02-21 11:21:50 +00:00
poder ocultar campos por defecto
This commit is contained in:
parent
c0590164f0
commit
0dc9d1d157
2 changed files with 51 additions and 40 deletions
|
@ -22,7 +22,7 @@ class Post
|
||||||
# datos que no tienen que terminar en el front matter
|
# datos que no tienen que terminar en el front matter
|
||||||
REJECT_FROM_FRONT_MATTER = %w[date slug draft ext].freeze
|
REJECT_FROM_FRONT_MATTER = %w[date slug draft ext].freeze
|
||||||
# datos que no traemos del template
|
# 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,
|
DEFAULT_PARAMS = [:title, :date, :content, :slug, :cover,
|
||||||
:layout, :permalink, :dir,
|
:layout, :permalink, :dir,
|
||||||
{ lang: {} }, { tags: [] }, { categories: [] }]
|
{ lang: {} }, { tags: [] }, { categories: [] }]
|
||||||
|
@ -187,7 +187,11 @@ class Post
|
||||||
|
|
||||||
# Determina si el post lleva contenido o es solo front_matter
|
# Determina si el post lleva contenido o es solo front_matter
|
||||||
def content?
|
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
|
end
|
||||||
|
|
||||||
# imita Model.update_attributes de ActiveRecord
|
# imita Model.update_attributes de ActiveRecord
|
||||||
|
@ -300,6 +304,7 @@ class Post
|
||||||
return [] unless template
|
return [] unless template
|
||||||
@template_fields ||= template.front_matter.map do |key, contents|
|
@template_fields ||= template.front_matter.map do |key, contents|
|
||||||
next if REJECT_FROM_TEMPLATE.include? key
|
next if REJECT_FROM_TEMPLATE.include? key
|
||||||
|
next if key.start_with? 'has_'
|
||||||
|
|
||||||
Post::TemplateField.new(self, key, contents)
|
Post::TemplateField.new(self, key, contents)
|
||||||
end.compact
|
end.compact
|
||||||
|
|
|
@ -35,44 +35,50 @@
|
||||||
t('help.preview_html') ]
|
t('help.preview_html') ]
|
||||||
= text_area_tag 'post[content]', @post.content, autofocus: true,
|
= text_area_tag 'post[content]', @post.content, autofocus: true,
|
||||||
class: 'post-content'
|
class: 'post-content'
|
||||||
.form-group
|
- if @post.has_field? :date
|
||||||
= label_tag 'post_date', t('posts.date')
|
.form-group
|
||||||
= date_field 'post', 'date', value: @post.date.try(:strftime, '%F'),
|
= label_tag 'post_date', t('posts.date')
|
||||||
class: 'form-control'
|
= date_field 'post', 'date', value: @post.date.try(:strftime, '%F'),
|
||||||
%small.text-muted.form-text= t('posts.date_help')
|
class: 'form-control'
|
||||||
.form-group
|
%small.text-muted.form-text= t('posts.date_help')
|
||||||
= render 'layouts/help', help: t('help.autocomplete_html')
|
= render 'layouts/help', help: t('help.autocomplete_html')
|
||||||
= label_tag 'post_categories', t('posts.categories')
|
- if @post.has_field? :categories
|
||||||
= select_tag 'post[categories][]',
|
.form-group
|
||||||
options_for_select(@site.categories(lang: @lang), @post.categories),
|
= label_tag 'post_categories', t('posts.categories')
|
||||||
{ class: 'form-control select2', multiple: 'multiple',
|
= select_tag 'post[categories][]',
|
||||||
data: { tags: true,
|
options_for_select(@site.categories(lang: @lang), @post.categories),
|
||||||
placeholder: t('posts.select.placeholder'),
|
{ class: 'form-control select2', multiple: 'multiple',
|
||||||
'allow-clear': true } }
|
data: { tags: true,
|
||||||
.form-group
|
placeholder: t('posts.select.placeholder'),
|
||||||
= label_tag 'post_tags', t('posts.tags')
|
'allow-clear': true } }
|
||||||
= select_tag 'post[tags][]',
|
- if @post.has_field? :tags
|
||||||
options_for_select(@site.tags(lang: @lang), @post.tags),
|
.form-group
|
||||||
{ class: 'form-control select2', multiple: 'multiple',
|
= label_tag 'post_tags', t('posts.tags')
|
||||||
data: { tags: true,
|
= select_tag 'post[tags][]',
|
||||||
placeholder: t('posts.select.placeholder'),
|
options_for_select(@site.tags(lang: @lang), @post.tags),
|
||||||
'allow-clear': true } }
|
{ class: 'form-control select2', multiple: 'multiple',
|
||||||
.form-group
|
data: { tags: true,
|
||||||
= label_tag 'post_slug', t('posts.slug')
|
placeholder: t('posts.select.placeholder'),
|
||||||
= text_field 'post', 'slug', value: @post.slug,
|
'allow-clear': true } }
|
||||||
class: 'form-control'
|
- if @post.has_field? :slug
|
||||||
%small.text-muted.form-text= t('posts.slug_help')
|
.form-group
|
||||||
.form-group
|
= label_tag 'post_slug', t('posts.slug')
|
||||||
= label_tag 'post_permalink', t('posts.permalink')
|
= text_field 'post', 'slug', value: @post.slug,
|
||||||
= text_field 'post', 'permalink', value: @post.get_front_matter('permalink'),
|
class: 'form-control'
|
||||||
class: 'form-control'
|
%small.text-muted.form-text= t('posts.slug_help')
|
||||||
%small.text-muted.form-text= t('posts.permalink_help')
|
- if @post.has_field? :permalink
|
||||||
.form-group
|
.form-group
|
||||||
= label_tag 'post_layout', t('posts.layout')
|
= label_tag 'post_permalink', t('posts.permalink')
|
||||||
= select_tag 'post[layout]',
|
= text_field 'post', 'permalink', value: @post.get_front_matter('permalink'),
|
||||||
options_for_select(@site.layouts, @post.get_front_matter('layout')),
|
class: 'form-control'
|
||||||
{ class: 'form-control select2' }
|
%small.text-muted.form-text= t('posts.permalink_help')
|
||||||
%small.text-muted.form-text= t('posts.layout_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?
|
- if @site.i18n?
|
||||||
- @site.translations.each do |lang|
|
- @site.translations.each do |lang|
|
||||||
- next if lang == @lang
|
- next if lang == @lang
|
||||||
|
|
Loading…
Reference in a new issue