- unless @post.errors.empty? .alert.alert-danger %ul - @post.errors.each do |key, error| %li %strong= @post.template_fields.find { |tf| tf.key == key.to_s }.try(:label) || key = [error].flatten.join("\n") -# TODO seleccionar la dirección por defecto según el idioma actual - direction = @post.get_front_matter('dir') || 'ltr' -# string para configurar la clase con direccion de texto - field_class = "form-control #{direction}" -# TODO habilitar form_for - if @post.new? - url = site_posts_path(@site, lang: @lang) - method = :post - else - url = site_post_path(@site, @post, lang: @lang) - method = :patch - if pre = @post.template.try(:get_front_matter, 'pre') = render 'layouts/help', help: CommonMarker.render_doc(pre).to_html = form_tag url, method: method, class: "form #{@invalid ? 'was-validated' : ''}", novalidate: true, multipart: true do = hidden_field_tag 'template', params[:template] .form-group = submit_tag t('posts.save'), class: 'btn btn-success submit-post' = submit_tag t('posts.save_incomplete'), class: 'btn btn-info submit-post-incomplete', name: 'commit_incomplete' .invalid_help.alert.alert-danger.d-none= @site.config.dig('invalid_help') || t('posts.invalid_help') .sending_help.alert.alert-success.d-none= @site.config.dig('sending_help') || t('posts.sending_help') - if current_user.is_a? Usuaria .form-group = label_tag 'post_author', t('posts.author') - todxs = (@site.usuarias + @site.invitadxs).compact.uniq.map(&:username) = select_tag 'post[author]', options_for_select(todxs, @post.author || current_user.email), { class: 'form-control select2', data: { tags: true, placeholder: t('posts.select.placeholder'), 'allow-clear': true } } %small.text-muted.form-text= t('posts.author_help') - if @post.has_field? :dir .form-group = label_tag 'post_dir', t('posts.dir') = select_tag 'post[dir]', options_for_select([[t('posts.ltr'), 'ltr'], [t('posts.rtl'), 'rtl']], direction), { class: 'form-control' } %small.text-muted.form-text= t('posts.dir_help') - if @post.has_field? :title .form-group = label_tag 'post_title', t('posts.title') = text_field 'post', 'title', value: @post.title, class: field_class, required: true - if @post.content? .form-group{class: direction} = label_tag 'post_content', t('posts.content') = render 'layouts/help', help: [ t('help.markdown.intro'), t('help.distraction_free_html'), t('help.preview_html') ] = text_area_tag 'post[content]', @post.content, class: 'post-content' - 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 .form-group = label_tag 'post_lang', t("posts.lang.#{lang}") = select_tag "post[lang][#{lang}]", options_for_select(@site.posts_for(lang).map { |p| [p.title, p.id] }, @post.get_front_matter('lang').try(:dig, lang)), { class: 'form-control select2' } %small.text-muted.form-text= t('posts.lang_help') -# Genera todos los campos de la plantilla - @post.template_fields.each do |template| - next unless type = template.type - if template.title.present? %h1{id: template.title.tr(' ', '_').titleize}= template.title - if template.subtitle.present? %p= template.subtitle - value = @post.new? ? template.values : @post.get_front_matter(template.key) .form-group = label_tag "post_#{template}", id: template do = link_to '#' + template.key, class: 'text-muted', data: { turbolinks: 'false' } do = fa_icon 'link', title: t('posts.anchor') - if template.private? = fa_icon 'lock', title: t('posts.private') = sanitize_markdown template.label, tags: %w[a] - if template.help %small.text-muted.form-text= template.help = render "posts/template_field/#{type}", template: template, name: template.key, value: value .invalid-feedback= t('posts.invalid') .form-group = submit_tag t('posts.save'), class: 'btn btn-success submit-post' = submit_tag t('posts.save_incomplete'), class: 'btn btn-info submit-post-incomplete', name: 'commit_incomplete' .invalid_help.alert.alert-danger.d-none= @site.config.dig('invalid_help') || t('posts.invalid_help') .sending_help.alert.alert-success.d-none= @site.config.dig('sending_help') || t('posts.sending_help') - if post = @post.template.try(:get_front_matter, 'post') = render 'layouts/help', help: CommonMarker.render_doc(post).to_html