diff --git a/app/models/metadata_boolean.rb b/app/models/metadata_boolean.rb new file mode 100644 index 00000000..f1a78b89 --- /dev/null +++ b/app/models/metadata_boolean.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +# Implementa valores por sí o por no +class MetadataBoolean < MetadataTemplate + def default_value + false + end + + # Convertir el valor que pasemos a boolean + def value + self[:value].present? || document.data.fetch('draft', default_value) + end +end diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml index 3f2b2df6..3d47cc15 100644 --- a/app/views/posts/_form.haml +++ b/app/views/posts/_form.haml @@ -21,15 +21,21 @@ = form_tag url, method: method, class: 'form post', multipart: true do -# Botones de guardado - = render 'posts/submit', site: site + = render 'posts/submit', site: site, post: post -# Dibuja cada atributo - - post.attributes.each do |attribute| - - metadata = post.send(attribute) - - type = metadata.type - = render "posts/attributes/#{type}", - post: post, attribute: attribute, - metadata: metadata, site: site + :ruby + post.attributes.each do |attribute| + # El borrador se muestra distinto + next if attribute == :draft + + metadata = post.send(attribute) + type = metadata.type + + haml_io.write render("posts/attributes/#{type}", + post: post, attribute: attribute, + metadata: metadata, site: site) + end -# Botones de guardado - = render 'posts/submit', site: site + = render 'posts/submit', site: site, post: post diff --git a/app/views/posts/_submit.haml b/app/views/posts/_submit.haml index 261631ee..438be23d 100644 --- a/app/views/posts/_submit.haml +++ b/app/views/posts/_submit.haml @@ -1,8 +1,10 @@ .form-group = submit_tag t('.save'), class: 'btn btn-success submit-post' - = submit_tag t('.save_incomplete'), - class: 'btn btn-info submit-post-incomplete', - name: 'commit_incomplete' + -# Permitir guardar como borrador + - if post.attributes.include? :draft + = submit_tag t('.save_draft'), + class: 'btn btn-info submit-post-draft', + name: 'post[draft]' .invalid_help.alert.alert-danger.d-none = site.config.fetch('invalid_help', t('.invalid_help')) .sending_help.alert.alert-success.d-none diff --git a/app/views/posts/attribute_ro/_boolean.haml b/app/views/posts/attribute_ro/_boolean.haml new file mode 100644 index 00000000..991e5fa5 --- /dev/null +++ b/app/views/posts/attribute_ro/_boolean.haml @@ -0,0 +1,3 @@ +%tr{ id: attribute } + %th= post_label_t(attribute, post: post) + %td= t "_#{post.send(attribute).value}" diff --git a/app/views/posts/attributes/_boolean.haml b/app/views/posts/attributes/_boolean.haml new file mode 100644 index 00000000..fe4bc20d --- /dev/null +++ b/app/views/posts/attributes/_boolean.haml @@ -0,0 +1,9 @@ +.form-check{ class: invalid(post, attribute) } + = check_box_tag "post[#{attribute}", metadata.value, metadata.value, + class: 'form-check-input', + aria: { describedby: id_for_help(attribute) } + = label_tag "post_#{attribute}", post_label_t(attribute, post: post), + class: 'form-check-label' + + = render 'posts/attribute_feedback', + post: post, attribute: attribute, metadata: metadata diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index cdfdd89b..646139cc 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -35,6 +35,10 @@ %td = link_to post.title.value, site_post_path(@site, post.id) + - if post.attributes.include? :draft + - if post.draft.value + %span.badge.badge-primary + = post_label_t(:draft, post: post) - if post.attributes.include? :categories - unless post.categories.value.empty? %br diff --git a/app/views/posts/show.haml b/app/views/posts/show.haml index bbd668d4..deaeb2bf 100644 --- a/app/views/posts/show.haml +++ b/app/views/posts/show.haml @@ -21,18 +21,19 @@ -# TODO: Cambiar por un método que nos deje interactuar directamente con los metadatos - - @post.attributes.each do |attr| - :ruby + :ruby + @post.attributes.each do |attr| metadata = @post.send(attr) - next unless metadata.front_matter? - = render "posts/attribute_ro/#{metadata.type}", post: @post, - attribute: attr, metadata: metadata, tags: all_html_tags + haml_io.write render("posts/attribute_ro/#{metadata.type}", + post: @post, attribute: attr, + metadata: metadata, + tags: all_html_tags) + end -# Mostrar todo lo que no va en el front_matter (el contenido) - @post.attributes.each do |attr| - - next if @post.send(attr).front_matter? %section{ id: attr } diff --git a/config/locales/en.yml b/config/locales/en.yml index 735484b7..42199caf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,4 +1,6 @@ en: + _true: Yes + _false: No dir: ltr site_service: create: 'Created %{name}' @@ -305,7 +307,7 @@ en: front_matter: Post metadata submit: save: 'Save' - save_incomplete: 'Save as draft' + save_draft: 'Save as draft' invalid_help: 'Some fields need attention! Please search for the fields marked as invalid.' attributes: date: @@ -327,8 +329,6 @@ en: categories: 'Everything' index: 'Posts' edit: 'Edit' - draft: revision - incomplete: draft open: 'Tip: You can add new options by typing them and pressing Enter' private: '🔒 The values of this field will remain private' select: diff --git a/config/locales/es.yml b/config/locales/es.yml index b633b3c0..63596719 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1,4 +1,6 @@ es: + _true: Sí + _false: No dir: ltr site_service: create: 'Creado %{name}' @@ -316,7 +318,7 @@ es: front_matter: Metadatos del artículo submit: save: 'Guardar' - save_incomplete: 'Guardar como borrador' + save_draft: 'Guardar como borrador' invalid_help: '¡Te faltan completar algunos campos! Busca los que estén marcados como inválidos' attributes: date: @@ -338,8 +340,6 @@ es: new_with_template: 'Comenzar %{template}' index: 'Artículos' edit: 'Editar' - draft: en revisión - incomplete: borrador open: 'Nota: Puedes agregar más opciones a medida que las escribes y presionas Entrar' private: '🔒 Los valores de este campo serán privados' select: diff --git a/doc/borradores.md b/doc/borradores.md new file mode 100644 index 00000000..e91cb2e6 --- /dev/null +++ b/doc/borradores.md @@ -0,0 +1,27 @@ +# Borradores + +En Jekyll, los borradores se encuentran en el directorio `_drafts`. + +En Sutty, para traducir a distintos idiomas, utilizamos "colecciones" +con el nombre del idioma. Nuestra extensión de traducciones reemplaza +el directorio `_posts` por cada uno de estos y genera un sitio por cada +idioma. De esta forma no tenemos que hacer adaptaciones más profundas a +las plantillas. + +Hasta ahora lo que hacíamos es agregar un metadata `draft: true` a los +artículos y luego los filtrábamos con una extensión. Creemos que esta +opción es mínima y suficiente para lo que queremos lograr (excluir +algunos artículos de la compilación). + +De lo contrario, tendríamos que implementar lo siguiente, que no es +trivial: + +* Mover artículos de lugar entre `_lang/` y `_lang/_drafts`, utilizando + `mv` y `rugged`. + +* Implementar acceso a borradores por colección. Jekyll carga los + borradores solo desde `_drafts`, con lo que no podríamos saber a qué + idioma pertenece a menos que ignoremos ese dato o lo guardemos como + metadato... + +En este momento es más simple para Sutty mantener el `draft: true`. diff --git a/doc/posts.md b/doc/posts.md index ba5c946e..180235cc 100644 --- a/doc/posts.md +++ b/doc/posts.md @@ -93,8 +93,8 @@ Al instanciar un `Post`, se pasan el sitio y la plantilla por defecto. ## TODO -* Reimplementar draft e incomplete (por qué eran distintos?) * Reimplementar subida de imagenes/archivos +* Implementar TUI-Editor, ACE y otros editores de texto * Leer artículos a medida que se los necesita en lugar de todos juntos. * Reimplementar glosario (se crea un artículo por cada categoría utilizada) @@ -102,3 +102,6 @@ Al instanciar un `Post`, se pasan el sitio y la plantilla por defecto. * Reimplementar campo 'pre' y 'post' en los layouts.yml * Convertir idiomas disponibles a pestañas? * Implementar traducciones sin adivinar. Vincular artículos entre sí +* Renombrar Metadata* a Metadata::* para poder organizarlas en + subdirectorios +* Implementar edición de layouts de metadatos