reimplementar borradores

This commit is contained in:
f 2019-08-20 19:11:10 -03:00
parent 0369716c59
commit 80457588dd
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
11 changed files with 92 additions and 24 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,3 @@
%tr{ id: attribute }
%th= post_label_t(attribute, post: post)
%td= t "_#{post.send(attribute).value}"

View file

@ -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

View file

@ -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

View file

@ -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 }

View file

@ -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: '&#128274; The values of this field will remain private'
select:

View file

@ -1,4 +1,6 @@
es:
_true:
_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: '&#128274; Los valores de este campo serán privados'
select:

27
doc/borradores.md Normal file
View file

@ -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`.

View file

@ -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