From 1878749910b952b46e5651f70e2dbd033813eec1 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 11 Nov 2020 14:41:12 -0300 Subject: [PATCH] campo de permalink closes #145 closes #79 --- app/models/metadata_permalink.rb | 22 ++++++++++++++++++++ app/views/posts/attribute_ro/_permalink.haml | 3 +++ app/views/posts/attributes/_permalink.haml | 7 +++++++ 3 files changed, 32 insertions(+) create mode 100644 app/models/metadata_permalink.rb create mode 100644 app/views/posts/attribute_ro/_permalink.haml create mode 100644 app/views/posts/attributes/_permalink.haml diff --git a/app/models/metadata_permalink.rb b/app/models/metadata_permalink.rb new file mode 100644 index 0000000..58feb9e --- /dev/null +++ b/app/models/metadata_permalink.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +# Este metadato permite generar rutas manuales. +class MetadataPermalink < MetadataString + # Los permalinks nunca pueden ser privados + def private? + false + end + + private + + # Al hacer limpieza, validamos la ruta. Eliminamos / multiplicadas, + # puntos suspensivos, la primera / para que siempre sea relativa y + # agregamos una / al final si la ruta no tiene extensión. + def sanitize(value) + value = value.strip.gsub('..', '/').gsub('./', '').squeeze('/') + value = value[1..-1] if value.start_with? '/' + value += '/' if File.extname(value).blank? + + value + end +end diff --git a/app/views/posts/attribute_ro/_permalink.haml b/app/views/posts/attribute_ro/_permalink.haml new file mode 100644 index 0000000..67642e2 --- /dev/null +++ b/app/views/posts/attribute_ro/_permalink.haml @@ -0,0 +1,3 @@ +%tr{ id: attribute } + %th= post_label_t(attribute, post: post) + %td{ dir: dir, lang: locale }= metadata.value diff --git a/app/views/posts/attributes/_permalink.haml b/app/views/posts/attributes/_permalink.haml new file mode 100644 index 0000000..8cbd92c --- /dev/null +++ b/app/views/posts/attributes/_permalink.haml @@ -0,0 +1,7 @@ +.form-group + = label_tag "post_#{attribute}", post_label_t(attribute, post: post) + = text_field 'post', attribute, value: metadata.value, + dir: dir, lang: locale, + **field_options(attribute, metadata) + = render 'posts/attribute_feedback', + post: post, attribute: attribute, metadata: metadata