diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 82bc1c79..5c490382 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -50,6 +50,10 @@ class PostsController < ApplicationController # Solo permitir cambiar estos atributos de cada articulo def post_params params.require(:post).permit(:title, :date, :content, :slug, + :cover, :layout, :permalink, :objetivos, + :duracion, :formato, :habilidades, + conocimientos: [], sesiones_ejercicios_relacionados: [], + materiales_requeridos: [], lang: [], tags: [], categories: []) end end diff --git a/app/models/post.rb b/app/models/post.rb index 313ed6c4..bd80b2c7 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -149,6 +149,11 @@ class Post @post <=> other.post end + # Obtiene metadatos asegurándose que siempre trabajamos con strings + def get_front_matter(name) + @front_matter.dig(name.to_s) + end + private # Genera un post nuevo y lo agrega a la colección del sitio. @@ -168,11 +173,6 @@ class Post @site.posts.sort! end - # Obtiene metadatos asegurándose que siempre trabajamos con strings - def get_front_matter(name) - @front_matter.dig(name.to_s) - end - # Los define, asegurandose que las llaves siempre son strings, para no # tener incompatibilidades con jekyll def set_front_matter(name, value) diff --git a/app/models/site.rb b/app/models/site.rb index cf18ea99..488bae98 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -42,11 +42,17 @@ class Site end def categories - posts.map(&:categories).flatten.uniq + everything_of :categories end def tags - posts.map(&:tags).flatten.uniq + everything_of :tags + end + + def everything_of(attr) + posts.map do |p| + p.get_front_matter attr + end.flatten.uniq end # El directorio donde se almacenan los sitios diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml index db5114cd..b83cb664 100644 --- a/app/views/posts/_form.haml +++ b/app/views/posts/_form.haml @@ -43,6 +43,57 @@ = text_field 'post', 'slug', value: @post.slug, class: 'form-control' %small.text-muted.form-text= t('posts.slug_help') + .form-group + = label_tag 'post_cover', t('posts.cover') + = text_field 'post', 'cover', value: @post.get_front_matter(:cover), + class: 'form-control' + %small.text-muted.form-text= t('posts.cover_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.everything_of(:layout), @post.get_front_matter(:layout)), + { class: 'form-control select2' } + %small.text-muted.form-text= t('posts.layout_help') + .form-group + = label_tag 'post_objetivos', t('posts.objetivos') + = text_area 'post', 'objetivos', value: @post.get_front_matter(:objetivos), + class: 'form-control' + %small.text-muted.form-text= t('posts.objetivos_help') + .form-group + = label_tag 'post_habilidades', t('posts.habilidades') + = select_tag 'post[habilidades][]', + options_for_select(@site.everything_of(:habilidades), @post.get_front_matter(:habilidades)), + { class: 'form-control select2' } + %small.text-muted.form-text= t('posts.habilidades_help') + .form-group + = label_tag 'post_formato', t('posts.formato') + = select_tag 'post[formato][]', + options_for_select(@site.everything_of(:formato), @post.get_front_matter(:formato)), + { class: 'form-control select2' } + %small.text-muted.form-text= t('posts.formato_help') + .form-group + = label_tag 'post_conocimientos', t('posts.conocimientos') + = select_tag 'post[conocimientos][]', + options_for_select(@site.everything_of(:conocimientos), @post.get_front_matter(:conocimientos)), + { class: 'form-control select2', multiple: 'multiple' } + %small.text-muted.form-text= t('posts.conocimientos_help') + .form-group + = label_tag 'post_sesiones_ejercicios_relacionados', t('posts.sesiones_ejercicios_relacionados') + = select_tag 'post[sesiones_ejercicios_relacionados][]', + options_for_select(@site.everything_of(:title), @post.get_front_matter(:sesiones_ejercicios_relacionados)), + { class: 'form-control select2', multiple: 'multiple' } + %small.text-muted.form-text= t('posts.sesiones_ejercicios_relacionados_help') + .form-group + = label_tag 'post_materiales_requeridos', t('posts.materiales_requeridos') + = select_tag 'post[materiales_requeridos][]', + options_for_select(@site.everything_of(:materiales_requeridos), @post.get_front_matter(:materiales_requeridos)), + { class: 'form-control select2', multiple: 'multiple' } + %small.text-muted.form-text= t('posts.materiales_requeridos_help') :javascript $(document).on('turbolinks:load', function() { diff --git a/config/environments/production.rb b/config/environments/production.rb index 5d3ad7d3..84391705 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -66,6 +66,8 @@ Rails.application.configure do # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true + config.i18n.default_locale = :es + # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify diff --git a/config/locales/en.yml b/config/locales/en.yml index 8bed5c12..0c4d718b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -23,6 +23,24 @@ en: categories_help: 'Comma separated!' slug: 'Slug' slug_help: 'This is the name of the article on the URL, ie. /title/. You can leave it empty.' + cover: 'Cover' + cover_help: 'Path to the cover' + layout: 'Layout' + layout_help: 'The layout of this post' + objetivos: 'Objectives' + objetivos_help: 'Objectives of this session' + permalink: 'Permanent link' + permalink_help: "If you want to access the post from a specific URL, use this field. Don\'t forget to start with a /" + habilidades: 'Skill level' + habilidades_help: 'Skills required for this session' + formato: 'Format' + formato_help: 'Format of this session' + conocimientos: 'Required knowledge' + conocimientos_help: 'Select all required knowledge for this session' + sesiones_ejercicios_relacionados: 'Related sessions/exercises' + sesiones_ejercicios_relacionados_help: 'Select all related sessions/exercises' + materiales_requeridos: 'Needed materials' + materiales_requeridos_help: 'Select all materials needed for this session' logger: rm: 'Removed %{path}' errors: diff --git a/config/locales/es.yml b/config/locales/es.yml index 21914f5d..9f135d24 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -21,6 +21,24 @@ es: categories_help: '¡Separadas por comas!' slug: 'Nombre la URL' slug_help: 'Esto es el nombre del artículo en la URL, por ejemplo /título/. Puedes dejarlo vacío.' + cover: 'Portada' + cover_help: 'La dirección de la portada' + layout: 'Plantilla' + layout_help: 'El tipo de plantilla' + objetivos: 'Objetivos' + objetivos_help: 'Objetivos de esta sesión' + permalink: 'Dirección del enlace' + permalink_help: 'Si quieres que el artículo se acceda desde esta URL completa aquí, no te olvides de empezar con /' + habilidades: 'Habilidades' + habilidades_help: 'Habilidades requeridas para esta sesión' + formato: 'Formato' + formato_help: 'Formato de esta sesión' + conocimientos: 'Conocimientos' + conocimientos_help: 'Elige todos los conocimientos requeridos para abordar esta sesión' + sesiones_ejercicios_relacionados: 'Sesiones y ejercicios relacionados' + sesiones_ejercicios_relacionados_help: 'Elige todas las sesiones relacionadas con esta' + materiales_requeridos: 'Materiales requeridos' + materiales_requeridos_help: 'Materiales necesarios para esta sesión' logger: rm: 'Eliminado %{path}' errors: